Home   Help Search Login Register  

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

0 Members and 1 Guest are viewing this topic.

Baphomet

  • Guest
Unit replication script: Its going out of control.
« on: 19 Oct 2002, 03:41:47 »
Well. I've made this script. I sort of don't know what I'm doing so if something doesn't make sense its my fault =P. Basically I want to make a script wherein a marker named "manmake" spawns the unit civilian7 until there are six of them then stops (It currently creates them indefinitely). I plan on doing something else with it after that point however I can't even get this to work so I'm going to take baby steps here.


Heres the atrocity in question

_marker = "manmake"



#man
?(civilian7>6):goto"noman" //I don't know how to specify that if there are more than 6 of "Civilian7" then goto"noman"
~2
_theman="civilian7" createvehicle getmarkerpos _marker
goto"man"



#noman
?!(civilian7>6):goto"man"
~6
goto"noman"

A5hley

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #1 on: 19 Oct 2002, 04:05:05 »
Ok this wont check that there is 6 units but it will only create 6.

Code: [Select]
_marker = "manmake"
_c1 = 0

goto "start"

#reset

_c1 = _c1 + 1
? _c1 > 6 : goto "end"

#start

_theman="civilian7" createvehicle getmarkerpos _marker

goto"reset"

#end

Exit


What this does is create a varible (or somthing like that) called c1 with 0, then it is redircted to the start of the script where u add the man. Then after u added the unit,  it is directed to reset, it then adds 1 to the c1 so now it has the value of 1.
The script then checks if c1 is not greater than 6 and continues with the script.
If the script checks ad finds c1 is greater than 6 it will end the script.

Hope that helps, if u dont understand the script i used say so and ill explain it further, bit l8 now lol




« Last Edit: 19 Oct 2002, 04:05:58 by A5hley »

Baphomet

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #2 on: 19 Oct 2002, 04:16:25 »
Hm. Yeah, see I need this script to run continuously. It will end up becoming a script that spawns six guys. Checks for the maximum amount of guys alloted '6' then makes 6 more when there is no longer 6. For a multiplayer map I'm making. You make money various ways. One of which moving into a town, and leading these civilians into a specific location and then converting them into cash. I dunno what I'm going to call it. It sounds like a death camp of some sort, now that I think about it. Although that certainly wasn't the idea. Just an interesting way to make money.

Imagine all the fights players would get into trying to secure these civilians for themselves. Heh.
« Last Edit: 19 Oct 2002, 04:52:31 by Baphomet »

A5hley

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #3 on: 19 Oct 2002, 04:25:36 »
Well u could use a trigger that activates this script everytime the 6 guys are dead, so then it respawns six more, but that would only work if u want all six to be dead beofre respawning another 6.

Baphomet

  • Guest
Re:Unit replication script: Its going out of control.
« Reply #4 on: 19 Oct 2002, 05:03:02 »
Just out of curiousity what does _c1 represent? Aside from an integer '0'. How would the script differentiate between whether there was 6 soldiers or six civilians?

Offline KTottE

  • Former Staff
  • ****
Re:Unit replication script: Its going out of control.
« Reply #5 on: 19 Oct 2002, 09:24:34 »
The only part which controls what kind of unit is spawned is this here line:

_theman="civilian7" createvehicle getmarkerpos _marker


If you want a different unit type, you put something other than "civilian7".
"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!'"

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #6 on: 19 Oct 2002, 10:05:09 »
i think u beter use da createunit command - cuz units dat r created wid createvehicle dont have AI

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 #7 on: 19 Oct 2002, 10:15:00 »
*slaps his forehead*

Yeah, didn't even think about that LCD. Good point.

"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 #8 on: 19 Oct 2002, 21:39:19 »
Hm. Okay well use createunit instead of createvehicle. That helps. I still don't know how to script something that tests for how many civilian7 units have been spawned and then jump to another part of the script. Test again and if the value is beneath six, jump back.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #9 on: 20 Oct 2002, 00:56:32 »
if u r usin da createunit command it can b like dat

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"

exec it like dat

["MarkerName","UnitType",GroupName,UnitsSide] exec "nameofscript.sqs"

- just 4 example - in da case u r giving here

