Home   Help Search Login Register  

Author Topic: Problem in adding no of enemies left to the killed eventhandler....  (Read 1291 times)

0 Members and 1 Guest are viewing this topic.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
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..........
« Last Edit: 20 Aug 2009, 16:36:33 by haroon1992 »
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
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
try { return true; } finally { return false; }

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
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.............
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(