Jump to content

hide currently vehicle with command.


Annas

Recommended Posts

please help , i tried to change onPlayerQuit to a Command Handler .. i wish you understand me..

i have made a vehicle system , but i didnt complete it yet for this reason , when i quit , all currently vehicles spawned destroyed by this function

function SaveVehicleDataOnQuit() 
    for i, veh in ipairs (getElementsByType("vehicle")) do 
        if getElementData(veh, "Owner") == source then 
            destroyVehicle(veh) 
        end 
    end 
end 
addEventHandler("onPlayerQuit", root,SaveVehicleDataOnQuit) 

i try to change "addEventHandler("onPlayerQuit", root,SaveVehicleDataOnQuit)" to addcommandhandler, i do it like this:

function SaveVehicleDataOnQuit() 
    for i, veh in ipairs (getElementsByType("vehicle")) do 
        if getElementData(veh, "Owner") == source then 
            destroyVehicle(veh) 
        end 
    end 
end 
addCommandHandler("hide",SaveVehicleDataOnQuit) 

but not work with the command handler :/ , please help me

Link to comment

In your second code source isn't defined, if you want to destroy the vehicle of the player who typed the command you have to add a parameter to the function (thePlayer for example) which will be the player who typed the command (as described in the wiki) and replace source with the parameter "name" (thePlayer using my example...).

function SaveVehicleDataOnQuit( thePlayer ) -- define thePlayer 
    for i, veh in ipairs (getElementsByType("vehicle")) do 
        if getElementData(veh, "Owner") == thePlayer then   -- replace source with thePlayer 
            destroyVehicle(veh) 
        end 
    end 
end 
addCommandHandler("hide",SaveVehicleDataOnQuit) 

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...