Home   Help Search Login Register  

Author Topic: Script: Trouble with a "counter".  (Read 3701 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #15 on: 01 Sep 2006, 15:43:04 »
Hey Rhysduk, i just finished the last part like i said:

I'll post you two versions - one for your setup and another one a little bit
improved (lol - CD the Improvator).

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1,"mark2"]]
_temp_array = []

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

#back
"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0][b]; hint format [{%1 will be removed now},(_x select 1)][/b]; goto {remove}}" forEach _unit_array

?(_a == 1): goto "Loop"

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

#remove

"if (alive (_x select 0)) then {_temp_array = _temp_array + [_x]}" forEach _unit_array

_unit_array = _temp_array
_temp_array = []
goto "back"

:note - the phat line inside was just a hint for me you can remove it if you want

Well, that's the version based on your method of assigning the unit within the script.

Now i've made another version, where you can add as many units as you want without having
to edit the script.

If you have an init.sqs, put inside: unit_array = []
If not, make it from inside the first unit you've placed onto the map.
If the first unit being placed onto the map should run the markerupdate script, then put
the following code in it's init field instead:
unit_array = [[this,"markx"]]

:note it's important to initialize an array before adding elements to it therefore this method.
::note - markx you should replace with the marker name of the unit

Now into each unit's init field, which should run the script too put:

unit_array = unit_array + [[this,"markx"]]

The script you start best from a trigger, because triggers will for sure become active after the last
unit's init field has been executed (just take a look into mission.sqm and you'll see sensors come
after the units).

trigger: size 0/0
condition: true
onActivation: [] exec "markerupd.sqs"

:note - or whatever you call your script

And here's the modified script for that method:

Code: [Select]
_temp_array = []

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

#back
"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0][b]; hint format [{%1 will be removed now},(_x select 1)][/b]; goto {remove}}" forEach unit_array

?(_a == 1): goto "Loop"

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

#remove

"if (alive (_x select 0)) then {_temp_array = _temp_array + [_x]}" forEach unit_array

unit_array = _temp_array
_temp_array = []
goto "back"

:note - basically it's the same script with the only difference of using a global array: unit_array
and not having assigned the array inside the script.

You can also make a radio trigger now to hint format ["%1",unit_array] so that you can
see the content of the array.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #16 on: 01 Sep 2006, 16:08:00 »
Hey Chris.

Thanks!

I tried the detecting a dead unit but failed miserably.

Right here what ive done so far:
  • In the init.sqs added unit_array = []
  • In the Init field of each unit, i put unit_array = [[this,"markx"]] (Replace markx for relevant name of marker.)
  • Also added unit_array = unit_array + [[this,"markx"]] to each units Init field.
  • Added a West, Present, 0,0, Cond: true, On Activ: [] exec "unit_mark.sqs"
  • Added your final script to the mission folder and saved.
  • Saved everything, load Flashpoint. Run mission.
  • No error! But the markes just sit where they were put in the mission editor and dont attach to each unit!

Ill take another read of your post just in case ive done something wrong!

Thanks m8  :clap:
Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #17 on: 01 Sep 2006, 16:15:07 »
Right, I also tried the following.

According to the mission.sqm file, the PLAYER is the first person initiated on the map.

  • So in his Init field i put unit_array = [[this,"mark3"]] (mark3 is the marker to show pos of player.)
  • In the other two units Init fields i put unit_array = unit_array + [[this,"markx"]] and changed markx accordingly.

This didnt work either. Again no error! All 3 markers stay at the mission editor postion :(

Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #18 on: 01 Sep 2006, 17:41:01 »
hmm - i tried again now making it exactly how you did;

I've placed the player onto the map and in his init field i've put:

unit_array = [[this,"mark3"]]


Then i added two more units and in the init fields i've put:

unit_array = unit_array + [[this,"markx"]] markx accordingly.

I placed the three markers

And i placed a trigger: 0/0

Activation: West / present
Condition: true
onActivation: [] exec "unit_mark.sqs"

Started the mission and voilla it worked.
Well, the only problem i got was that after killing a unit an error popped up because of: hint format......
But that was because it seems that when using code here on the forums, the ... will not display it phat
but just the code itself. So remove the and the .

But this shouldn't be your problem since the markers were moving from start and this error shows up first time
when you kill a unit.

I suppose you have mixed something up in order of creating the array and adding the units or you have a simple
typo somewhere.
Maybe some names do not match - most i suspect it on the array name or the script name.  ;)

