Jump to content
Sign in to follow this  
owmyeye

How to accumulate 'points' for killing AI (to use for a trigger)

Recommended Posts

Is there some code I can put in enemy unit's init which will accumulate 'points' for killing them? For example, having a tank and accruing 5 points for killing it and a soldier with 1 point for killing it, and then a trigger set so when a certain amount of points are reached then it activates?

What I want to create is a mission where the player must cause a certain amount of damage to the enemy position, but not necessarily have to hit any one particular target or overall percentage of the enemy. I know there is a way of using some < (less than) code on groups and such, but I don't want killing a tank to be equal to killing a simple soldier.

When then player has done enough damage, I want it to complete the task- so some kind of counter which creates a minimum number required for a trigger to activate.

Share this post


Link to post
Share on other sites
Possibly what you want?

Score for kill AI

http://tinyurl.com/o7bm4r7

Review my list for any other Ai related questions.

From that thread I found the following code:

_AI addEventHandler ["Killed",

{

(_this select 1) addScore 1;

}];

But I don't know how to use it.

1) Do I put a variation of this code into each enemy unit's init? If not, where does it go?

2) Which parts are names I should change to match my units? For example, am I mean to change "_AI" to the name of each of the enemy units, or is that a code for all AI? And what about "_this"?

3) How do I then reference this score in the trigger field? What's the code to say "If the score equals 10", so I can pop that into a triggers condition?

Share this post


Link to post
Share on other sites

1. If your wanting to use the init fields, yes just put this code in there (just replace "_AI" with "this").

2."_this" is a magic variable that is passed into the EH, in this case "_this" looks like this following: [AI,killer]

So, "_this select 1" would be the player unit that killed the AI.

3. If this is SP, the trigger condition would be: "score player >= 10"

Share this post


Link to post
Share on other sites
1. If your wanting to use the init fields, yes just put this code in there (just replace "_AI" with "this").

2."_this" is a magic variable that is passed into the EH, in this case "_this" looks like this following: [AI,killer]

So, "_this select 1" would be the player unit that killed the AI.

3. If this is SP, the trigger condition would be: "score player >= 10"

I couldn't get that to work.

Here's what I did:

1) Created an opfor unit as player with no set name.

2) created 2 indi units as non-playable with no set names

3) Added the following to the 2 enemies init's: "this addEventHandler ["Killed", {(_this select 1) addScore 1;}];"

4) Created a trigger with 0 radius, no type, no activation, and the condition: "score player >= 1" . To know if it worked, I set it to fade to black with a text.

Killing both doesn't activate the trigger. I don't if it the problem is with the trigger condition or the addscore.

Share this post


Link to post
Share on other sites

Did you ensure that the Ind was set to unfriendly to all units (or whatever it say under the intel tab in the editor).

Share this post


Link to post
Share on other sites
Did you ensure that the Ind was set to unfriendly to all units (or whatever it say under the intel tab in the editor).

Yeah I did set them to unfriendly.

To test that further, I just placed some opfor vs blufor but still doesn't work.

Share this post


Link to post
Share on other sites

See if this makes a difference:

this addEventHandler ["Killed", 
{ 
[
	[
		[(_this select 1)],
		{(_this select 0) addScore 1;}
	],
	"BIS_fnc_call",
	false,
	false,
	false
] call BIS_fnc_MP;
}];

Share this post


Link to post
Share on other sites

Doesn't work either :icon_wink:

Even though the original question hasn't be answered yet, can I be cheeky and add to it? As well as adding to a count for units killed, I also want to have certain buildings destroyed to add points. I've already got triggers linked to the buildings which activate when they are destroyed, but I need some code to put into their on act to add to the counter.

(anyone curious about how to link triggers to building status, you just make a trigger and group (not sync) it to the building. After grouping the trigger, set the field to encompass the building and set it to 'not present')

Share this post


Link to post
Share on other sites

I almost just posted a paragraph on a similar issue here.. Just thought I would post what I did, or borrowed and chopped it into what i needed.  I just wanted to get points for killing ai spawned outside the mission.  I haven't tested it with others in the game, but it is working in my mp test..  I am probably calling it wrong too. I just imagine it needs to be MP because of the mission. But I get so lost when the scope should be private or global or server, I just change it until no errors or I quit. But for some reason I always get errors using loops or sleeps if I don't do something funny like this. :/

 

not in init, but called from a script the init calls.

null = ["killedpoints.sqf","BIS_fnc_execVM",true,true] spawn BIS_fnc_MP;

killedpoints.sqf

run2=true;
while {run2} do {
	enemykilled1 = addMissionEventHandler ["EntityKilled",{_this select 2 addscore 1}];
	sleep 1;
};

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  

×