["manmake","civilian7",GroupName,civilian] exec "nameofscript.sqs"

cuz of da limits of da createunit command u have 2 have a group dats da created units r spawned into - so @ da start dere should b 1 unit of da type u want wid da next init

groupname = group this

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 #10 on: 20 Oct 2002, 02:55:41 »
I think I sort of understood and then I was completely lost when _marker changed from _marker=manmake. To _marker= _this select 0. _marker=manmake indicated that the marker referred to in the script was one in the map called "manmake". I have no idea what it means now. I don't know what the _this select x stuff does let alone the values that follow it.

This: ["MarkerName","UnitType",GroupName,UnitsSide] exec "nameofscript.sqs" Seems like more work than is necessary. I don't know why you can't just exec the script in the init.sqs file and forego all that?

I don't even know where in that script it says anything about spawning a civilian7 unit... Fuck. Something that originally started as simple has now become impossibly convoluted.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #11 on: 20 Oct 2002, 03:49:19 »
:wow:
LOL

if u donno wat _this select 0 means - its bout time u learn  ;D  ;)

in myscript u can use da same script on every situation u wil need it - but in ur way u wil need 2 create a new script each time - wen u give parameters 2 da script in da array like [man,car,etc] exec "nameofscript" - da script can read em - da first parameter u give is _this select 0 da second is _this select 1 nd continuing  ;D

so wat i do is get parameters from ur exec line nd make da script work wid em  ;D

Code: [Select]
; geting parameters from exec line
_marker = _this select 0 <----first parameter in exec line
_unittype = _this select 1 <---- second parameter in exec line
_groupname = _this select 2 <---- third parameter in exec line
_side = _this select 3 <---- fourth parameter in exec line

#loop
_unittype createunit [getmarkerpos _marker, _groupname] <---- Creates unit in da position of da first parameter nd join it 2 da group
? _side countside units _groupname > 5 : goto "check" <---- checks if da group have more dan 6 members - if so goes out of loop
~0.5 <---- waits 0.5 seconds
goto "loop" <---- loops

#check <---- breaks from da main loop, enters secondry loop
? _side countside units _groupname < 6 : goto "loop" <---- checks if da group have less dan 6 units, if so goes 2 main loop
~0.01 <----waits 0.01 seconds
goto "check" <----- continue wid secodry loop

nd dis is a simple script  :P  ;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 #12 on: 20 Oct 2002, 04:19:06 »
Aaaand, I still don't get the purpose of _this select 0. What it does or why it needs to be there. I'd look at the comref regarding that, however flashpoint1985's page is usually so unreliabe I can't access it half the time.

I understand a little more as to why you use this  ["MarkerName","UnitType",GroupName,UnitsSide] exec "nameofscript.sqs" to exec the script

However, my way is simpler in terms of undertsanding, It may not be functional. However for the most part I understand what each and every part does (or is intended to do). I think I'm already way in past over my head. Creating multiple scripts suits me fine so long as they're at the elementary level of scripting, which is all I can understand right now.  All I wanted was a way to test if there was a particular unit was in a certain quantity. Now I'm left with more questions than answers...



Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Unit replication script: Its going out of control.
« Reply #13 on: 20 Oct 2002, 04:43:47 »
k i can make it simpeler  :P

Code: [Select]
#loop
"civilian7" createunit [getmarkerpos "manmake"
, groupname]
? civilian countside units groupname > 5 : goto "check"
~0.5
goto "loop"

#check
?  civilian countside units groupname < 6 : goto "loop"
~0.01
goto "check"

u stil have 2 create group nd name it groupname (or nything else - as long as u change da script  ;D)

dats it

LCD OUT

P.S - if ny1 who do understand my previous script can try explainin wat i did - PLZ explain  ;D
"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 #14 on: 20 Oct 2002, 05:50:20 »
Sounds easy enough. Only thing is. Aside from making groups using the groups tab in the editor. I wouldn't know how to create a group, let alone being able to name it.

This must be a lot of work you guys trying to explain all this to me. However in all fairness a lot of this I've been shown is the first time I've really seen it. So my apolgies if I'm a bit dumbfounded at all this information being crammed into my head at once.

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!'"