Home   Help Search Login Register  

Author Topic: Respawning ai (Yay, solved! =])  (Read 1283 times)

0 Members and 1 Guest are viewing this topic.

Offline Kneehi

  • Members
  • *
Respawning ai (Yay, solved! =])
« on: 17 Jun 2010, 21:28:24 »
Hello guys, need some help over here!
I'm quite new to scripting so i might be doing a stupid and obvious mistake, since my script is very simple.
What i'm trying to do is create a script that will create a random pre-defined man when someone on the group dies.
First, here's my script:
Quote
_target = _this select 0
_units = _this select 1
_respnumb = _this select 2
_objpos = _this select 3
_group = grp
_respawns = _respnumb * _units
_respawnrem = _respnumb * _units
_count = 0

#chec
_unitnumb = count units grp
~2
?_unitnumb < _units: goto "create"
?_unitnumb == _units: goto "chec"

goto "chec"

#create
~0.1

 "SoldierWB" createunit [getpos _objpos, grp]
leader _group move getpos leader _target

_count = _count + 1
_respawnrem = _respawnrem - 1
hint format["There are " + "%1" + " respawns left", _respawnrem]
?_count == _respawns: goto "end"

goto "chec"

#end

exit


This script will simple create a soldier from  "_objpos" when one or more guys died. This one works fine, but the problem is when i add some more guys to be spawned, like this:
Quote
_target = _this select 0
_units = _this select 1
_respnumb = _this select 2
_objpos = _this select 3
_group = grp
_respawns = _respnumb * _units
_respawnrem = _respnumb * _units
_count = 0

#chec
_unitnumb = count units grp
~2
?_unitnumb < _units: goto "create"
?_unitnumb == _units: goto "chec"

goto "chec"

#create
~0.1

_rand = (random 2) + 1

?_rand = 1 : "OfficerW" createunit [getpos _objpos, grp]
?_rand = 2 : "SoldierWB" createunit [getpos _objpos, grp]
?_rand = 3 : "SoldierWLAW" createunit [getpos _objpos, grp]
leader _group move getpos leader _target
_count = _count + 1
_respawnrem = _respawnrem - 1
hint format["There are " + "%1" + " respawns left", _respawnrem]
?_count == _respawns: goto "end"

goto "chec"

#end

exit


Doing this, the script just don't work. Any sugestions?


Thanks for your time!

PS: Sorry my bad english, i'm Br :X

Forget it fellas, i solved it myself!
A hurraah for the trial and error!
Thanks again...
« Last Edit: 17 Jun 2010, 22:31:20 by Kneehi »
War ain't fair.

Offline eegore

  • Members
  • *
Re: Respawning ai (Yay, solved! =])
« Reply #1 on: 22 Jun 2010, 09:38:02 »

  How did you fix it? 

  If someone comes across this while searching they will have an answer and thats always handy.

Thanks

Offline Kneehi

  • Members
  • *
Re: Respawning ai (Yay, solved! =])
« Reply #2 on: 27 Jul 2010, 02:34:54 »
Oh, sorry, my mistake! :blink:

I fixed it and it got like this:
Quote
;Script by Kneehi
_target = _this select 0
_units = _this select 1
_respnumb = _this select 2
_objpos = _this select 3
_group = _this select 4
_respawns = _respnumb * _units
_respawnrem = _respnumb * _units
_count = 0
_units1 = units _group
leader _group move getpos leader _target
#chec

_unitnumb = count units _group
~1
?_unitnumb <= (_units - 5): goto "randomize"

goto "chec"

#randomize
hint "got to randomize"
_rand = 0
_rand = random 21
_num = _rand - (_rand % 1)
? ((_num >= 0) && (_num <= 10)): goto "resp1"
? ((_num >= 11) && (_num <= 20)): goto "resp2"
#resp1
"SoldierWLAW" createunit [getpos _objpos, _group];
"SoldierWMG" createunit [getpos _objpos, _group];
"SoldierWB" createunit [getpos _objpos, _group]
"SoldierWB" createunit [getpos _objpos, _group]
"SoldierWB" createunit [getpos _objpos, _group]
_count = _count + 5
_respawnrem = _respawnrem - 5
goto "count"
#resp2
"SoldierWSniper" createunit [getpos _objpos, _group];
"SoldierWMedic" createunit [getpos _objpos, _group];
"SoldierWAT" createunit [getpos _objpos, _group];
"SoldierWB" createunit [getpos _objpos, _group]
"SoldierWB" createunit [getpos _objpos, _group]
_count = _count + 5
_respawnrem = _respawnrem - 5
~.1
goto "count"

#count
"deletevehicle _x" foreach _units1
hint format["There are " + "%1" + " respawns left", _respawnrem]
leader _group move getpos leader _target
?_count == _respawns: goto "end"

goto "chec"

#end

exit


As you can see, I also created a random chance that would respawn any of two pre-defined groups that would go to the target location.
If there's any of you find a way to simplify or correct it in any way, please reply to me (:

Ah, sorry my bad English.. I'm BR  :D
War ain't fair.