Home   Help Search Login Register  

Author Topic: random tank spawn  (Read 1994 times)

0 Members and 1 Guest are viewing this topic.

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
random tank spawn
« on: 09 Mar 2010, 18:56:15 »
Ello guys

Ive recently made a random vehicle creation scipt that spawns a random tank from an array. The script also creates units to crew the tank. Heres the script:

Code: [Select]
_logic = _this select 0
_endlogic = _this select 1

_pos = getpos _logic
_endpos = getpos _endlogic
_i = 0
_j = 2

#LOOP

_veh = ["T72", "T80"]
_list = _veh select _i
_ran = random _j
_z = (random (count _veh))
_create = _veh select _z
_tank = _create createVehicle getpos _logic
"SoldierECrew" createunit [getpos _logic, rb1, "e1 = this", 1, "COLONEL"]
"SoldierECrew" createunit [getpos _logic, rb1, "e2 = this", 1, "LIEUTENANT"]
"SoldierECrew" createunit [getpos _logic, rb1, "e3 = this", 1, "LIEUTENANT"]
e1 addeventhandler ["Killed", {_this exec "deadbody.sqs"}]
e2 addeventhandler ["Killed", {_this exec "deadbody.sqs"}]
e3 addeventhandler ["Killed", {_this exec "deadbody.sqs"}]
e1 moveincommander _tank
e2 moveindriver _tank
e3 moveingunner _tank
e1 setbehaviour "safe"
e1 setspeedMode "FULL"
e2 setspeedMode "FULL"


~220

goto "LOOP"

exit

But ive recently been having probs with it. For some reason a tank is sometimes not created but the crew are. It's almost as tho one of the 2 tanks in the array dont exist. Have i got one of the class names wrong?

Any ideas??  :dunno:

Thx in advance

Gruntage
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: random tank spawn
« Reply #1 on: 09 Mar 2010, 19:26:39 »
Perhaps this is the problem?

Code: [Select]
_z = (random (count _veh))
_create = _veh select _z

You don't seem to have anything in place that will insure that only a whole number is generated. Also, remember that the count _veh is 2, but there is no such thing as _veh select 2.

BTW the mod command is used to generate whole numbers.
« Last Edit: 09 Mar 2010, 19:29:21 by RKurtzDmitriyev »
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: random tank spawn
« Reply #2 on: 09 Mar 2010, 19:51:16 »
Ok. ive added the mod command in there. But u say the '_create = _veh select -z' is the prob. What do i put in place of _create? the format for createvehicle is _tank = 'name of tank' createVehicle getpos _logic. What do i put in the 'name of tank' part?
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: random tank spawn
« Reply #3 on: 10 Mar 2010, 01:01:45 »
I think you misunderstood.

I said that

Code: [Select]
_veh select 2
does not exist. That's because there are only two elements of _veh . Select 0 would give the first one, select 1 the second.

What I suspect is that

Code: [Select]
_z = (random (count _veh))
is sometimes generating a number like 1.98362. Then when you do

Code: [Select]
_create = _veh select _z
it translates to

Code: [Select]
_create = _veh select 1.98362
select is meant to work with whole numbers, so perhaps the engine is rounding 1.98362 to 2, and therefore

Code: [Select]
_create = _veh select 2
and _create will have nothing in it. Then when you do

Code: [Select]
_tank = _create createVehicle getpos _logic
you have no vehicle type created, and therefore no vehicle. This would account for the symptoms you describe, though I haven't tested all of this myself. Frankly I thought the select command would give you an error if a non-whole number was passed to it, so I'm surprised you've seen any tanks created at all.  ???

Maybe try this:

Code: [Select]
_create = random (count _veh)
_create = _create - (_create mod 1)

That should round _create down to 1 if it happens to be something like 1.98362 .
« Last Edit: 10 Mar 2010, 01:10:22 by RKurtzDmitriyev »
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: random tank spawn
« Reply #4 on: 10 Mar 2010, 09:28:51 »
Code: [Select]
so I'm surprised you've seen any tanks created at allAFAIK select rounds the value automatically if it's not an integer so that probably explains it..

So every time the value was over 0.5 and less than 1.5 select 1 was created, and 0.5 or below select 0 was created.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: random tank spawn
« Reply #5 on: 10 Mar 2010, 15:06:30 »
First of all, your passing unused parameters to your script such as endlogic(which you do not utilize).

Second, you assign global variables to each created unit which prevents further use of the script unless those existing units are first deleted.

Third you have the script running on a continual loop which would only allow it to loop 4 times(12 man per group) had the global variables not been assigned.

