Home   Help Search Login Register  

Author Topic: Errors with script  (Read 1911 times)

0 Members and 1 Guest are viewing this topic.

Offline Ghost644

  • Members
  • *
    • Ghostland
Errors with script
« on: 07 Jul 2006, 02:03:05 »
I wrote this little script for a mission im making. Basically i want units to spawn into a chinook(s) and then the chinook(s) fly over a town and para drop the units in cargo.  I have a separate script for the para drop so that is not under question.
Code: [Select]
?Stopspawn: exit
;[plane] exec "enemyrespawn.sqs"
_plane = _this select 0

#spawn
"OfficerW" createUnit [getmarkerpos "spawn1", attackgrp1]
~.2
"SoldierWMG" createUnit [getmarkerpos "spawn2", attackgrp2]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn3", attackgrp3]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn1", attackgrp4]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn2", attackgrp5]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn3", attackgrp6]
~.2
goto "move"

#move
"_x MoveinCargo _plane" foreach units attackgrp1
~.2
"_x MoveinCargo _plane" foreach units attackgrp2
~.2
"_x MoveinCargo _plane" foreach units attackgrp3
~.2
"_x MoveinCargo _plane" foreach units attackgrp4
~.2
"_x MoveinCargo _plane" foreach units attackgrp5
~.2
"_x MoveinCargo _plane" foreach units attackgrp6
~.2

if ("Alive _x" count units attackgrp1) == 1 then goto "spawn"
~.1
if ("Alive _x" count units attackgrp2) == 1 then goto "spawn"
~.1
if ("Alive _x" count units attackgrp3) == 1 then goto "spawn"
~.1
if ("Alive _x" count units attackgrp4) == 1 then goto "spawn"
~.1
if ("Alive _x" count units attackgrp5) == 1 then goto "spawn"
~.1
if ("Alive _x" count units attackgrp6) == 1 then goto "spawn"
~.1
this script seems to work fine, except i get errors with the last section
Code: [Select]
if ("Alive _x" count units attackgrp5) == 1 then goto "spawn"I tried making an if then statement because when the units were floating to the ground, some would dissappear, and others would after touching the ground. They would then respawn back into the chinook(s). So I thought that by having an if statement saying that when the group gets to 1 then new units spawn. But if it is more than one nothing happens. I have the chinook(s) flying back and forth on a cycle so every few moments they would drop off new units if the group(s) are dead. Thanks in advance and i looked at the comref for the if statement, but i guess i dont understand fully.
Ghost

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Errors with script
« Reply #1 on: 07 Jul 2006, 02:32:26 »
Okay i think i fixed the errors in the if statement, but i still am getting disappeaing units, that respawn back into the chinook(s)
Code: [Select]
?Stopspawn: exit
;[plane] exec "enemyrespawn.sqs"

_plane = _this select 0

#loop
if ("Alive _x" count units attackgrp1 >= 1) then {goto "spawn"} else

{goto "end"}
if ("Alive _x" count units attackgrp2 >= 1) then {goto "spawn"} else

{goto "end"}
if ("Alive _x" count units attackgrp3 >= 1) then {goto "spawn"} else

{goto "end"}
if ("Alive _x" count units attackgrp4 >= 1) then {goto "spawn"} else

{goto "end"}
if ("Alive _x" count units attackgrp5 >= 1) then {goto "spawn"} else

{goto "end"}
if ("Alive _x" count units attackgrp6 >= 1) then {goto "spawn"} else

{goto "end"}

#spawn
"OfficerW" createUnit [getmarkerpos "spawn1", attackgrp1]
~.2
"SoldierWMG" createUnit [getmarkerpos "spawn2", attackgrp2]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn3", attackgrp3]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn1", attackgrp4]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn2", attackgrp5]
~.2
"SoldierWB" createUnit [getmarkerpos "spawn3", attackgrp6]
~.2
goto "move"

#move
"_x MoveinCargo _plane" foreach units attackgrp1
~.2
"_x MoveinCargo _plane" foreach units attackgrp2
~.2
"_x MoveinCargo _plane" foreach units attackgrp3
~.2
"_x MoveinCargo _plane" foreach units attackgrp4
~.2
"_x MoveinCargo _plane" foreach units attackgrp5
~.2
"_x MoveinCargo _plane" foreach units attackgrp6
~.2
goto "loop"

