KariiiM Posted July 28, 2015 Share Posted July 28, 2015 Helle guys, i have a small problem in same time big one, i scripter a simple shop for fun everything scripted sucessfully but ,When i add the Event "onVehicleExplosde",if just one player's vehicle explosed then all other vehicles gonna explodes too. Thanks in advance. function onVehicleExplode() destroyElement(Vehicle) end addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode) Here's a part of my code: --Ser-Side: function onVehicleExplode() destroyElement(Vehicle) end addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode) local Cash = 500000 function rentVehicle () if ( getPlayerMoney ( source ) < Cash ) then outputChatBox("You need 300,000$ to rent this vehicle.", source, 255,0,0) else takePlayerMoney(source, Cash) if (getElementZoneName(source) == "Los Santos International") then Vehicle= createVehicle(425, 1924.5841064453, -2291.1552734375, 13.5) warpPedIntoVehicle(source, Vehicle) else Vehicle= createVehicle (425,1485.49, 1231.93, 10.82,0,0,180) end warpPedIntoVehicle(source, Vehicle) end end addEvent ("rentV", true) addEventHandler ("rentV", root, rentVehicle) Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 (edited) local Vehicle = {} function onVehicleExplode() destroyElement(Vehicle[getVehicleOccupant(source)]) end addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode) local Cash = 500000 function rentVehicle () if ( getPlayerMoney ( source ) < Cash ) then outputChatBox("You need 300,000$ to rent this vehicle.", source, 255,0,0) else takePlayerMoney(source, Cash) if (getElementZoneName(source) == "Los Santos International") then Vehicle[source]= createVehicle(425, 1924.5841064453, -2291.1552734375, 13.5) warpPedIntoVehicle(source, Vehicle[source]) else Vehicle[source]= createVehicle (425,1485.49, 1231.93, 10.82,0,0,180) end warpPedIntoVehicle(source, Vehicle[source]) end end addEvent ("rentV", true) addEventHandler ("rentV", root, rentVehicle) Edited July 28, 2015 by Guest Link to comment
Buffalo Posted July 28, 2015 Share Posted July 28, 2015 Wow man, simple rules: -Try never use events and functions with same name -Use global constants carefully This should work for you: function vehicleExplodeRented() if getElementData(source,'rented') then destroyElement(source) end end addEventHandler("onVehicleExplode", getRootElement(), vehicleExplodeRented) local Cash = 500000 function rentVehicle () if ( getPlayerMoney ( source ) < Cash ) then outputChatBox("You need 300,000$ to rent this vehicle.", source, 255,0,0) else takePlayerMoney(source, Cash) if (getElementZoneName(source) == "Los Santos International") then local Vehicle = createVehicle(425, 1924.5841064453, -2291.1552734375, 13.5) warpPedIntoVehicle(source, Vehicle) setElementData(Vehicle,'rented',true,false) else local Vehicle = createVehicle (425,1485.49, 1231.93, 10.82,0,0,180) warpPedIntoVehicle(source, Vehicle) setElementData(Vehicle,'rented',true,false) end end end addEvent ("rentV", true) addEventHandler ("rentV", root, rentVehicle) 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