mouadys Posted January 19, 2014 Share Posted January 19, 2014 Hello , i made a script to spawn vehicle and set player as driver , and it only works if you are admin . But i want to destroy that vehicle with a command and i dont know how . function createVehicleForPlayer(thePlayer, command, ...) local x,y,z = getElementPosition(thePlayer) -- get the position of the player x = x + 3 local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) local vehicleName = table.concat({...}, " ") local vehID = getVehicleModelFromName ( vehicleName ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then local createdVehicle = createVehicle( vehID,x,y,z ) warpPedIntoVehicle ( thePlayer, createdVehicle ) setVehicleDamageProof(createdVehicle, true) if (createdVehicle == false) then -- if so, output a message to the chatbox, but only to this player. outputChatBox("Failed to create vehicle.",thePlayer) else outputChatBox("Vehicle has been created",thePlayer) end end end addCommandHandler("cv", createVehicleForPlayer) function destroy(thePlayer, command ) destroyElement ( createdVehicle ) end addCommandHandler ("dv", destroy) Link to comment
Bonsai Posted January 19, 2014 Share Posted January 19, 2014 createdVehicle is local, so u cant use it in that second function. You have to declare it outside of any function. But you should probably store them in a table anyway. vehicles = {} vehicles[player] = Link to comment
DNL291 Posted January 19, 2014 Share Posted January 19, 2014 vehicle = {} function createVehicleForPlayer(thePlayer, command, ...) local x,y,z = getElementPosition(thePlayer) -- get the position of the player local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) local vehicleName = table.concat({...}, " ") local vehID = getVehicleModelFromName ( vehicleName ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then vehicle[thePlayer] = createVehicle( vehID,x,y,z ) warpPedIntoVehicle ( thePlayer, vehicle[thePlayer] ) setVehicleDamageProof(vehicle[thePlayer], true) if (vehicle[thePlayer] == false) then -- if so, output a message to the chatbox, but only to this player. outputChatBox("Failed to create vehicle.",thePlayer) else outputChatBox("Vehicle has been created",thePlayer) end end end addCommandHandler("cv", createVehicleForPlayer) function destroy(thePlayer, command ) if isElement(vehicle[thePlayer]) then destroyElement ( vehicle[thePlayer] ) end end addCommandHandler ("dv", destroy) 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