Jobs
Read the players' jobs, react to deliveries and hand out your own freight jobs.
The active job
player.job is the job the player is doing right now, or null:
const j = player.job
if (j) {
mp.chat.send(player, `${j.cargo}: ${j.source.city} -> ${j.destination.city}, ${j.distanceKm} km, ${j.income} €`)
}Besides display names (in the player's game language), source and destination carry the game's ids - cityId and companyId, e.g. dusseldorf and tradeaux. The cargo id is cargoId, e.g. apples. You need these ids to hand out jobs.
Progress
jobStarted fires when a player takes a job, jobLoaded when its cargo is picked up. How far it still is shows the navigation's route in player.vehicle.route:
mp.events.on("jobLoaded", (player, job) => {
const route = player.vehicle.route
mp.chat.send(player, `${job.cargo} loaded - ${route ? `${route.distanceKm} km, about ${route.minutes} min` : "set your route"}`)
})Deliveries and cancellations
mp.events.on("jobDelivered", (player, job) => {
mp.chat.broadcast(`${player.name} earned ${job.revenue} € and ${job.earnedXp} XP`)
})
mp.events.on("jobCancelled", (player, job) => {
mp.chat.send(player, `Job cancelled, penalty ${job.penalty} €`)
})Switching off the game's job markets
Three game rules decide which of the game's own job screens players can open: companyJobs (own truck, the company's trailer - Freight Market in the game, German: Frachtaufträge), ownTrailerJobs (own truck and trailer - Cargo Market, German: Frachtmarkt) and quickJobs (quick jobs, German: Schnellaufträge). Before they were called freightMarket and cargoMarket; server.cfg and the server console still accept those names. Switched off, the entry disappears from the game's menu and its tab in the job screens is locked (should all three of a menu be off, one stays and only shows a notice). Jobs your gamemode hands out still work - so a server can offer jobs only through its own UI.
mp.rules.set("quickJobs", false)In server.cfg: rule_quickJobs = false; in the server console: rule quickJobs off.
Skipping the drive
mp.players.teleportToJob(player) moves the player to where the job continues: to the trailer at the source, or to the destination once it is loaded. With true the game time moves on as if they had driven (fuel and driving time too); without, it is an instant jump.
mp.commands.add("skip", "drive to the job's next stop", (player) => mp.players.teleportToJob(player), { role: "admin" })Handing out jobs
JobBuilder creates a freight job, as if the player had taken it in the game's freight market with their own truck: the trailer waits at the source company, the route leads there, the player picks it up and delivers it. Once the trailer is coupled, the route continues to the destination. Companies and cargo are checked against the map (mp.world): a typo such as dfh.breme throws a RangeError instead of silently starting nothing.
const job = new JobBuilder()
job.cargo = "apples"
job.source = { company: "tradeaux", city: "dusseldorf" }
job.destination = { company: "dfh", city: "hamburg" }
job.income = 12000 // optional
job.assign(player)Or in one go:
new JobBuilder({
cargo: "gravel",
source: { company: "steinbr_str", city: "magdeburg" },
destination: { company: "sanbuild_bas", city: "leipzig" },
}).assign(player)- All values are game ids (lowercase, digits,
_, up to 12 characters) - see Finding ids. - The source company must send the cargo and the destination company must accept it, and both must be in the given cities.
- income is the payment on delivery in euro. Without it, the game calculates the payment as usual.
- A job the player is doing is cancelled first.
- The source company must have at least one job offer in the player's game - nearly all companies do.
assignthrows an error if cargo, source or destination are missing or not valid ids.
mp.jobs.assign(player, { cargo, source, destination, income }) does the same without the builder.
Finding ids
The job finder offers every combination of cities, companies and cargo that exists in the game and writes the code for it. The full lists are under Cities, Companies and Cargo.