TorNix~|nR Posted December 19, 2017 Share Posted December 19, 2017 (edited) Hello guys, I have a marker of spawning a car, I made when a player wasted, it destroy, but I want to make it only for source not for all players, please help, I already used the destroyElement(source, vehicles99ui) but it didn't work, help please Code: addEventHandler("onPlayerWasted", root, function() if isElement(vehicles99ui) then destroyElement(source, vehicles99ui) vehicles99ui = nil end end) Edited December 19, 2017 by TorNix~|nR Link to comment
Dimos7 Posted December 19, 2017 Share Posted December 19, 2017 (edited) addEventHandler("onPlayerWasted", root, function() if isElement(vehicles99ui)and isPedDead(source) then destroyElement(vehicles99ui) vehicles99ui = nil end end) Edited December 19, 2017 by Dimos7 1 Link to comment
Awang Posted December 19, 2017 Share Posted December 19, 2017 (edited) You should use not only server side... I don't know well, what you want to make, but here is, how I understand your problem: Make a marker for all: Server side: car_marker = createMarker( 0,0,0 , "checkpoint",4,0,0,255,255) setElementData(car_marker,"type","car") You can check the hit on client side: addEventHandler ( "onClientMarkerHit", getRootElement(), function() if getElementData(source,"type") == "car" then local x,y,z = getElementPosition(getLocalPlayer()) triggerServerEvent("createVeh",root,getLocalPlayer(),x,y,z) end end) Now create veh on Server: addEvent("createVeh",true) addEventHandler("createVeh",getRootElement(),function(player,x,y,z) local veh = createVehicle ( 432,x+10,y+10,z+3) triggerClientEvent(player,"synMyVeh",player,veh) end) Receive and save the car element on client and write a death handler: addEvent("synMyVeh",true) local myCar = nil addEventHandler("synMyVeh",root,function(veh) myCar = veh end) addEventHandler("onClientPlayerWasted",root,function() triggerServerEvent("deleteMyVeh",root,myCar) end) And delete only the client car in server side(maybe you can solve this in client side, not tested) addEvent("deleteMyVeh",true) addEventHandler("deleteMyVeh",getRootElement(),function(vehicle) destroyElement(vehicle) end) All the code not tested.... Edited December 19, 2017 by Awang 1 Link to comment
TorNix~|nR Posted December 19, 2017 Author Share Posted December 19, 2017 Thank you guys, @Dimos7, it's the same, when any player dead, it destroy Awang, I think there is a way on the server-side, help please? Link to comment
Awang Posted December 19, 2017 Share Posted December 19, 2017 (edited) You can't use only serverside for that problem if you want to delete only the clien's car on the client death... Try the code, what I'm wrote... Edited December 19, 2017 by Awang Link to comment
TorNix~|nR Posted December 19, 2017 Author Share Posted December 19, 2017 Yes, I will, I'm sorry I told that because I'm using this script so many times for other teams, if your script works, I should take a long time to add them all I will try it, ty Link to comment
Awang Posted December 19, 2017 Share Posted December 19, 2017 Your way, but you need to use client side, or maybe an assoc server table with the car elements ( where the table keys can be the player name) , but I don't really suggest that... Just a little communication between the client and server... 1 Link to comment
TorNix~|nR Posted December 19, 2017 Author Share Posted December 19, 2017 Thank you so much @Awang, I appreciate your help, but I want to use it only for server side, I will wait for someone, thank alot Any help please? Link to comment
Dimos7 Posted December 19, 2017 Share Posted December 19, 2017 (edited) you mean you want a vehicle destoryed insde of all the players? Edited December 19, 2017 by Dimos7 Link to comment
TorNix~|nR Posted December 19, 2017 Author Share Posted December 19, 2017 I want only for the player it destroy the vehicle the problem is when I get the vehicle and when any player died, it destroy, I want it to be destroyed only if the player (source) died if you want, I can post the full code Link to comment
Dimos7 Posted December 19, 2017 Share Posted December 19, 2017 (edited) addEventHandler("onPlayerWasted", root, function() car = getPedOccupiedVehicle(source) if isPedInVehicle(source) and isPedDead(source) then destroyElement(car) end end) Edited December 19, 2017 by Dimos7 Link to comment
TorNix~|nR Posted December 19, 2017 Author Share Posted December 19, 2017 the same here is the full code mark = createMarker( x,y,z, "cylinder", 2, 169, 199, 29, 150 ) vehicles99ui = {} function fun(hitPlayer) local x, y, z = getElementPosition(source) if hitPlayer and getElementType(hitPlayer) == "player" and not isPedInVehicle (hitPlayer) then if ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "team" ) ) then if isElement(vehicles99ui) then destroyElement(vehicles99ui) end vehicles99ui = createVehicle(522, 1680.89, 957.67, 10.70) setVehicleColor (vehicles99ui, 169, 199, 29, 169, 199, 29) warpPedIntoVehicle(hitPlayer, vehicles99ui) else outputChatBox ("fail",hitPlayer, 169, 199, 29, true) end end end addEventHandler("onMarkerHit",mark,fun) addEventHandler("onPlayerWasted", root, function() if isElement(vehicles99ui) then destroyElement(vehicles99ui) vehicles99ui = nil end end) Link to comment
kieran Posted December 19, 2017 Share Posted December 19, 2017 (edited) Here's an idea (someone helped me understand this as I had similar issues) try setting the players element data to the vehicle, then when they die, get the data, here's untested code, if it doesn't work do a debugscript 3 and tell me the errors. function spawnVeh (thePlayer) --This function adds a command that spawns a car and sets players data, we will remove the car later local x, y, z = getElementPosition (thePlayer) --Get players position local rotX, rotY, rotZ = getElementRotation (thePlayer) --Get there rotation veh = createVehicle (468, x, y, z+5, rotX, rotY, rotZ) --Create the vehicle at the players position +5 height warpPedIntoVehicle (thePlayer, veh) --Warp the player into the vehicle setElementData(thePlayer, "freecar", veh) --Set the players data to the car end addCommandHandler("sanchez", spawnVeh) --When command is passed we create a sanchez above and set players data function removeVehicle () local theVeh = getElementData( source, "freecar" ) --First we get the players element data if ( theVeh ~= false ) then --If the data exists, it means the vehicle exists (unless you have done above command and the car gets destroyed) destroyElement(theVeh) --Since we got the element with getElementData above we can now destroy it setElementData(source, "freecar", false) --We now set the players data to false. end end addEventHandler("onPedWasted", getRootElement(), removeVehicle) --When player dies we trigger our function to check there data Hopefully this works! Edited December 19, 2017 by kieran Forgot spawnVehicle existed xD 1 Link to comment
Dimos7 Posted December 19, 2017 Share Posted December 19, 2017 remove the line 3 mate line 3 make it table 1 Link to comment
TorNix~|nR Posted December 19, 2017 Author Share Posted December 19, 2017 (edited) @kieran, finally it worked, in the place of command, I made the event handler of marker, and I added the marker, and I added the team access, and it working, ty Edited December 19, 2017 by TorNix~|nR 1 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