Home   Help Search Login Register  

Author Topic: problems with script  (Read 470 times)

0 Members and 2 Guests are viewing this topic.

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
problems with script
« on: 04 Jan 2003, 02:23:32 »
now, i created this script so that when a west man gets shot then he screams one of the editor voices - like MEDIC etc.

now this works PERFECT .... but (u knew there was a but) it errors if 2 get killed at once or in quick succession - understandable

so, looking at the script below, is there any way of it like 'forgeting' about the others and only allow one at a time and not error - so, like, if 5 peeps get killed at once, only one shouts and the rest are forgotten and the script wont error?

cheers.

Code: [Select]
_unitarray= _this select 0
_hurt = []
_say = ["eng22","eng23","eng29","eng30","eng31","eng32","eng33","eng34"]

#start
_tmp=0

#loop1
_unit = _unitarray select _tmp
? vehicle _unit != _unit : goto "cycle"
? "man" CountType [_unit] == 0 : goto "cycle"
? _unit in _hurt : goto "check"
? getdammage _unit > 0: _hurt = _hurt + [_unit]; goto "speak"

#cycle
_tmp = _tmp + 1
?_tmp > count _unitarray: _tmp=0
~0.05
goto "loop1"

#check
? getdammage _unit == 0: _hurt = _hurt - [_unit]
goto "cycle"

#speak
_rand = random 8
_rand = _rand - _rand % 1
_unit say (_say select _rand)
goto "cycle"

Proud Member of the Volunteer Commando Battalion

Bremmer

  • Guest
Re:problems with script
« Reply #1 on: 04 Jan 2003, 02:39:35 »
Hello Messiah

The errors are probably being caused by the loop trying to execute when there are no units left in the array. You could try it like this:

Code: [Select]
_unitarray= _this select 0
_hurt = []
_say = ["eng22","eng23","eng29","eng30","eng31","eng32","eng33","eng34"]

#start
_tmp= (count _unitarray) - 1
?_tmp < 0 : exit

#loop1
_unit = _unitarray select _tmp
? vehicle _unit != _unit : goto "cycle"
? "man" CountType [_unit] == 0 : goto "cycle"
? _unit in _hurt : goto "check"
? getdammage _unit > 0: _hurt = _hurt + [_unit]; goto "speak"

#cycle
~0.05
_tmp = _tmp - 1
?_tmp < 0 : goto "start"
goto "loop1"

#check
? getdammage _unit == 0: _hurt = _hurt - [_unit]
goto "cycle"

#speak
_rand = random 8
_rand = _rand - _rand % 1
_unit say (_say select _rand)
~5
goto "cycle"

I haven't tested this, but I have used this technique for many similar scripts without a hitch. For your multiple injury problem you can just insert a delay into the speak portion of the script - should work OK.

Good Luck

 :)
« Last Edit: 04 Jan 2003, 02:42:01 by Bremmer »

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:problems with script
« Reply #2 on: 04 Jan 2003, 16:36:17 »
cheers bremmer - if i remember correctly this was a script you helped on - thanx again for the help... again  ::)
Proud Member of the Volunteer Commando Battalion