manve1 Posted February 2, 2013 Share Posted February 2, 2013 Is it possible to destroy a vehicle with same name but from the same person who spawned it, not from like if one person spawns it, then next one and first vehicle that got spawned gets destroyed? Link to comment
K4stic Posted February 2, 2013 Share Posted February 2, 2013 you mean then spawn second to be destroyed the previus Vehicle? Link to comment
Puma Posted February 2, 2013 Share Posted February 2, 2013 You mean when player1 spawns an Infernus, spawns a NRG-500 and spawns another Infernus, the first spawned Infernus is destroyed? Easy. Just use a table. Script comes down to this: -- create a table in which we're going to put the vehicle-tables for players playerVehicles = {} -- create a table in which we're going to save the players that spawned the vehicles vehiclePlayers = {} function playerJoin() -- when player joins, create the player's vehicletable playerVehicles[source] = {} end function playerQuit() -- loop through all the vehicles the player spawned and destroy them for model, vehicle in pairs ( playerVehicles[source] ) do if vehicle and isElement(vehicle) then vehiclePlayers[vehicle] = nil destroyElement ( vehicle ) end end -- destroy the player's vehicleable when he leaves playerVehicles[source] = nil end -- when a vehicle is spawned by a player function playerSpawnsVehicle(player, vehicleElement) -- get the spawned vehicle's model local vehicleModel = getVehicleModel(vehicleElement) -- check if there is a value for the vehiclemodel in the player's vehicletable if playerVehicles[player][vehicleModel] and isElement(playerVehicles[player][vehicleModel]) then -- if it exists, destroy that earlier spawned vehicle destroyElement ( playerVehicles[player][vehicleModel] ) end -- set the new spawned vehicle as element for the vehiclemodel in the player's vehicletable playerVehicles[player][vehicleModel] = vehicleElement -- save who created the vehicle vehiclePlayers[vehicleElement] = player end -- if a vehicle is destroyed, delete it from the table from the player that spawned it function vehicleDestroyed() -- get player who spawned the vehicle local player = vehiclePlayers[source] -- destroy data in the player's table, if the player still exists if player and isElement(player) then playerVehicles[player][getElementModel(source)] = nil end -- remove this vehicle from the vehiclePlayers table vehiclePlayers[source] = nil end I didn't add function handlers, the function-names should explain where to put the parts in your script. Link to comment
manve1 Posted February 2, 2013 Author Share Posted February 2, 2013 Puma ur script didn't work, even i can create (( 1 person )) tons of vehicles, after all, i mean like: Two people spawn a vehicle, but when they both re-spawn their vehicles, old ones get destroyed. And Two people spawn a vehicle, when one of them re-spawns same id vehicle that was created by 'createVehicle' function, it only destroy's the person who needed re-spawn of vehicle Link to comment
Puma Posted February 2, 2013 Share Posted February 2, 2013 No duh it doesn't work on it's own, I expected you to implement it in your script. You only asked for a way how do do it and I gave an example. Link to comment
manve1 Posted February 2, 2013 Author Share Posted February 2, 2013 Is there easier way? Link to comment
Puma Posted February 2, 2013 Share Posted February 2, 2013 Easier as in a complete script? Link to comment
manve1 Posted February 2, 2013 Author Share Posted February 2, 2013 Can i do this on account data? if yes, how? Link to comment
Puma Posted February 2, 2013 Share Posted February 2, 2013 No. My script does exactly what you need, you just have to add some eventhandlers and changes some variables. 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