I tried making a weapon command that would give you a pistol but it didn’t work.
AddEventHandler("chatMessage", function(s, n, m)
local message = string.lower(m) -- This prevents it from NOT recognizing /WEAPON as the command (just in case the user has caps lock on)
if message == "/weapon" then
CancelEvent() -- Hide the message from user chat
GiveWeaponToPed(s, "WEAPON_PISTOL", 1000, false, false)
end
end)
It just gives me this error and gives me no pistol
Error running system event handling function for resource script: citizen:/scripting/lua/scheduler.lua:39: Failed to execute thread: sv.lua:5: attempt to call a nil value (global 'GiveWeaponToPed')
stack traceback:
sv.lua:5: in upvalue 'handler'
citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
This handler is on the server (assuming from the sv.lua filename). You will then need to trigger a client event to give the ped the weapon. The server can’t execute game natives. The server can only tell the client(s) (by events) what to do.
Error running call reference function for resource script: sv.lua:2: attempt to call a nil value (global 'PlayerId')
stack traceback:
sv.lua:2: in local 'ref'
citizen:/scripting/lua/scheduler.lua:277: in function <citizen:/scripting/lua/scheduler.lua:268>
Let me explain further. Anything to do with natives has to be done on a client script. So you have 2 options for commands. You can create the command on the client and put the weapons natives like I did above or you can create a client event to do it for you and use the server command to trigger the client event.
do you want it bound to a job and for multi different commands you would need jobs or some deciding factor so you didn’t pick up other weapons in the command