Hello, I’m working on a staff menu with lua native ui and I want to create a jail and comserv item. In the resources there are examples of how to put them in police job ( I used this for the menu ) but it is about the closest player. The think is that I want to create a dialog with esx_menu_dialog to type player server id and then another dialog to add how many swipes or jail time I want him to do. I am also sending you the code. Just saying, Im new to fivem development and the code is not the best… Can you help?
Sorry for my bad english or bad explanation and also sorry if my topic has something wrong, It’s my first topic…
Screenshots of what I want :
The Item in the Menu :
The first dialog that gets the id of the player you want :
The jail minutes or swipes that you want to add to the id :
i give you an function that you can use in your code
first off all, add bellow code to first of the script:
function dialogMenu(quistionText , maxLenght )
while true do
AddTextEntry('quistion', quistionText )
DisplayOnscreenKeyboard(1, "quistion", "", "" , "", "", "", maxLenght )
while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do
Citizen.Wait(7)
end
local playerReplay = GetOnscreenKeyboardResult()
if ( playerReplay ~= nil ) then
return playerReplay
break
end
end
end
and for get value from player you just add bellow code where ever you want:
local playerId = dialogMenu('Enter Player ID:' , 6 )
-- local playerId = dialogMenu('Enter Player ID:' , 6 )
local swipes = dialogMenu('Add Swipes:' , 6 )
if swipes == nil then
ESX.ShowNotification('Invalid services count.')
else
TriggerServerEvent("esx_communityservice:sendToCommunityService", player, swipes)
end
end
It says that I have been sent in ~ months of comserv but i do not have the blue sign or even the text on bottom left that says how many swipes left… Any solution?
Again thank you for your fast respond. I made my code like this :
function SendToCommunityService(player)
local playerId = dialogMenu('Enter Player ID:' , 6 )
local swipes = dialogMenu('Add Swipes:' , 6 )
if swipes == nil then
ESX.ShowNotification('Invalid services count.')
else
TriggerServerEvent("esx_communityservice:sendToCommunityService", playerId , swipes )
end
end
When I send myself to comserv, I get teleported but I cant swipe actually. I wear the clothes etc but there is not text with the left swipes I have in the bottom left and also there is an error of esx_community service :
Maybe I found the error. In the Trigger I have this :
SendToCommunityService(GetPlayerServerId(closestPlayer))
What Can I put istead of closest player to make it work?
and it says in the console that I cannot have duplicate entry…
Let me also send you my code to add anything you want yourself… menu.lua (9.7 KB) __resource.lua (129 Bytes)
This error is probably happening because you are getting a string input and using it as int.
swipes are counted as int in the main scripts and probably somewhere it will compare it to a number thats why you get a error.
its probably better to protect your inputs from the player because they can write whatever they want instead of the actual server id or actual numbers.
local playerId = dialogMenu('Enter Player ID:' , 5 )
local swipes = dialogMenu('Add Swipes:' , 4)
if not swipes or not playerId then
ESX.ShowNotification('Please Enter a valid Number')
return
end
if not tonumber(swipes) or not tonumber(playerId) then
ESX.ShowNotification('~r~ Please Enter a Valid Number')
return
end
swipes = tonumber(swipes)
playerId = tonumber(playerId) -- Changing Them To INT
if swipes < 0 or swipes > 1000 then
ESX.ShowNotification('Please enter a number between 0-1000 for the swipes')
return
end
if not NetworkIsPlayerActive(GetPlayerFromServerId(playerId)) then
ESX.ShowNotification('Please Enter a valid Server id')
return
end
if swipes == nil then
ESX.ShowNotification('Invalid services count.')
else
TriggerServerEvent("esx_communityservice:sendToCommunityService", tonumber(playerId) , tonumber(swipes) )
end
i do not know anything about the CommunityService script and the event that you are triggering, i assume it works.