Jump to content
Sign in to follow this  
Malle2000

[question] createunit and execute a script

Recommended Posts

To keep resources low i created a unit which randomly respawns alive every 5 seconds even if it has been shot before.

The init line of the unit contains some values [this, "seek", 40] exec "RandomMove.sqs".

"seek" is the name of the marker to position it and 40 is the radius of the respawn area.

The script works fine so far. The unit however is in the game right from the start.

Now i was planning to let the unit appear after a trigger has been activated and then let it execute the script

After reading several threads i have learned that people having problems to combine creatunit with executing scripts.

The following commandline almost works:

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, (this "seek", 40); this Exec "RandomMove.sqs", 0.7, "CAPTAIN"]

When executing the script i get an error due to the bold part of the line.

Now my question. How can i get the information [this, "seek", 40] assigned to the unit when creating it so the script can read the values process and them?

I was thinking of giving the unit a name and let the script execute afterwards: Name = "SoldierWB" CreateUnit [.....

This however will take too many triggers. I want to keep it as simple as possible.

Is there any way i can get the values [this, "seek", 40] in the createunit command itself?

This way i would only have one command and one trigger for the unit.

Thx

Malle

Share this post


Link to post
Share on other sites

Try this-

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, [this "seek", 40] Exec "RandomMove.sqs", 0.7, "CAPTAIN"]

Share this post


Link to post
Share on other sites

Well that would have been too easy. Thx for the try anyway. I guess OFP does mix up the brackets. I got a solution in ofpediting.com forumr which works fine:

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, "enemyR1 = this", 0.7, "CAPTAIN"]; enemyR1 setBehaviour "careless"; enemyR1 = [this, "seek", 40]; enemyR1 Exec "RandomMove.sqs";

it still didnt answer my question of how to get in values right into the createunit command but it does the job and i still have one command line.

THX

Malle

Share this post


Link to post
Share on other sites

Ah damn, sorry confused.gif

I never really played around with createUnit much...

I think your workaround is the best way to do it. You could shorten it a little bit though-

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, "enemyR1 = this", 0.7, "CAPTAIN"]; enemyR1 setBehaviour "careless"; [enemyR1, "seek", 40] exec "RandomMove.sqs"

not that there's much point in making it shorter, except having to type a bit less smile.gif

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Trilon @ July 17 2002,19:15)</td></tr><tr><td id="QUOTE">You could shorten it a little bit though-

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, "enemyR1 = this", 0.7, "CAPTAIN"]; enemyR1 setBehaviour "careless"; [enemyR1, "seek", 40] exec "RandomMove.sqs"<span id='postcolor'>

You cannot use it this way. As init line "enemyR1 = this" may be called not during execution of createUnit, but later, there is no guarantee it will be executed before enemyR1 setBehaviour "careless"; [enemyR1, "seek", 40] exec "RandomMove.sqs". It may (when running on single computer it probably will), but it need not (easily possible in real MP environment).

Share this post


Link to post
Share on other sites

Hmm, interesting bit of info Suma. Are you saying that in a MP environment the init for each unit is executed on each client and might get executed at slightly different times?

Share this post


Link to post
Share on other sites

Ahh, nevermind, I think understand. The init for a unit has to be executed slightly after the createUnit command and the unit might not be named before it carries out the rest of the commands in the line, am I right?

Would this work then (if in a script)?

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, "enemyR1 = this", 0.7, "CAPTAIN"]

~1

enemyR1 setBehaviour "careless"

[enemyR1, "seek", 40] exec "RandomMove.sqs"

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Suma @ July 17 2002,20:04)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Trilon @ July 17 2002,19:15)</td></tr><tr><td id="QUOTE">You could shorten it a little bit though-

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, "enemyR1 = this", 0.7, "CAPTAIN"]; enemyR1 setBehaviour "careless"; [enemyR1, "seek", 40] exec "RandomMove.sqs"<span id='postcolor'>

You cannot use it this way. As init line "enemyR1 = this" may be called not during execution of createUnit, but later, there is no guarantee it will be executed before enemyR1 setBehaviour "careless"; [enemyR1, "seek", 40] exec "RandomMove.sqs". It may (when running on single computer it probably will), but it need not (easily possible in real MP environment).<span id='postcolor'>

You're really active in these boards lately Suma. That's nice to see! Carry on! smile.gif

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Trilon @ July 17 2002,21:08)</td></tr><tr><td id="QUOTE">Are you saying that in a MP environment the init for each unit is executed on each client and might get executed at slightly different times?<span id='postcolor'>

No, it is executed only on one computer - on the one where the unit is created. It may be different computer than the one where "createUnit" was called (mostly it will be the computer where group into which unit is created in local).

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Trilon @ July 17 2002,21:22)</td></tr><tr><td id="QUOTE">Would this work then (if in a script)?

"SoldierWB" createUnit [getMarkerPos "seek", alphagroup, "enemyR1 = this", 0.7, "CAPTAIN"]

~1

enemyR1 setBehaviour "careless"

[enemyR1, "seek", 40] exec "RandomMove.sqs"<span id='postcolor'>

There is no guarantee this would work, as there is no guarantee init will be called within any set ammount of time - and it may be even executed on different computer.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×