Hello folks,
I’m new here - I’ve developed my fair share of GTA San Andreas (SAMP) servers in the past and very confident with it - However LUA? That’s a whole new breed of scripting language I now wish to learn.
So to kickstart my understanding of it. I’ve been playing around with some of the functions, mainly ‘RegisterCommand’.
I originally made a command which was along the lines of
RegisterCommand("spawnveh", function(source, args, raw)
local hash = GetHashKey("zentorno")
RequestModel(hash)
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(0)
end
local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
local vehicle = CreateVehicle(hash, x + 2, y + 2, z + 1, 0.0, true, false)
TriggerEvent("chatMessage", "", { 3, 3, 3 }, "Vehicle Spawned!")
end, false)
Simple enough - Spawns in a Zentorno and sends a message in chat. I’m now wishing to try make it so you can type /spawnveh ‘Zentorno’ or /spawnveh ‘Calvacade’ etc.
So - I always attempt before asking - Let me detail what I did
RegisterCommand("spawnveh", function(source, args, raw)
local hash = GetHashKey(args)
RequestModel(hash)
while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(0)
end
local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
local vehicle = CreateVehicle(hash, x + 2, y + 2, z + 1, 0.0, true, false)
TriggerEvent("chatMessage", "", { 3, 3, 3 }, "Vehicle Spawned!")
end, false)
Now I read the RegisterCommand wiki and realised that ‘source’ is the ID typically of the player typing the command, args is the additional arguments they type (in table format, I believe? This might be my problem) and raw which is the entire command and arguments in a string format.
Now how is it I can extract the parameters from args as it’s evident probably to you professionals that local hash = GetHashKey(args) isn’t going to return anything if it cannot understand what’s been typed. I’m yet to test this but would tostring(args) work?
Thanks, first day here so I hope I’ve explained that relatively well.