Anyways, i'll attach a working example to the post so that you can see yourself.

It's on desert island just for ya info.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #19 on: 01 Sep 2006, 18:06:20 »
Thanks for that CD.

I tried your example missionand it does indeed work!

But i couldnt see the line unit_array = [] anywhere?
Which is what you said to put in the init.sqs file.

So i took this out of my init file and tried again.

This time only the player and 1 unit had their markers work. the other guy (enemy - East) marker didnt work it just sat there.. :(

Thanks
Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #20 on: 01 Sep 2006, 19:06:45 »
Well, you can initialize an array by: unit_array = []

Or by directly filling it with something like i did in player's init field (the very first unit on the map):

unit_array = [[this,"mark3"]]

If you somewhere after this say: unit_array = [] you will clear it off course again.

But upon the fact that only the player and one unit had a working marker, while their east unit's
markers were just sitting in place i suspect that it probably was like this:

init.sqs: unit_array = []

east units init fields: unit_array = unit_array + [[this,"markx"]]

followed by the player: unit_array = [[this,"mark3"]]

followed by the one unit where it's been working: unit_array = unit_array + [[this,"markx"]]

 :)

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #21 on: 01 Sep 2006, 19:20:15 »
Ive figured out why its not working.. Its because the Unit is EAST and not WEST like the other two units (whose markers are working)

How do i solve this? Perhaps check the SIDE of the unit through the script, if its possible?!

Rhys

EDIt: Ive looked at the COMREF and not sure how i can use side .....
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #22 on: 01 Sep 2006, 20:14:34 »
Well Rhysduk, it's weird but true  :o

But don't worry i got the solution for ya aswell:  :)

I figured out that east unit's init fields become executed before west unit's init fields.

This means that all you need to do is;

change the west player's init field into: unit_array = unit_array + [[this,"mark3"]]

and change the very first east unit's init field into: unit_array = [[this,"markx"]]

Strange but i did never take notice of that - maybe it's because E is comming before W
in alphabetical order.  ???

:btw - i attached another working example, this time featuring the player, two west and two east units.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #23 on: 01 Sep 2006, 21:09:24 »
Call me Rhys m8  :)

Quote
I figured out that east unit's init fields become executed before west unit's init fields.

 :o How? I took a look at the mission.sqm file and WEST units appear to be executed/initiated before EAST units.. im curious how you did that. Another of you array/sub arrays...

Everything works now.. thanks!

Topic left open for few hours for replys, will be locked later.

Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #24 on: 01 Sep 2006, 21:24:09 »
lol - i figured that out by trying / wondering and trying more:  :D

First i made it like we had it before and i saw that east units weren't included to
the array.

This made me think that west and east units can't be together in an array.

But i remember from my MOTAG (MOre Than A Group) that i head already east and west
units together in an array -> so this couldn't have been the reason.

Then i thought that maybe you cannot add them together into arrays - i tried to manually
setup the array: unit_array = [[w1,"mark1"],[w2,"mark2"],[e1,"mark4"],[e2,"mark5"]]
and all units were included to the array when i displayed it ingame.

Then i thought to tell you that but suddenly a flash came into my brain: who's init field gets
really executed first?

So i tried the following:

I've put:
a = 1
in player's inti field (the first unit i placed onto the map)

and by adding an east unit with an init field like: a = 2

Then showing the value of a on screen resulted in: 1

Then i made: a = 1 with the east unit
and a = a + 2
with the player.
Result showing up on screen was: 3

This lead me to the conclusion that east units get executed before west units no matter
whom of them has been placed first.

Like i said, maybe it's because East comes before West in alphabetical order.

However - we got it finally working and i could also learn something new.  :)

Isn't OFP just wonderful?  :thumbsup:

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #25 on: 01 Sep 2006, 21:36:04 »
Ah right I see. Clever i must say.

Quote
Isn't OFP just wonderful? 

Oh yes, indeed it is.

Cheers.
Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)