Fourth, you fail to send the group on its way once they are created.(Thus the failure to utilize the second parameter.

With that said, I attempted your script as is and nothing happened. So, I reworked it and the script below is a working script which spawns and sends the unit on their way as it should.
Code: [Select]
;Instructions= place a gamelogic, place a marker called "spawnmarker",. Call like this [groupname,gamelogicname] exec "thisscript.sqs"
;Don't forget to place a uit with the groupname you use before mission start.


_group = _this select 0
_logic = _this select 1

;You could add these additional parameters to pass to the script to prevent from having to use global variables in the createunit command line. Just make sure you replace the below variables(e1,e2,e3) with the following local ones. This will allow you to use one script for each patrol. Don't worry about sending them on their way because once created, they will proceed to the waypoints already assigned to the group name.
;_commander = _this select 2
;_gunner = _this select 3
;_driver = _this select 4






_rtank = ["T72","T80","BMP"]

_r = random (Count _rtank)

_tank = (_rtank select _r - _r mod 1) createVehicle getMarkerPos "SpawnMarker"

_tank lock true

"SoldierECrew" createunit [getMarkerPos "SpawnMarker", _group, "e1 = this; this addeventhandler [{Killed}, {_this exec {deadbody.sqs}}]", 1, "COLONEL"]
~.1
"SoldierECrew" createunit [getMarkerPos "SpawnMarker", _group, "e2 = this; this addeventhandler [{Killed}, {_this exec {deadbody.sqs}}]", 1, "LIEUTENANT"]
~.1
"SoldierECrew" createunit [getMarkerPos "SpawnMarker", _group, "e3 = this; this addeventhandler [{Killed}, {_this exec {deadbody.sqs}}]", 1, "LIEUTENANT"]

e1 moveincommander _tank
e2 moveindriver _tank
e3 moveingunner _tank
e1 setbehaviour "safe"
e1 setspeedMode "FULL"
e2 setspeedMode "FULL"

;This will move the group to the gamelogic passed as the second parameter. Feel free to replace this portion of the
;script with editor inserted waypoints for the appropriate groups.
leader _group domove getpos _logic


~220

goto "LOOP"

exit

The script above can only be used once unless you delete all existing units and then recreate them.
That can be done simply by adding additional code at the start of the script such as.....
Code: [Select]
{_x removealleventhandlers "Killed"} foreach units rb1; {Deletevehicle _x} foreach units rb1. Not sure but if the units are in a vehicle, you may have to eject them first.

If its going to be for patrol purpose only, go ahead and place two tank units with patrol routes and then place a trigger which checks the alive status of the group that deletes and then executes the above script to replnish the units so that they even if the player destroys the tank, another unit and crew will take its place and continue along its route. That will prevent unneeded numbers from hindering framerate.

The only other thing to work out would be having them react to the player when they(anyone in that group) detects the player and then resetting them once the player has vanished. This can be done using a trigger with the knowsabout command for the group leader to switch their behaviour and then a distance check and knowsabout trigger to reset them.

Hope this helps.
« Last Edit: 10 Mar 2010, 17:05:46 by savedbygrace »

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: random tank spawn
« Reply #6 on: 10 Mar 2010, 20:28:47 »
Thx for ur help. My only problem now is that when i loop the script (which is what i wanted the script to do) other tanks that are created dont move to the game logic position. Any ideas why? Should i cut out the 'domove getpos _logic' and put in a preset waypoint for the group leader?
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: random tank spawn
« Reply #7 on: 10 Mar 2010, 23:24:05 »
I have to ask but why do you need to continually create and send new units to that same position?

It would be much less complicated to use the script as a replacement script for groups that have been killed.That way you could combine the script with existing groups and their complete set of waypoints so that when the initial group is killed, the script is executed via a trigger.

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: random tank spawn
« Reply #8 on: 10 Mar 2010, 23:29:43 »
I need to because i want a continuous flow of armour going from one town to another without the use of a cycle waypoint. Plus i want them to be different tanks. If it can't be done then ok ill think of an alternative.
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: random tank spawn
« Reply #9 on: 10 Mar 2010, 23:35:27 »
It can be done but each creation will require a new group. You can not continue to use the same group names and variables and it makes little sense to use large amounts of groups for an effect that can be created with only two. Have you considered setpositioning the tank and its crew back to the start position once it reaches its destination?

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: random tank spawn
« Reply #10 on: 11 Mar 2010, 08:45:38 »
good idea. thx ill try that instead.
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: random tank spawn
« Reply #11 on: 11 Mar 2010, 15:21:23 »
Just keep in mind that units disappearing or reappearing near or in the line of sight of the player can ruin immersion and gameplay faster than anything.