Jump to content
Dreadleif

Deleting all dropped items for spawned units in SIDE

Recommended Posts

Hello!  ;) I have been struggling with this one challenge for a long time, I'd be super thankful if anyone could help me with. I'm making a Jagged Alliance map, and it's looking really good despite my lacking skills. I'm trying to accomplish what it says in the title, preferably I'd want this script(s) to:

 

 

 

  1.  Delete items from all killed OPFOR units (spawned and otherwise)
     
  2.  The killed AI then spawns a random item on the ground instead, from a pool of items defined in script

 

 

 

 

notatallwhatiwanted.sqf

//DELETE GEAR
{_x addeventhandler ["killed",{
_this spawn {_unit = _this select 0; removeallweapons _unit;removeallassigneditems _unit;removeheadgear _unit;clearmagazinecargo _unit;sleep 60; deletevehicle _unit};
}];
} forEach allUnits;

I really hope there is some way to do this, it would be a saving grace for my mission :b: 

Share this post


Link to post
Share on other sites
Guest

Hello. You need to include the nearest Weapon holder in your script or it will not remove it all.

Share this post


Link to post
Share on other sites

Hello. You need to include the nearest Weapon holder in your script or it will not remove it all.

Thank you for your feedback, but I'm no closer to a solution. The script I posted actually works perfectly when run from the init.sqf, but it removes items for ALL units of all sides, and doesn't spawn any items on the location of the dead soldier (not as important).

 

Still hoping to get this solved tonight, would be soo awesome. :)

Share this post


Link to post
Share on other sites

Ok, the first issue is easy:

//DELETE GEAR
{if (side _x == EAST) then {_x addeventhandler ["killed",{
_this spawn {_unit = _this select 0; removeallweapons _unit;removeallassigneditems _unit;removeheadgear _unit;clearmagazinecargo _unit; sleep 60; deletevehicle _unit};
}];
}} forEach allUnits;

About the second, you have to describe what ítems you want to spawn and do what with them.

 

But will be something like, inside the spawn:

 

_pos = position _unit;

deleteehicle _unit;

_item = createVehicle [itemClassName, _pos,[],0,"NONE"]

  • Like 1

Share this post


Link to post
Share on other sites

Ok, the first issue is easy:

//DELETE GEAR
{if (side _x == EAST) then {_x addeventhandler ["killed",{
_this spawn {_unit = _this select 0; removeallweapons _unit;removeallassigneditems _unit;removeheadgear _unit;clearmagazinecargo _unit; sleep 60; deletevehicle _unit};
}];
}} forEach allUnits;

About the second, you have to describe what ítems you want to spawn and do what with them.

 

But will be something like, inside the spawn:

 

_pos = position _unit;

deleteehicle _unit;

_item = createVehicle [itemClassName, _pos,[],0,"NONE"]

 

This doesn't run for spawned units though, only for units placed in the editor (run from the init.sqf). Thanks so much for the answer though, definitely in the right direction!

Share this post


Link to post
Share on other sites

Ah, for spawning units is easier.

 

After your createUnit line, like:

 

_unit = _group createUnit bla bla

 

_unit addEventHandler ["Killed", blablá]

  • Like 1

Share this post


Link to post
Share on other sites

Cool! I'll see what I can do, not good at writing scripts.

 

And anyone got an idea on how to do the item drop thing? :)

Share this post


Link to post
Share on other sites

I told you how in my first post

 

Sorry, but I didn't understand how to form the script at all. As I said in the original post, I'm really not good with scripts. I really don't know how to write this myself, which is why I asked for help. I think I emphazised how bad I am at scripting and that I really needed help forming the entire scripts(s), thanks for your help though, barbolani :) 

Share this post


Link to post
Share on other sites

Then what you have to do is to tell me what ítem you want to spawn instead of the body and if you want any interaction between players and the ítem itself.

Share this post


Link to post
Share on other sites

Ok, I will post more substantially on the challenge and what I'm trying to achieve. I'm learning to script just this week, so I'm learning by changing and failing (mostly failing), so this is taking me hours instead of what would be minutes for most.. Example scripts below:

 

 

spawnsoldiers.sqf

I want to change this noob script to instead spawn the group regularily in a wave every 10-30 minutes randomly (still on marker), and the soldiers in random numbers from 1-10, as long as "spawnobject" is alive (so I can eventually stop the spawning).

 

