kahmoon2k 10 Posted May 9, 2013 Hello, I'm wondering if anyone can give me any pointers on the following. I would like to create a script that creates a trigger. This trigger then needs to reference the unit that executes the script when it is activated. Since I would like the script to be able to be run multiple times for different units, I cannot simply name the unit that executes the script and then reference that name, neither can I use the script to set a particular name for the unit which is then referenced by the trigger. I've been considering creating an array with names which are incremented when the script executes, but I'm not sure if this is a good solution or, frankly, how to do it. My attempt so far is something like this (just an example, where the intention is to give a magazine to a unit when a western unit comes close): _man = _this _trg=createTrigger["EmptyDetector",getPos _man]; _trg setTriggerArea[10,10,0,false]; _trg setTriggerActivation["West","present",false] _trg setTriggerStatements ["this","[color="#FF0000"]???[/color] addMagazine '30Rnd_65x39_caseless_green'","null"] If I replace the ??? with _man, it doesn't work - I presume because _man is a local variable, and the trigger needs to reference a global. Anyway, I've been trying to figure this out myself for a while with no luck, so I'd very much appreciate any help or ideas. Thanks! Share this post Link to post Share on other sites
f2k sel 145 Posted May 9, 2013 Maybe this will work but I'm not sure about how it will function in MP situation. player setvariable ["man",_this,true]; _trg=createTrigger["EmptyDetector",getPos _man]; _trg setTriggerArea[10,10,0,false]; _trg setTriggerActivation["West","present",false]; _trg setTriggerStatements ["this","(player getvariable 'man') addMagazine '30Rnd_65x39_caseless_green'","null"]; And yes it is a locality issue. Share this post Link to post Share on other sites
kahmoon2k 10 Posted May 12, 2013 F2k Sel, thank you very much for your help. I ended up using another solution, mainly intended to get around the problem that the setTriggerStatements command takes strings as input. I also wanted to be able to run the script independently on several different units in the same mission, which means I can't use the same global for all of them. If anyone is interested, I've posted my current solution below. It seems to work decently and is part of a very simple script that arms civilians when bluefor gets close, and makes them hostile. The only (minor) problem I've identified so far is that the unit needs to be named in the editor, the default names don't seem to work for some reason. //Creates a center for East if no center exists and creates an enemy group on first execution createCenter east; if (isNil ("enemyGroup")) then [{enemyGroup = createGroup east},{"null"}]; //Creats lists of weapons and corresponding ammo and selects one a random _name = format ["%1",_this]; _weapons = ["'hgun_Rook40_F'","'hgun_P07_F'"]; _mags = ["'16Rnd_9x21_Mag'","'16Rnd_9x21_Mag'"]; _ran = (floor(random(count _weapons))); _selectedWeapon = format ["%1",_weapons select _ran]; _selectedMag = format ["%1",_mags select _ran]; _mag = _name+" addMagazine "+_selectedMag+";"; _weapon = _name+" addWeapon "+_selectedWeapon+";"; //Creates the code which makes the civilian hostile and sets up the activation part of the trigger, can be modified to add more mags _hostile = "["+_name+"] joinSilent grpNull;["+_name+"] joinSilent enemyGroup;"; _activation =_mag+_mag+_weapon+_hostile; //Trigger is created and attached to the unit _area = 10 + random 45; _trg=createTrigger["EmptyDetector",getPos _this]; _trg setTriggerArea[_area,_area,0,false]; _trg setTriggerActivation["West","present",false]; _trg setTriggerStatements ["this",_activation,"null"]; _trg attachTo [_this]; Share this post Link to post Share on other sites