#end
~30
goto "loop"
Anyone have a way to keep the units from respawning back into the chinook(s) until they group is down to 1 guy?
Ghost

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Errors with script
« Reply #2 on: 07 Jul 2006, 15:06:08 »
First thing to fix is not to break code lines in a script. Second thing is that I think you want your >= sign to be <=

Code: [Select]
#loop
if ("Alive _x" count units attackgrp1 <= 1) then {goto "spawn"} else {goto "end"}
if ("Alive _x" count units attackgrp2 <= 1) then {goto "spawn"} else {goto "end"}
if ("Alive _x" count units attackgrp3 <= 1) then {goto "spawn"} else {goto "end"}
if ("Alive _x" count units attackgrp4 <= 1) then {goto "spawn"} else {goto "end"}
if ("Alive _x" count units attackgrp5 <= 1) then {goto "spawn"} else {goto "end"}
if ("Alive _x" count units attackgrp6 <= 1) then {goto "spawn"} else {goto "end"}

Finally, why are you spawning the units all into different groups?  If you answer that I can help you fix the rest of the script.
« Last Edit: 07 Jul 2006, 15:10:35 by Mr.Peanut »
urp!

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Errors with script
« Reply #3 on: 07 Jul 2006, 16:47:13 »
I have 3 chinooks and the way this respawn works is I have a unit on the map which is the leader( attackgrp1= group this)  and so on. So Only 11 men can spawn since groups only support 12 men. I wanted about 2 groups per chinook. I hope that helps you out. And thanks for posting ill have to try out what you said later, in a rush...
Ghost

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Errors with script
« Reply #4 on: 07 Jul 2006, 19:25:54 »
It is better to write one script to handle a generic plane, group and spawn marker, and then call it for each group.

spawninheli.sqs
Code: [Select]
;[heli,group,spawnmarker] exec "spawninheli.sqs"

if (not local server) then {exit}
_heli = _this select 0
_grp = _this select 1
_spawnmarker = _this select 2

#loop
if Stopspawn or (not alive _heli) then {exit}
if ({alive _x} count units _grp < 1) then {goto "spawn"}
~30
goto "loop"

#spawn
"OfficerW" createUnit [getmarkerpos _spawnmarker, _grp]
~.2
"SoldierWMG" createUnit [getmarkerpos _spawnmarker, _grp]
~.2
"SoldierWB" createUnit [getmarkerpos _spawnmarker, _grp]
~.2
"SoldierWB" createUnit [getmarkerpos _spawnmarker, _grp]
~.2
"SoldierWB" createUnit [getmarkerpos _spawnmarker, _grp]
~.2
"SoldierWB" createUnit [getmarkerpos _spawnmarker, _grp]
~.2

{_x MoveinCargo _heli} foreach units _grp
~30
goto "loop"

Call this script for each attack group i.e.
Code: [Select]
[chinook1,attackgroup1,"spawn1"] exec "spawninheli.sqs"
[chinook1,attackgroup2,"spawn1"] exec "spawninheli.sqs"
[chinook2,attackgroup3,"spawn2"] exec "spawninheli.sqs"
[chinook2,attackgroup4,"spawn2"] exec "spawninheli.sqs"
[chinook3,attackgroup5,"spawn3"] exec "spawninheli.sqs"
[chinook3,attackgroup6,"spawn3"] exec "spawninheli.sqs"

The line if (not local server) then {exit} can be removed if this mission is not for MP. If the mission is for MP you must also put a game logic named server on your map for the script to work properly.
« Last Edit: 07 Jul 2006, 19:39:33 by Mr.Peanut »
urp!

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Errors with script
« Reply #5 on: 09 Jul 2006, 20:52:06 »
ok i had to edit some of the script but it seems to work well. Thankyou for the help. But the ei still disappear and respawn back inside the heli's and sometimes they respawn as dead. The game did not like
Code: [Select]
if Stopspawn or (not alive _heli) then {exit} so i just deleted the Stopspawn part. aslo the line
Code: [Select]
if ({alive _x} count units _grp < 1) then {goto "spawn"} wasnt working so i changed it to
Code: [Select]
if ({alive _x} count units _grp < 1) then goto "spawn" and that seemed to work. and for the
Code: [Select]
"SoldierWB" createUnit [getmarkerpos _spawnmarker, _grp] lines i had to change it to
Code: [Select]
"SoldierWB" createUnit [getmarkerpos "_spawnmarker", _grp] It would have taken me a long time just to come up with something like this and i want to thankyou. But i am still runing into the little problem previously mentioned.
Ghost

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re: Errors with script
« Reply #6 on: 09 Jul 2006, 21:53:14 »
Problem will be the difference between
{alive _x} count units attackgrp
and
count units attackgrp

