OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: haroon1992 on 18 Aug 2009, 12:35:52

Title: Problem in adding no of enemies left to the killed eventhandler....
Post by: haroon1992 on 18 Aug 2009, 12:35:52
I have added this to the init line of the enemy:
Code: [Select]
this addeventhandler ["Killed",{[this,player] exec "enemygotkilled.sqs"}]
PROBLEM : I CAN'T UPDATE CURRENT NO OF ENEMIES LEFT
enemygotkilled.sqs
Code: [Select]

_prey=_this select 0;
_killer=_this select 1;
?_killer != player : exit

kills=kills+1
;a variable that has been set to 0 in the init.sqs
hint format ["Rating : %1 points\nHealth Status : %2 (0=Good,>0=Hit)\n\nYour Kills = %3 ",rating player,getdammage player,_kills]
~1
exit

I wanted to add number of enemies left,so i have place a trigger

Properties of the trigger

Code: [Select]
OPFOR PRESENT REPEATEDLY  
axisa/b: 500
name : area1
condition : startcount
On Act : noofenemies=EAST countside area1
[b]in another try[/b],
On Act : noofenemies=EAST countside list area1
and changed the script like this :

enemygotkilled.sqs

Code: [Select]
_kills=0
_prey=_this select 0;
_killer=_this select 1;
?_killer != player : exit
startcount=true
_kills=_kills+1
hint format ["Rating : %1 points\nHealth Status : %2 (0=Good,>0=Hit)\n\nYour Kills = %3\n\nNo of enemies left : %4 ",rating player,getdammage player,_kills,noofenemies]
~1
startcount=false
exit

So that the variable startcount will be true at the script runs and will be set to false as soon as the script end........to make the trigger update the current no of enemy left......
But both of the On Act codes in the trigger don't work........when used as "noofenemies=EAST countside area1", the script only count the no of enemies once and was not updating the current status............
When used the other, "noofenemies = EAST countside list area1", i got the same problem plus
some strange text in the hint at the first run of the script, the text is similar to "00000fx0es" >:(

Haroon1992..............................
Hoping to get your solutions to this problem soon........ :scratch:
Note : This script is used in my mission S.T.E.A.L.T.H [Rahmadi] which is in BETA Testing Forum....
If i could get the help from you, i will add no of enemies left to the mission..........
Thanks in Advance..........
Title: Re: Problem in adding no of enemies left to the killed eventhandler....
Post by: Worldeater on 18 Aug 2009, 22:50:40
Every time "enemygotkilled.sqs" is run _kills is reset to zero. And "no!", simply removing the first line won't work. Because _kills will be uninitialized (read: will have a value of nil) and the first time the script is run it'll try to to do something like:

  _kills = nil + 1

So _kills will be nil again (and forever).

The next problem is that _kills is a local variable. As soon as a script ends all local variables are deleted. So you can't use a local variable here.

The solution is to have a global variable (like playerKills). To avoid the nil problem mentioned above this variable has to be initialized (read: set to zero) at the start of the mission (e.g. in "init.sqs" or "init.sqf").

HTH
Title: Re: Problem in adding no of enemies left to the killed eventhandler....
Post by: haroon1992 on 19 Aug 2009, 15:38:12
Thank you very much for showing my error in the script.........................
I will fix my script in that part but i still have no idea of what to do with the problem.............