Jump to content
Sign in to follow this  
Lala14

Question - Deleting Vehicles spawned via Script

Recommended Posts

Big thanks to Kylania for helping me add scripts to scripts ...

SHORT VERSION

I've developed a script that allows to spawn in a vehicle with createvehicle at a certain location, the issue I'm encountering is deleting said vehicles that have been spawned will only delete the latest one spawned in.

LONG INFORMATIVE VERSION

Alright so I'm quite new to scripting in arma and I was just wondering on how I remove multiple vehicles that all have been spawned in with the same name. What I'm trying to say is that I've developed a tiny script that allows for people to spawn in a vehicle via a action menu on a cash register. Now once the selected vehicle is spawned you can take it without the hassle but the issue that I'm seeing is what if people spawn in too many vehicles. e.g. 1 person spawns in a M2A1 but decides he would rather take a AMV-7 Marshall, the only way to remove the M2A1 is by using the deleteVehicle command, since in the scripts I named all vehicles myVEH this caused the "last" vehicle that has been spawned in to take the name of myVEH, so I went ahead and renamed each vehicle individually, now the other issue that I've come across is that now the "last" vehicle of that will only be deleted. e.g. 1 person spawns in 3 M2A1's but only wants one so he tries to delete 2 but can only delete 1 since only one vehicle will be called myM2A1. So after all that my issue is trying to delete a vehicle that has been spawned in via script.

here is the code for where for script.

e.g. M2A1.sqf

hint "M2A1 Slammer is being created standby";
sleep 2;
myM2 = createVehicle ["B_MBT_01_cannon_F", getPos VEH22, [], 0,"NONE"];
myM2 setDir -134.605;
[myM2] execVM "scripts\aw_unitSetup.sqf"; 
myM2 addaction ["Delete Vehicle", "deleteVehicle myM2"]
sleep 5;

Now as you can see that when using action delete vehicle will delete the vehicle named myM2.

Share this post


Link to post
Share on other sites

one misinterpretation i spot in your post is that you don't "name" the created vehicle myM2.

myM2 = createVehicle ["B_MBT_01_cannon_F", getPos VEH22, [], 0,"NONE"];

this line does the following:

the right part (right from the =) creates the desired vehicle/object inGame on the set position and then

put a reference to the created object (left from the =) in the variable myM2 for further use.

myM2 setDir -134.605; 
[myM2] execVM "scripts\aw_unitSetup.sqf";  
myM2 addaction ["Delete Vehicle", "deleteVehicle myM2"]

all examples of your further use of the object..

so to delete a created object later, especially if you lost the variable through script end or if used in the same script but filled with another object later

you need to store it in some way.

possible solutions:

- you could create an global array and fill it with the created vehicles/objects along with other needed information.

And then have another script which scans through the array for empty vehicles and deletes them.

- use a 'forEach allMissionobjects;' loop that does the same

- and there are lots of other solutions. only meant to give you an hind

greetings Na_Palm

Share this post


Link to post
Share on other sites

If you're trying to delete a vehicle from an addAction attached to the vehicle you don't need a name at all since it'll be available via _this select 0 inside the addAction.

this addAction ["Delete me!", {deleteVehicle (_this select 0)}];

You're also missing a trailing ; in the code in the first post.

Share this post


Link to post
Share on other sites

thanks again Kylania, was just also wanting to ask would this work on a dedi server?

hint "M2A1 Slammer is being created standby";
sleep 2;
myM2 = createVehicle ["B_MBT_01_cannon_F", getPos VEH22, [], 0,""];
myM2 setDir -134.605;
[myM2] execVM "scripts\aw_unitSetup.sqf"; 
myM2 addaction ["Delete Vehicle", {deleteVehicle (_this select 0)}, "_target call compile", 0, false, true, "", "driver  _target == _this"];  
sleep 5;

Share this post


Link to post
Share on other sites

Since both Hint and AddAction are local, you'd need to provide ways of the server to tell the clients to do that.

LALA_fnc_addAction = {
   private["_object","_script"];
   _object = _this select 0;
   _script = _this select 1;

   _object addAction _script;

};

"GlobalHint" addPublicVariableEventHandler
{private ["_GHint"];_GHint = _this select 1;hint parseText format["%1", _GHint];
};


_myHint ="M2A1 Slammer is being created standby";
GlobalHint = _myHint;
publicVariable "GlobalHint";
hintsilent parseText _myHint;
sleep 2;
myM2 = createVehicle ["B_MBT_01_cannon_F", getPos VEH22, [], 0,""];
myM2 setDir -134.605;
[myM2] execVM "scripts\aw_unitSetup.sqf"; 
// deleting a vehicle as driver, is... odd.
[[myM2, ["Delete Vehicle", {deleteVehicle (_this select 0)}, [], 0, false, true, "", "driver _target == _this"]], "LALA_fnc_addAction", true, true] spawn BIS_fnc_MP;

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×