timebomb18 0 Posted May 15, 2017 Hello! I need a script that causes the enemy to die, drop an expecific item, does anyone have a light? Share this post Link to post Share on other sites
pierremgi 4739 Posted May 15, 2017 One specific enemy? theBadBoy spawn { waitUntil {sleep 1; !alive _this}; _wh = "groundWeaponHolder" createVehicle (getpos _this); _wh addItemCargoGlobal ["<yourItemClassHere>",1]; }; Replace addItemCargoGlobal for addMagazineCargoGlobal or addweaponCargoGlobal if required. For all enemies: { _x addEventHandler ["killed",{ (_this select 0) spawn { waitUntil {sleep 1; !alive _this}; _wh = "groundWeaponHolder" createVehicle (getpos _this); _wh addItemCargoGlobal ["<yourItemClassHere>",1]; } }] } forEach (allUnits select {<the enemey side or getfriend>}); (Need to be added also on enemy spawned units). Share this post Link to post Share on other sites
timebomb18 0 Posted May 15, 2017 In case it is to spawn on all enemies. How to put a Drop Rate%? Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 15, 2017 The script did not work :'( Share this post Link to post Share on other sites
pierremgi 4739 Posted May 15, 2017 4 hours ago, Lucas Andreatta said: The script did not work :'( What script? Mine must be adapted with your units and "items". As I said, this can be magazine, item weapons.. So, save time, show yours. Share this post Link to post Share on other sites
pierremgi 4739 Posted May 15, 2017 4 hours ago, timebomb18 said: In case it is to spawn on all enemies. How to put a Drop Rate%? drop rate? Share this post Link to post Share on other sites
Belbo 461 Posted May 15, 2017 { _x addEventHandler ["killed",{ (_this select 0) spawn { waitUntil {sleep 1; !alive _this}; if (floor random 10 > 8) then { _wh = "groundWeaponHolder" createVehicle (getpos _this); _wh addItemCargoGlobal ["<yourItemClassHere>",1]; }; } }] } forEach (allUnits select {<the enemey side or getfriend>}); Adds a 10% chance to drop an item. Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 15, 2017 { _x addEventHandler ["killed",{ (_this select 0) spawn { waitUntil {sleep 1; !alive _this}; if (floor random 10 > 8) then { _wh = "groundWeaponHolder" createVehicle (getpos _this); _wh addItemCargoGlobal ["Suitcase",1]; }; } }] } forEach (allUnits select {EAST}); It does not work, the AI does not drop anything. I was spawning via ALIVE, tried it manually and it also did not work. I put the code in init.sqf right? Share this post Link to post Share on other sites
Belbo 461 Posted May 15, 2017 Have you even got an item called "Suitcase"? Or do you mean object "Land_Suitcase_F"? Land_Suitcase_F is not an item, it's an object, hence: { _x addEventHandler ["killed",{ if (floor random 10 > 8) then { _suitcase = "Land_Suitcase_F" createVehicle (getpos (_this select 0)); }; }] } forEach (allUnits select {EAST}); It will only work for units that are present at mission start and, the way it's written right now, of side east. Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 15, 2017 Yes, I copied a "suitcase" class from eden editor. This script dont work with ALIVE? Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 15, 2017 FUS_fnc_moneyDrop = { _money = createVehicle ["Land_Laptop_unfolded_F", getPosATL (_this select 0), [], 0, "CAN_COLLIDE"]; _moneyId = _money addAction ["pick up the intel", {call FUS_fnc_moneyGrab;}]; }; FUS_fnc_moneyGrab = { deleteVehicle (_this select 0); hint "You've acquired some intel"; pMoney = pMoney + 100; }; { if (side _x isEqualTo EAST) then { _x addEventHandler ["Killed", {call FUS_fnc_moneyDrop;}]; }; } forEach allUnits; In another forum, they passed me this script. It worked, but it talks about money, I do not understand. My ultimate goal is to make AI drop intel to reveal the ammo cache. Share this post Link to post Share on other sites
Belbo 461 Posted May 15, 2017 There is no class called suitcase. That might be the description of the object, but it isn't a classname. Here you can find all of vanilla classnames: https://community.bistudio.com/wiki/Arma_3_Assets If you use alive to spawn in enemies, you'd have to apply the killed-EventHandler to every newly spawned unit for it to work. I don't know if Alive offers an option to execute code on newly spawned units. You could try something like this: 0 spawn { if (isServer) then { while {true} do { sleep 10; { if !(_x getVariable ["hasIntelEVH",true]) then { _x addEventHandler ["killed",{ params ["_unit"]; if (floor random 10 > 8) then { _suitcase = "Land_Suitcase_F" createVehicle (getpos _unit); [_suitcase,["Pick up INTEL", {hint "you have intel, clever one, you."}]] remoteExec ["addAction",2]; }; }]; }; nil; } count (allUnits select {EAST}); }; }; }; That will loop every 10 seconds, run through all units of side east, but will add the evh only if they don't have the variable hasIntelEVH on true attached - and create the variable at the same time, so a unit will not have the evh twice. #edit: At best you look up the function, syntax and implications of each and every command here, so you might understand it. https://community.bistudio.com/wiki/Special:Search Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 16, 2017 Spoiler Error Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 16, 2017 I tried to replace "count (allUnits select {EAST});" by "forEach allUnits;" (just for testing) and gave this: Spoiler Share this post Link to post Share on other sites
pierremgi 4739 Posted May 16, 2017 { _unit = _x; if !(_unit getVariable ["hasIntelEVH",true]) then {... ..... } forEach (allUnits select {side _x == EAST}); Share this post Link to post Share on other sites
Belbo 461 Posted May 16, 2017 Yeah, that was my bad. I forgot to exchange the _unit-bit. I edited my post above with a correct and possibly working loop. You can't just throw a while-loop in your init.sqf. Nothing after the while loop will be executed until the loop is done looping. That's why I put it in a spawn. Again: At best you look up the function, syntax and implications of each and every command here, so you might understand it. https://community.bistudio.com/wiki/Special:Search Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 16, 2017 It did not work yet pierremgi ... I do not understand programming, I know the basics of eden editor, so I came to ask for help here :/ Share this post Link to post Share on other sites
pierremgi 4739 Posted May 17, 2017 I guess you want more than a "drop if an enemy die"... drop rate... for all killed enemies?, or once one has dropped the suitcase, there is no more reason to drop another one? anyway, try this (20% rate with random 10 > 8 ) 0 = [] spawn { if (isServer) then { while {true} do { sleep 10; { _unit = _x; if !(_unit getVariable ["hasIntelEVH",false]) then { _unit addEventHandler ["killed",{ params ["_unit"]; if (random 10 > 8) then { _suitcase = "Land_Suitcase_F" createVehicle (getpos _unit); [_suitcase,["Pick up INTEL", {hint "you have intel, clever one, you."}]] remoteExec ["addAction"]; }; }]; _unit setVariable ["hasIntelEVH",true]; }; } forEach (allUnits select {side _x == EAST}); }; }; }; There are some other details to fix, like removing the addaction... 1 Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 17, 2017 Hell yeah, it worked !! Thank you so much guys. Where do I put the removeaction? Is he going to make the suitcase disappear? How do I make a drop rate (%) setting parameter? Share this post Link to post Share on other sites
pierremgi 4739 Posted May 17, 2017 kill the action inside it!: replace: [_suitcase,["Pick up INTEL", {hint "you have intel, clever one, you."}]] remoteExec ["addAction",2]; by: [_suitcase,["Pick up INTEL", {params ["_suitcase","_caller","_id"]; hint "you have intel, clever one, you."; [_suitcase,_id] remoteExec ["removeAction"] } ] ] remoteExec ["addAction",0,_suitcase]; Note (advanced): removed also the "2" on remoteExec addAction. That doesn't make sense, even if the object is on server. You need to add the action for every players. I replaced it by 0 like for an hosted server. You can write -2 instead for a dedicated server. No,the suitcase is still here. You can delete it if you add: deleteVehicle _suitcase: [_suitcase,["Pick up INTEL", {params ["_suitcase","_caller","_id"]; hint "you have intel, clever one, you."; [_suitcase,_id] remoteExec ["removeAction"]; deleteVehicle _suitcase } ] ] remoteExec ["addAction",0,_suitcase]; Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 17, 2017 Many thanks for your patience. Is the params correct? class Params { class _dropRate { title = "Drop Rate"; // Param name visible in the list values[] = {10,20,30,40,50}; // Values; must be integers; has to have the same number of elements as 'texts' texts[] = {"10","20","30","40","50"}; // Description of each selectable item default = 20; // Default value; must be listed in 'values' array, otherwise 0 is used }; }; Share this post Link to post Share on other sites
pierremgi 4739 Posted May 17, 2017 Not exactly. Class is not a local variable. Change for: class dropRate (I'd place texts above values. I don't remember if it's mandatory...) That's for the description.ext Now, you have to extract the value in your script: 0 = [] spawn { if (isServer) then { while {true} do { { _unit = _x; if !(_unit getVariable ["hasIntelEVH",false]) then { _unit addEventHandler ["killed",{ params ["_unit"]; if (random 100 < ("droprate" call BIS_fnc_getParamValue) ) then { _suitcase = "Land_Suitcase_F" createVehicle (getpos _unit); [_suitcase,["Pick up INTEL", {params ["_suitcase","_caller","_id"]; hint "you have intel, clever one, you."; [_suitcase,_id] remoteExec ["removeAction"]; deleteVehicle _suitcase } ] ] remoteExec ["addAction",0,_suitcase]; }; }]; _unit setVariable ["hasIntelEVH",true]; }; } forEach (allUnits select {side _x == EAST}); sleep 10; }; }; }; Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 17, 2017 Hell yeah, it worked !!! thank you so much! Share this post Link to post Share on other sites
Lucas Andreatta 1 Posted May 18, 2017 Taking advantage of the post, I got a way to spawn caches without scripts, but as I do when I get INTEL, there will appear marks on the map approaching the location of the cache? Share this post Link to post Share on other sites