So I already got my spawnvehicle-script to work. It works with spawnvehicle targetname vehicleid.
However, I wanted to add a function so that if you don't specify a target, the person who enters the command becomes the target. But somehow it doesn't work, I get the error BadArgument@getPlayerFromName in line 10, which means that the entry in line 5 doesn't work either. What am I doing wrong?
function spawnvehicle (thePlayer, commandname, target, vehicleid)
if not vehicleid then
if tonumber (target) then
vehicleid = tonumber (target)
target = (thePlayer)
else
outputChatBox("Invalid VehicleID was given", thePlayer)
end
end
local targetp = getPlayerFromName (target)
if targetp then
local x, y, z = getElementPosition ( targetp )
local spawnedvehicle = createVehicle (tonumber (vehicleid), x+2, y+2, z+1)
if not spawnedvehicle then outputChatBox("Invalid VehicleID was given", thePlayer)
end
else
outputChatBox("Invalid player specified", thePlayer)
end
end
addCommandHandler ( "spawnvehicle", spawnvehicle )