So I am very new to Lua and fiveM. The only coding experience I have is with C# and SQL, that’s it. It’s helpful but doesn’t do the job. So I’ve been lurking around on the forum and google but couldn’t find a tutorial of what I want to do. I have no code or any game mode made yet. I’m just trying to experiment so that I can learn to program in lua/fiveM and eventually create a server.
Basically I want to create a command /givegun “gunname” and all it does is just give a gun they wrote with 9999 ammo. e.g. /givegun m4 will give them WEAPON_ASSAULTRIFLE with 9999 bullets (I know typing m4 won’t give weapon_assaultrifle, I will have to manually transform m4 to weapon_assaultrifle in code). I first tried with just /givegun and it would’ve given the assaultrifle with 500 ammo but that didn’t work either. It only succeeded my to give them guns when they spawn but that’s not what I need.
This is what i’ve tried:
TriggerEvent('es:addCommand', 'car', function(source, args, user)
TriggerClientEvent("es_com:giveGun"), source, args)
local ped = GetPlayerPed(-1)
local weapon = GetHashKey(w)
if weapon == nil then
GiveWeaponToPed(ped, GetHashKey("WEAPON_ASSAULTRIFLE"), 5000, false))
GiveWeaponToPed(ped,GetHashKey(weapon), 5000, false))
I’ve tried it with RegisterCommand but couldn’t find a way either.
An extra problem I have atm is never knowning when to use things like: Source, args, user and such in function().
My excuses for lack of lots of knowledge. I’m just hyped to try run a server in FiveM. SA:MP days were glorious. Thank you!