Soldiers can be dead but will remain members of their group for some time. So it's not guranteed that spawned soldiers will find a space in this group. Sometimes the dead group members are moved into cargo again.

You should be patient and use
Code: [Select]
if (count units _grp < 1) then {goto "spawn"}That makes sure they're no longer part of the group.

Or you'll have to write another script that joins every dead soldier immediately to grpNull.

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Errors with script
« Reply #7 on: 10 Jul 2006, 00:17:10 »
in the line
Code: [Select]
if (count units _grp < 1) then {goto "spawn"} why did you put {} around the goto "spawn"? i tried it like that but units dont seem to spawn unless i remove them? does that change the if statement? And the units still disappear... hmmm
Ghost

Offline Cheetah

  • Former Staff
  • ****
Re: Errors with script
« Reply #8 on: 10 Jul 2006, 00:19:24 »
Instead of the count units, you might want to use the following code:
Code: [Select]
WEST CountSide group
In my opinion this one works better. Just put the units you want to check in an array.
Code: [Select]
group = [soldier1,soldier2]
Hope that this helps.
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Errors with script
« Reply #9 on: 10 Jul 2006, 00:28:47 »
How would i count spawned units? They do not have a name and im dealing with about 6 groups of 12 men. 6 group leaders are on the map from start, there  required for the spawning, unless someone knows how to spawn 12 units and make one of them group leader?
Ghost

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re: Errors with script
« Reply #10 on: 10 Jul 2006, 21:14:21 »
:) I put it like this because the comref says so: http://www.ofpec.com/COMREF/index.php?action=list&letter=h#if

Maybe the commmands after then are always executed if they're not in code {}, I don't know. Modifying not following script language norms can't be good.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Errors with script
« Reply #11 on: 11 Jul 2006, 16:38:49 »
Change the script:
Code: [Select]
;[heli,group,spawnmarker] exec "spawninheli.sqs"

if (not local server) then {exit}
_heli = _this select 0
_grp = _this select 1
_spawnmarker = _this select 2

#loop
if (Stopspawn or (not alive _heli)) then {exit}
if ({alive _x} count units _grp < 1) then {goto "spawn"}
~30
goto "loop"

#spawn
{if (not alive _x) then {[_x] join grpNull}} forEach units _grp
~1
"OfficerW" createUnit [getmarkerpos "_spawnmarker", _grp]
~.2
"SoldierWMG" createUnit [getmarkerpos "_spawnmarker", _grp]
~.2
"SoldierWB" createUnit [getmarkerpos "_spawnmarker", _grp]
~.2
"SoldierWB" createUnit [getmarkerpos "_spawnmarker", _grp]
~.2
"SoldierWB" createUnit [getmarkerpos "_spawnmarker", _grp]
~.2
"SoldierWB" createUnit [getmarkerpos "_spawnmarker", _grp]
~.2

~1
if (Stopspawn or (not alive _heli)) then {exit}
{_x MoveinCargo _heli} foreach units _grp
~30
goto "loop"

Could someone please illuminate me on why it is necessary to put quotes around _spawnmarker in the script? I do not understand why this is needed since the _spawnmarker argument is already a string.

« Last Edit: 11 Jul 2006, 16:43:26 by Mr.Peanut »
urp!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Errors with script
« Reply #12 on: 11 Jul 2006, 18:18:51 »
i suspect it depends on how the script is called, specifically how the marker name is passed to the script. for example

Code: [Select]
[chopper_1, my_group, name_of_marker] exec "spawninheli.sqs"
is not the same as

Code: [Select]
[chopper_1, my_group, "name_of_marker"] exec "spawninheli.sqs"
until it comes to the bit in the script where you try to use the variable held in _this select 2, flashpoint doesn't know if it's a unit, a number, a string or whatever. only until you use it in the context of a marker does it know that it's meant to be a string.

to test it, remove the quotes from your script and put them around the marker name in the script call. if it works, there's your answer.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Errors with script
« Reply #13 on: 11 Jul 2006, 18:56:02 »
Maybe it requires the extra quotes beacuse the getMarkerPos "_spawnmarker" is inside the square brackets of the createUnit command?
urp!

Offline Ghost644

  • Members
  • *
    • Ghostland
Re: Errors with script
« Reply #14 on: 11 Jul 2006, 21:13:08 »
Thank you all for replying. This should work now, but i wont be able to test it until tonight. Thanks again!
Ghost