Home   Help Search Login Register  

Author Topic: Unit replication script: Its going out of control.  (Read 4026 times)

0 Members and 1 Guest are viewing this topic.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #15 on: 20 Oct 2002, 06:12:24 »
nah dont wory  ;D its natural  ::)  ;D

2 create a group - create a unit  ;D nd put in its init
Code: [Select]
groupname = group this
now groupname is da name of da units group  ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Baphomet

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #16 on: 20 Oct 2002, 06:31:35 »
I replaced the code with yours and created a unit with "groupname = group this" in its initstring. However It gave me a funny error something like

|#|, groupname] invalid number in expression

... I don't know what I did wrong.  :o

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #17 on: 20 Oct 2002, 06:49:53 »
i donno either  ;D

so i think i gonna make a example mision  ;) ;D

but if so it wil b after i wake up

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline KTottE

  • Former Staff
  • ****
Re:Unit replication script: Its going out of control.
« Reply #18 on: 20 Oct 2002, 09:55:56 »
Script-explanation delux:

Code: [Select]
_marker = _this select 0
_unittype = _this select 1
_groupname = _this select 2
_side = _this select 3

#loop
_unittype createunit [getmarkerpos _marker, _groupname]
? _side countside units _groupname > 5 : goto "check"
~0.5
goto "loop"

#check
? _side countside units _groupname < 6 : goto "loop"
~0.01
goto "check"

==============================================

We'll do it in steps, so it's easier to grasp.


1.
Code: [Select]
_marker = _this select 0
_unittype = _this select 1
_groupname = _this select 2
_side = _this select 3

This creates the following variables:

marker
unittype
groupname

and
side


The little _ infront of them makes them local, so they can only be accessed in this script.
Now, we have to store some data in those variables, don't we?
Cue _this select 0.

_this select 0 will take the first parameter passed to the script* and store it in the variable.
_this select 1 will take the second parameter and to the same thing, and so on and so forth with
_this select 2 and 3.

Pretty straight forward.

*Passing parameters to the script:
["MarkerName","UnitType",GroupName,UnitsSide]
There you are passing four parameters to the script.
"MarkerName" as the first one (_this select 0) is the name of the marker where you want to
create your units.
"UnitType" as the second (_this select 1) will tell the script what type of unit we want to create.
In this case: "Civilian7".
groupName as the third, (_this select 2) will store the value of what group we want the unit to
spawn into. You have to have a group to spawn the unit into.
side as the fourth and last one (_this select 3) will store the value of what side the unit will be on.
West, East, Resistance or Civilian. Civilian in our case.

==============================================

2.
Code: [Select]
#loop
_unittype createunit [getmarkerpos _marker, _groupname]
? _side countside units _groupname > 5 : goto "check"
~0.5
goto "loop"

#loop and goto "loop"
These are the only two components you need to make a loop.
#loop will create a label in the script, called "loop". It could be called whatever you want, but it is good to
name it after what it is. A loop.
goto "loop" tells the script to skip to the place labeled #loop and continue to run the script from there, in this
case repeating what it just did.

_unittype createUnit

This will take the variable _unittype, in which we had stored what type of unit we wanted to create (Civilian7) and tell the
script to create that unit.

[getMarkerPos _marker, _groupname]

But you need this line as well. It tells the script where to create the unit, and in which group to place it. It first gets the
position of a marker, then the name of a group, after that the unit is created. Simple enough.

? _side countSide units _groupname

Okay, this will check the group stored in _groupname for any units belonging to the side we specified in _side. Are you with me?
It asks the script "How many civilian units are there in the group called _groupname?"

> 5 : goto "check" asks "Are there more than five units? If so, then go to the place called "check"".

~0.05 tells the script to halt there for 0.05 seconds.

Now, a quick summary of this piece of code.
It starts up, creates a unit (of our choice) at a place (of our choice), then it counts how many civilian units there are.
If there are more than 5, it skips ahead in the script, if there are less than five, it halts for 0.05 seconds then moves back and does
it all over again, until there are more than 5 units.

==============================================

3.
Code: [Select]
#check
? _side countside units _groupname < 6 : goto "loop"
~0.01
goto "check"

Again, #check and goto "check sets up a loop. Of course we have to name it differently ;)

? _side countSide units _groupname < 6 : goto "loop"

You know all the commands here, so I'll just explain why it's there.
This part of the script will always be running, and keep checking if the number of units in the group is
6 or lower, if yes (true) then skip to "loop", if no (false) then continue forward.

~0.01 another pause in the script, for 0.01 seconds.

Quick summary, once again.
This will keep checking the mission if there are 6 or fewer units in the group, if yes go back to the previous part
and create more. If no, just continue checking. One of them might die, after all.

Now, do note that When making loops, you always have to have a pause. A ~ that is, followed by a number. If you want a loop checking things
almost constantly, make the number really small.

Yikes, looking back this grew to be pretty big. Oh well, as long as you learn something from it mate ;D

/KTottE
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

Baphomet

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #19 on: 20 Oct 2002, 21:33:05 »
_side = _this select 3|#|: error zero divisor

I understood most of what you said. I think or perhaps not, as this was the error I got when I tried to run the script.

["Manmake","civilian7",GroupName,civ]  exec "makeman.sqs"

This is what I put in the activation string of the trigger.
I'm still not clear on this whole group thing. Bah. This turned out to be far more trouble than its worth.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #20 on: 20 Oct 2002, 21:42:02 »
i thinjk da prob is dat dere is no side called civ  ::) da side is - civilian

so it should be

["Manmake","civilian7",GroupName,civilian]  exec "makeman.sqs"

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Baphomet

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #21 on: 20 Oct 2002, 23:00:34 »
No... It still does it regardless. I think I just need to stick to simpler things. I simply cut/pasted the code. Then added this: ["Manmake","civilian7",GroupName,civ] to a trigger in the activation string. If I was to do something else. I didn't know, or it was implied in the message and I didn't get it.
« Last Edit: 20 Oct 2002, 23:15:54 by Baphomet »

Offline KTottE

  • Former Staff
  • ****
Re:Unit replication script: Its going out of control.
« Reply #22 on: 21 Oct 2002, 09:19:25 »
Quote
Take this:

Quote from: KTottE

_marker = _this select 0
_unittype = _this select 1
_groupname = _this select 2
_side = _this select 3

#loop
_unittype createunit [getmarkerpos _marker, _groupname]
? _side countside units _groupname > 5 : goto "check"
~0.5
goto "loop"

#check
? _side countside units _groupname < 6 : goto "loop"
~0.01
goto "check"

stick it in a text file, save it as MyScript.sqs (in your mission folder, but I guess you knew that).

Now, head into the mission, place a trigger where you like it, make it activate the way you want (by west, by east?)
then add the following to the On Activation field:

["ManMake","civilian7",GroupName,civilian] exec "MyScript.sqs"

Next, be sure to create the group, "GroupName". How you do it is described earlier in the thread. The marker "ManMake" should also be placed in the mission, where you want the units to spawn.

And you have to make it civilian at the end, otherwise it won't work.
Try adding " " around civilian, like so:
"civilian"
and see if it works better.
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"