[Release] [ESX] ESX_CommunityService

hey just wondering how i decrease the size of the txt that shows up in the chat window and second thing
when people get sentenced to community service when they leave the area they are teleported back but doesnt add any extra jobs to there sentence

RegisterServerEvent(‘esx_communityservice:extendService’)
AddEventHandler(‘esx_communityservice:extendService’, function()

local _source = source
local identifier = GetPlayerIdentifiers(_source)[1]

MySQL.Async.fetchAll('SELECT * FROM communityservice WHERE identifier = @identifier', {
	['@identifier'] = identifier
}, function(result)

	if result[1] then
		MySQL.Async.execute('UPDATE communityservice SET actions_remaining = actions_remaining + @extension_value WHERE identifier = @identifier', {
			['@identifier'] = identifier,
			['@extension_value'] = Config.ServiceExtensionOnEscape
		})
	else
		print ("ESX_CommunityService :: Problem matching player identifier in database to reduce actions.")
	end
end)

end)

First confirm the player’s ID has an entry in your database table “communityservice”, then replace that entire section with the following and test. If it works it should fulfill your needs, feel free to alter it.

RegisterServerEvent('esx_communityservice:extendService')
AddEventHandler('esx_communityservice:extendService', function()
    local xPlayer = ESX.GetPlayerFromId(source)
    local identifier = xPlayer.identifier

	MySQL.Async.execute('UPDATE communityservice SET actions_remaining = actions_remaining + @extension_value WHERE identifier = @identifier', {
		['@identifier'] = identifier,
		['@extension_value'] = Config.ServiceExtensionOnEscape
	})
end)

You basically have to replace the way that command is registed in server/main.lua

use ESX.RegisterCommand(‘comserv’, ‘admin’, function(xPlayer, args, showError)

(in both commands)

i have added the sql and ensured it per the instructions but /comserv does not work?
i am set as admin and still the same, also tried to set as pd job still says “invalid command”

how can i get this to work ??

Apostolos_Iatridis Για καποιο λογο οταν πληκτρολογο το command endcomserv λεει οτι δεν υπαρχει κατι τετοιο σε command αυτο το λεει και στο command comserv αλλα το comserv τουλαχιστον δουλευει στο staff menu ενω στο αλλο συνεχιζει να λεει οτι δεν υπαρχει τετοιο command (να σημειωθει οτι δεν εχω κανει καποια αλαγη στον κωδικα του script και το εχω κανει start απο το server.cfg)

Thank you sir working great !

legend, thanks for you help!

i keep getting invaild command /comserv can anybody help me out

Even if i put 1 or 100 or 1000 actions
when i finish 1 action i am free …
any ideas ?

For anyone who has problems with the Script. I edited it so police can use the Command and did some other changes. Have fun with the script. Works like a charm on Esx Legacy :slight_smile:

ESX_CommunityService.rar (21.1 KB)

2 Likes

well,
if admin try to do /comserv (playerID) (count)
i get a error : "invalid ID or actions count.

so, only police can do it

ESX.RegisterCommand(‘geeftaakstraf’, ‘admin’, function(xPlayer, args, showError)
local _source = source
local abc = ESX.GetPlayerFromId(xPlayer)
if args.id ~= nil and args.amount ~= nil and xPlayer[“job”][“name”] == ‘police’
then
TriggerEvent(‘esx_communityservice:sendToCommunityService’, args.id.source, args.amount)
else
TriggerClientEvent(‘chat:addMessage’, xPlayer.source, { args = { _U(‘system_msn’), _U(‘invalid_player_id_or_actions’) } } )
end
end, true, {help = “give someone communityservice.”, validate = true, arguments = {
{name = “id”, help = _U(‘target_id’), type = ‘player’},
{name = ‘amount’, help = “amount of comserv”, type = ‘number’}
}})

ESX.RegisterCommand(‘stoptaakstraf’, ‘admin’, function(xPlayer, args, showError)
local _source = source
local abc = ESX.GetPlayerFromId(xPlayer)
if args.id ~= nil and xPlayer[“job”][“name”] == ‘police’
then
TriggerEvent(‘esx_communityservice:endCommunityServiceCommand’, args.id.source)
else
print(“You can’t do that”)
end
end, true, {help = “end the cs.”, validate = false, arguments = {
{name = “id”, help = _U(‘target_id’), type = ‘player’}
}})

Found a fix to this,

ESX.RegisterCommand(‘comserv’, ‘admin’, function(xPlayer, args, showError)
local _source = source
local abc = ESX.GetPlayerFromId(_source)
if xPlayer.getGroup() == ‘admin’ or xPlayer.getGroup() == ‘leadadmin’ or xPlayer.getGroup() == ‘management’ then
TriggerEvent(‘esx_communityservice:sendToCommunityService’, args.id.source, args.amount)
else
TriggerClientEvent(‘chat:addMessage’, xPlayer.source, { args = { _U(‘system_msn’), _U(‘invalid_player_id_or_actions’) } } )
end
end, true, {help = “give someone communityservice.”, validate = true, arguments = {
{name = “id”, help = _U(‘target_id’), type = ‘player’},
{name = ‘amount’, help = “amount of comserv”, type = ‘number’}
}})

ESX.RegisterCommand(‘endcomserv’, ‘admin’, function(xPlayer, args, showError)
local _source = source
local abc = ESX.GetPlayerFromId(_source)
if xPlayer.getGroup() == ‘admin’ or xPlayer.getGroup() == ‘leadadmin’ or xPlayer.getGroup() == ‘management’ then
TriggerEvent(‘esx_communityservice:endCommunityServiceCommand’, args.id.source)
else
print(“You can’t do that”)
end
end, true, {help = “end the cs.”, validate = false, arguments = {
{name = “id”, help = _U(‘target_id’), type = ‘player’}
}})

Its not working for me

command does not work help plz

image

If someone can send the addon solved I would appreciate it, thanks

excelent! working in legacy, with a little problem, because my database change the length of the varchar, its only 46, and has problem to keep the track for the remain actions, but, works, any ideas why my database take the varchar 100 for the identifier, and when Im in the game its only varchar 46?

i can’t get it work because they ask me for essential mode in sql
what i have to do

For anyone who still wants to use this script, this is extremely deprecated, and only good for one thing. If you need something that works in 2024, then use this! This script has inbuilt AdminJail, Community Service and ban! GitHub - fivemland/fl_punishment: Admin Jail, Community Service, Ban + Admin panel for list players.