As they spawn, I want to activate another two scripts on them, one which removes all the gear on their bodies when they are killed (eventhandler), and one which spawns a random item under their body from a list of items.

 

For now, lets say those random items are "16Rnd_9x21_Mag", "30Rnd_65x39_caseless_mag" or "SMG_01_F".

if (isServer) then {
_grp = createGroup EAST; // This will be needed for later on in the createUnit command.
//SPAWN SOLDIERS
_soldier = _grp createUnit ["O_HeavyGunner_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier addHeadgear "H_HelmetB_desert"; _soldier forceAddUniform "U_BG_leader";
_soldier1 = _grp createUnit ["O_Soldier_AA_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier1 addHeadgear "H_Booniehat_dgtl"; _soldier1 forceAddUniform "U_BG_leader"; _soldier1 unassignItem "NVGoggles_OPFOR"; _soldier1 removeItem "NVGoggles_OPFOR";
_soldier2 = _grp createUnit ["O_sniper_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier2 addHeadgear "H_Booniehat_dgtl"; _soldier2 forceAddUniform "U_BG_leader"; _soldier2 unassignItem "NVGoggles_OPFOR"; _soldier2 removeItem "NVGoggles_OPFOR";
_soldier3 = _grp createUnit ["O_recon_TL_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier3 addHeadgear "H_Cap_blk_Raven"; _soldier3 forceAddUniform "U_BG_leader"; _soldier3 unassignItem "NVGoggles_OPFOR"; _soldier3 removeItem "NVGoggles_OPFOR";
_soldier4 = _grp createUnit ["O_recon_TL_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier4 addHeadgear "H_Cap_blk_Raven"; _soldier4 forceAddUniform "U_BG_leader";
//Make more etc..

//SET WAYPOINT
_Pos1 = getMarkerPos "spawnguardgo";
wp =_grp addWaypoint [_Pos1, 0];

};

This is the heart and soul of my mission and would really unlock everything if I got it working :).

 

 

 

 

_________________________________________________________________________________________________________

 

PS: My shabby attempt at making the script I referenced above, don't use it as template.

 

 

removegearkilled.sqf

...this works for people who want to activate it once at the start of the mission, from init.sqf, but it is not what I want, which is adding this eventhandler to spawned units regularly through the mission.

//DELETE GEAR
{if (side _x == EAST) then {_x addeventhandler ["killed",{
_this spawn {_unit = _this select 0; removeallweapons _unit;removeallassigneditems _unit;removeheadgear _unit;clearmagazinecargo _unit; sleep 60; deletevehicle _unit};
}];
}} forEach allUnits;

Share this post


Link to post
Share on other sites

ok, so you want those soldiers to get deleted and leave some ammo on the floor, Wolfenstein style, isn't it?

 

I need to be at home to give you the right solution, but is on the way I told you in my first post, so you can do some homework: check createVehicle command on biki (works like createUnit, easier indeed) and try to create a car in the position of the CSAT corpse. Is not that hard once you reached today's status.

 

Anyway: do you really like the idea? I mean: some ammo in the floor is hard to be seen for the players. Dead bodies do not compsume much CPU, so, if you want to give the players a "prize" for killing enemies, I think is enough with the dead men inventory... isn't it? And if we talk about realism...

 

BTW letme say when I was 1 month scripting I was far far behind you are now.

Share this post


Link to post
Share on other sites

Thanks! I really love making this homage to JA:2, and I almost wanna show the mission just to explain why the item drop is a big deal: Basically each player can earn cash (cash = 0; in unit init), and then buy weapons and ammo (cash = cash - 100;). I made a GUI look like a computer where you can press buttons to buy stuff (hooked to a .sqf), then it subtracts from your cash. The prices are steep and they have to manage everything well and defend towns, so if soldiers dropped weapons everywhere that would "crash the economy". ;)

 

I don't want ammo to spawn on the ground. What would be preferable was if the random drops I described above would actually be ON the dead bodies, instead of their default gear :). If you've ever played Jagged Alliance 2 (which this is based on) you'd quickly recognice the similarities ;). One disclaimer: I have written 5% of the content in these scripts myself, I just pick up things and google search...a lot.

 

UPDATE: I fooled around with the spawning script, and suddenly this worked!

if (isServer) then {
_grp = createGroup EAST; // This will be needed for later on in the createUnit command.

//SPAWN SOLDIERS
_soldier = _grp createUnit ["O_HeavyGunner_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier addHeadgear "H_HelmetB_desert"; _soldier forceAddUniform "U_BG_leader";
_soldier1 = _grp createUnit ["O_Soldier_AA_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier1 addHeadgear "H_Booniehat_dgtl"; _soldier1 forceAddUniform "U_BG_leader"; _soldier1 unassignItem "NVGoggles_OPFOR"; _soldier1 removeItem "NVGoggles_OPFOR";
_soldier2 = _grp createUnit ["O_sniper_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier2 addHeadgear "H_Booniehat_dgtl"; _soldier2 forceAddUniform "U_BG_leader"; _soldier2 unassignItem "NVGoggles_OPFOR"; _soldier2 removeItem "NVGoggles_OPFOR";
_soldier3 = _grp createUnit ["O_recon_TL_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier3 addHeadgear "H_Cap_blk_Raven"; _soldier3 forceAddUniform "U_BG_leader"; _soldier3 unassignItem "NVGoggles_OPFOR"; _soldier3 removeItem "NVGoggles_OPFOR";
_soldier4 = _grp createUnit ["O_recon_TL_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier4 addHeadgear "H_Cap_blk_Raven"; _soldier4 forceAddUniform "U_BG_leader"; 


//_soldier addEventHandler ["killed", "removeallweapons _unit;removeallassigneditems _unit;removeheadgear _unit;removevest _unit;clearmagazinecargo _unit; sleep 60; deletevehicle _unit"];


//SET WAYPOINT
_Pos1 = getMarkerPos "spawnguardgo";
wp =_grp addWaypoint [_Pos1, 0];

[]execVM "scripts\removegearkilled.sqf";

};

removegearkilled.sqf

//DELETE GEAR
{if (side _x == EAST) then {_x addeventhandler ["killed",{
_this spawn {_unit = _this select 0; removeallweapons _unit;removeallassigneditems _unit;removeheadgear _unit;clearmagazinecargo _unit; sleep 60; deletevehicle _unit};
}];
}} forEach allUnits;

This is all like magic to me :459: , but I'm learning by doing!  :627:

 

One last piece is missing in this picture for me to move on: the random item (placed on the body or dropped) next to dead OPFOR soldiers.. I'm looking through the stuff you mentioned above till then.. :D Correction: I have been making maps for a long time for fun with my friends, but this last week is the first time I've gotten into scripting ^^.

Share this post


Link to post
Share on other sites

What remains:

 

Making the AI spawn at 10-30 minute intervals, randomly, making their numbers between 1-10 randomly (they can be the "same soldier" for this purpose), and making them drop random items from a list when they die :) :)..

 

(is this at all possible?)

Share this post


Link to post
Share on other sites

Simply put: Is there any way to make this line repeat a random number of times between 1-10 in the script?

_soldier = _grp createUnit ["O_HeavyGunner_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; _soldier addHeadgear "H_HelmetB_desert"; _soldier forceAddUniform "U_BG_leader";

To someone with the knowledge, it doesn't seem too difficult :).. But I am stuck.

 

Could this be used: for "_i" from 1 to random(10) do{}; ? How would I make that work with this simple soldier spawn..?

Share this post


Link to post
Share on other sites

Exactly. But promise me you will try to understand each line of code. I am not testing this, but you will be able to make it work:

 

spawn script:

while {true} do
{
sleep 600 + random 1200;

_grp = createGroup EAST;


for "_i" from 1 to round (random 10) do

{

_soldier = _grp createUnit ["O_HeavyGunner_F",(getmarkerpos "spawnguard"),[],0,"NONE"]; 
_soldier addHeadgear "H_HelmetB_desert"; 
_soldier forceAddUniform "U_BG_leader";

}
_wp = _grp addWaypoint [getMarkerPos "spawnguardgo",0];

{_x addEventHandler ["Killed",[_this select 0] execVM "bodyManagement.sqf"]} forEach units _grp;
};





"bodyManagement.sqf":

_unit = _this select 0; 
removeallweapons _unit;
removeallassigneditems _unit;
removeheadgear _unit;
clearmagazinecargo _unit; 
sleep 60; 
deletevehicle _unit;

Now about the money, prizes etc.. I haven't played that so I cannot tell you.

 

The easiest way, instead of adding any item or weapon on the dead body is to give money to the player.

 

Then setVariable is your command.

 

There was a nice tutorial around explaining this command with a driving license for players, can't remember the name or author but was fantastic. Check that.

Share this post


Link to post
Share on other sites

There are also a couple of bugs in the first code

 

}  missing a ;

 

and   {_x addEventHandler ["Killed",[_this select 0] execVM "bodyManagement.sqf"]} forEach units _grp;

 

needs to be {_x addEventHandler ["Killed",{[_this select 0] execVM "bodyManagement.sqf" } ]} forEach units _grp;

Share this post


Link to post
Share on other sites

Thanks guys! Writing this from my phone but will test it when i get home. Oh yes, barbolani, i learn so much from this, for example i just learned how to do random loops and random numbers :D, hope it works!

Still hoping someone could show me how to spawn random items on dead bodies :)

Share this post


Link to post
Share on other sites

f2k sel is true, thanks.

 

Check createVehicle command in biki.

 

In bodyManagement.sqf, right before unit deletion:

 

_randomItem = createVehicle [["itemclassname1","itemclassname2","itemclassnameN"] call BIS_fnc_selectRandom,position _unit,[],0,"CAN_COLLIDE"];

sleep 60;

deleteVehicle _randomItem;//so it gets deleted someday

 

"ItemClassName1" is the ítem class you may find in cfgVehicles, it can be a car, a backpack, whatever...

Share this post


Link to post
Share on other sites

Thanks all so much!! I'll stop posting in this thread now until I've tested everything and read through everything you've so kindly shared.

 

Thanks again, Barbolani for that correction. Checked out your Antistasi, amazing work. Hope I'll be able to do something similar one day. Now for the testing..

 

____________________________________________________________________________

 

 

UPDATE: I finally get to do this... :lol: ehem... Excuse me barbolani but

 

 

while {true} do
{
sleep 600 + random 1200;

 

should be

 

while {true} do
{
sleep (600 + (random 1200));

 

:D

Share this post


Link to post
Share on other sites

Thanks but, ehm, I'm pretty sure this doesn't work for spawning items, but is for actual vehicles??  :huh:

_randomItem = createVehicle [["16Rnd_9x21_Mag","9Rnd_45ACP_Mag"] call BIS_fnc_selectRandom,position _unit,[],0,"
CAN_COLLIDE"];

UPDATE:

This seems to work but only spawns one..

_randomitem addWeaponcargoglobal [["launch_RPG32_F", 1],["srifle_DMR_01_DMS_F", 1]] call BIS_fnc_selectRandom;

Tried this but didn't work =(

_randomitem addWeaponcargoglobal [["launch_RPG32_F", 1],["srifle_DMR_01_DMS_F", 1]] call BIS_fnc_selectRandom;
//_randomitem addWeaponcargoglobal ["launch_RPG32_F", 1,"srifle_DMR_01_DMS_F", 1] call BIS_fnc_selectRandom;//fail

Found it. This works instead of what barbolani posted (for anyone looking in the future)!

 

//DEFINE RANDOM ITEM
_randomitem = createVehicle ["groundWeaponHolder",position _unit,[],0,"can_collide"];

//SPAWN RANDOM ITEM
_rndNum = floor(random(4));
switch (_rndNum) do
{
    case 0: {_randomitem addWeaponcargoglobal ["launch_RPG32_F", 1]};
    case 1: {_randomitem addWeaponcargoglobal ["launch_RPG32_F", 3]};
    case 2: {_randomitem addWeaponcargoglobal ["launch_RPG32_F", 5]};
    case 3: {_randomitem addWeaponcargoglobal ["launch_RPG32_F", 10]};
    default {};
};

 

EDIT: I got it Barbolani, I made items on their uniforms instead, easier to find, thanks again :)

Share this post


Link to post
Share on other sites

Because you are confusing vehicle classnames with item/magazine classnames.

 

Things like "16Rnd_9x21_Mag" are magazine classnames, and are used with commands like addMagazineCargo, that's not an object you can place in the map.

 

Look at what says the biki in createVehicle:  (type is the name of the subclass in CfgVehicles)

 

This is, between brackets you have to put a vehicle classnames. For example to create a zodiak: "C_Rubberboat" 

 

But for example this is a vehicle classname of a weapon: "Weapon_arifle_MXC_F"

 

Thats the vehicle classname for the rifle on the floor, but not the classname to add it to your inventory, understand?

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

×