xxldoener Posted June 3, 2012 Share Posted June 3, 2012 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 ) Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 function spawnvehicle ( thePlayer, commandname, target, vehicleid ) local vehicleid = tonumber ( vehicleid ) if ( not vehicleid ) then outputChatBox ( "Invalid VehicleID was given", thePlayer ) else local targetp = getPlayerFromName ( target ) if ( not targetp ) then -- If the target is not online. targetp = thePlayer -- Set the "targetp" variable to the player who used the command. end local x, y, z = getElementPosition ( targetp ) local spawnedvehicle = createVehicle ( vehicleid, x + 2, y + 2, z + 1 ) if ( not spawnedvehicle ) then outputChatBox ( "Invalid VehicleID was given", thePlayer ) end end end addCommandHandler ( "spawnvehicle", spawnvehicle ) Read comments. Link to comment
xxldoener Posted June 3, 2012 Author Share Posted June 3, 2012 I think that is not what I want. I want to receive a message that says "Invalid target specified" if the target player is not online, but I want to spawn a vehicle next to the player who entred the command if no target is specified. For example, I am player1 and player2 is also online. If I enter spawnvehicle player3 500 - A message should appear telling "Invalid target specified" If I enter spawnvehicle 500 - A Vehicle with the ID 500 should appear next to me (being the player who entered the command) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now