OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: moritus on 15 Aug 2008, 05:15:03

Title: problem with random target
Post by: moritus on 15 Aug 2008, 05:15:03
I'm using 3 practice target in a shooting range...when you come to the shooting stand, i call this script from a trigger

Code: [Select]
#start
_targets = [targetc7l3_1,targetc7l3_2,targetc7l3_3]
? c7convl3check == 0 :goto "end"
_number= random 3
_number = _number - (_number % 1);
? _old == _number:goto "start"
_old = _number
hint format["%1",_number]
(_targets select _number) setDamage .7
~2
goto "start"

#end

exit


the problem is i always only 2 target working i can't have 3...what i'm doing wrong?
Title: Re: problem with random target
Post by: Mr.Peanut on 15 Aug 2008, 17:38:11
So your hint only displays zeroes or ones? I would check again that you have named your target objects the same as in the list. A typo is the most likely case.
Title: Re: problem with random target
Post by: THobson on 15 Aug 2008, 19:22:46
I am puzzled.  The code should give numbers 0 to 2.  If your hint does give numbers in this range but you only get two targets working then my guess is that Mr P. is spot on.  There is likely to be a misnaming of one of the targets.

I would say though that you could improve the script by putting the initialisation of the array above the loop label (why reinitialise the array every 2 seconds?) as follows:

Code: [Select]
_targets = [targetc7l3_1,targetc7l3_2,targetc7l3_3]
#start

You can also make the code more general by replacing
Code: [Select]
_number= random 3with
Code: [Select]
_number= random count _targetsThat way if you add a new target to the array you don't need to remember to change any other code further down.

Title: Re: problem with random target
Post by: moritus on 15 Aug 2008, 23:43:05
THobson: originally the script was like you said...but i have try different way to check if something change...


I have already check my name but i will recheck just to be sure...


for the hint i see number 0 to 2 but, by exemple when i see 2 the target don'T raise....if i restart the map i can be the number 1 who won't raise...it's why i'm here
Title: Re: problem with random target
Post by: Mr.Peanut on 16 Aug 2008, 17:29:35
Change:
(_targets select _number) setDamage .7
to:
(_targets select _number) setDamage 0
Title: Re: problem with random target
Post by: moritus on 17 Aug 2008, 05:01:48
na i need my target to 0.7...


i found something...if i run the mission from the editor i have strange things...but if i export to single mission my script work fine...