[ESX, FREE] Zerio Duty - Duty management with player metadata

Zerio Duty

This is a Duty system made for ESX, this is pretty much a library with all the functions and such.
Making it very easy to link this to any UI or such.

The upside to this duty system is that in other duty systems it changes the actual job name which messes up other scripts, example: when off duty your job name is “offduty”, when on duty your job name is “police”.

This is not how this script works , this script does not change your job name, it simply uses player metadata, which is way smarter.

Links

Github Page
Pull Requests
Github Issues

Contribution

If you want to contribute to this project, then please do. We are open to any help at all, simply open a PR (Pull Request) on the Github Repository, or open an Issue on the Github Repository.

Exports

Server

  • getDuty(identifier)

    Gets the current duty status of the player, returns a boolean (true / false).
    If the player doesnt exist / isnt online, then false will be returned.

  • setDuty(identifier, newValue)

    Updates the duty status for the inputted player. Doesn’t return anything.

  • getPlayersOnDuty(jobName)

    Returns a table with all players on duty for a specific job. This is based on ESX.GetExtendedPlayers, therefore the players returned are actual player objects / ESX players.

  • getPlayersOffDuty(jobName)

    Returns a table with all players that are off duty for a specific job. This is based on ESX.GetExtendedPlayers, therefore the players returned are actual player objects / ESX players.

Client

  • getDuty()

    Gets the duty status of the local player / client, returns a boolean (true / false)

Events

Server

  • zerio-duty:server:dutyChange

    Gets triggered when a players duty value is changed. It passes through the source of the player and also the new duty value.

  • zerio-duty:server:toggleDuty

    Toggles the duty for the player that triggered this event. (Has to be triggered from the client)
    Works great to be triggered from a “duty marker” / duty change function in a job script.

Client

  • zerio-duty:client:dutyChange

    This gets triggered when the local player / clients duty value gets changed. Passes through the new duty value.

Examples

EXAMPLE FOR ESX PAYCHECK EXISTS ON GITHUB

Server:

(Command displaying your duty status)

RegisterCommand("duty", function(source)
	local Player = ESX.GetPlayerFromId(source)

	if Player then
		local onduty = exports["zerio-duty"]:getDuty(Player.identifier)
		local str = "You are on duty"
		
		if onduty == false then
			str = "You are not on duty"
		end

		TriggerClientEvent("chat:addMessage", Player.source, {
			color = {255, 255, 255},
			multiline = true,
			args = {"Zerio-Duty", str}
		})
	end
end)

(Command toggling your duty status)

RegisterCommand("changeduty", function(source)
	local Player = ESX.GetPlayerFromId(source)

	if Player then
		local duty = exports["zerio-duty"]:getDuty(Player.identifier)
		exports["zerio-duty"]:setDuty(Player.identifier, not duty)
	end
end)

Client:

(Command displaying your duty status)

RegisterCommand("duty", function()
	local onduty = exports["zerio-duty"]:getDuty()
	local str = "You are on duty"

	if onduty == false then
		str = "You are not on duty"
	end

	TriggerEvent("chat:addMessage", {
		color = {255, 255, 255},
		multiline = true,
		args = {"Zerio-Duty", str}
	})
end)
Code is accessible Yes
Subscription-based No
Lines (approximately) ~100
Requirements ESX
Support Partial

Previous Scripts:
Fivem Resource CLI
Zerio Bobcat Security Heist
Zerio Proximity Prompts
Zerio Progress Bars
Zerio Crafting
Zerio Bossmenu
Zerio Radio
Zerio Cardealer
Zerio Jobcenter
Zerio Garage
Zerio Characters

7 Likes

great work bro thank you very much for free contribuite for community

is there any video ?

There is nothing to take a video of.
This is just a bunch of exports, events and callbacks that you can use in your own server / script.

So in the command / marker / whatever to toggle duty, you can use the zerio-duty:server:toggleDuty event etc.

If you need any help at all with setting it up or understanding it, I can help you. Just ask here.

1 Like

ok well thank for your responce if there is anything i will ask you thank you very much

UPDATE

  • Added discord logs for when you go off duty

image

  • Fixed error in setDuty export
  • Fixed error in zerio-duty:server:toggleDuty event
  • Changed player load etc to use setDuty export instead of Player.set()
  • Added clientsided example of changing duty (can be seen on github)
1 Like

thank you

hi, is there any snippet to put players on duty to ox_lib menu?

No, there is no such snippet. But you could create one yourself using the information in the documentation / readme.

Is resource outdated? i have set new es extended, but im getting

“Error loading script server/main.lua in resource zerio-duty: Execution of native 000000002f7a49e6 in script host failed: Argument at index 1 was null”

Could you please screenshot the error instead.
The script should not be outdated.