Home   Help Search Login Register  

Author Topic: Random error message  (Read 939 times)

0 Members and 1 Guest are viewing this topic.

Dane

  • Guest
Random error message
« on: 31 Oct 2005, 00:10:38 »
I made this script to make some random armored vehicle patrols with randomly placed waypoints and random vehicle types.
This code works perfectly most of the time but sometimes i get an error message.
Please look at attached photo.

Sorry if this looks messy but i'm not so skilled in scripting.
Code: [Select]
_eArmPatrol = _this select 0
_mbt = ["DKMM_GT12UM","DKMM_CT12UM"]
_ifv = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3_Arena"]
_ifvSe =["BTRT_A_oliv"]
_earmpatrolwpts = ["gearm1","gearm2","gearm3","gearm4","gearm5","gearm6","gearm7","gearm8","gearm9","gearm10","gearm11", "gearm12","gearm13","gearm14","gearm15","gearm16","gearm17", "gearm18","gearm19","gearm20","gearm21","gearm22","gearm23","gearm24"]
_patrolwpts = _earmpatrolwpts select random (count _earmpatrolwpts)

_eArmArray = ["BTRT_A_oliv","VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3_Arena","DKMM_GT12UM","DKMM_CT12UM"]
_eRanArm = _eArmArray select random (count _eArmArray)

arm = _eRanArm createvehicle getMarkerPos _patrolwpts
arm2 = _eRanArm createvehicle getMarkerPos _patrolwpts

type = format ["%1",typeof arm]

? (type in _mbt) : goto "mbt"
? (type in _ifv) : goto "ifv"
? (type in _ifvSe) : goto "ifvSe"

#mbt
hint "MBT"
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "SERGEANT"]
ec moveincommander arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveingunner arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveindriver arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "SERGEANT"]
ec moveincommander arm2
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveingunner arm2
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveindriver arm2

_eArmCount = 0

#mbtLabels
_labels = ["mbt2","loop"]
_RanLabels = _labels select random (count _labels)
goto _RanLabels
#mbt2
?(_eArmCount == 2): goto "loop"
arm = []
arm = _eRanArm createvehicle getMarkerPos _patrolwpts
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "SERGEANT"]
ec moveincommander arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveingunner arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveindriver arm
_eArmCount = _eArmCount + 1
goto "mbtLabels"

#ifv
hint "IFV"
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "SERGEANT"]
ec moveincommander arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveingunner arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveindriver arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "SERGEANT"]
ec moveincommander arm2
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveingunner arm2
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveindriver arm2

_eArmCount = 0

#ifvLabels
_labels = ["ifv2","loop"]
_RanLabels = _labels select random (count _labels)
goto _RanLabels
#ifv2
?(_eArmCount == 2): goto "loop"
arm = []
arm = _eRanArm createvehicle getMarkerPos _patrolwpts
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "SERGEANT"]
ec moveincommander arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveingunner arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveindriver arm
_eArmCount = _eArmCount + 1
goto "ifvLabels"


#ifvSe
hint "IFVSE"
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveindriver arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveingunner arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveindriver arm2
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveingunner arm2

_eArmCount = 0

#ifvSeLabels
_labels = ["ifvSe2","loop"]
_RanLabels = _labels select random (count _labels)
goto _RanLabels
#ifvSe2
?(_eArmCount == 2): goto "loop"
arm = []
arm = _eRanArm createvehicle getMarkerPos _patrolwpts
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "CORPORAL"]
ec moveinDriver arm
ec = []
"SoldierECrew" createunit [getPos arm, _eArmPatrol, "ec = this", 1, "PRIVATE"]
ec moveinGunner arm
_eArmCount = _eArmCount + 1
goto "ifvSeLabels"

#loop
_earmpatrolwpts=["gearm1","gearm2","gearm3","gearm4","gearm5","gearm6","gearm7","gearm8","gearm9", "gearm10","gearm11","gearm12","gearm13","gearm14","gearm15","gearm16","gearm17","gearm18", "gearm19","gearm20","gearm21","gearm22","gearm23","gearm24"]
_patrolwpts = _earmpatrolwpts select random (count _earmpatrolwpts)

[_eArmPatrol, 1] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 2] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 3] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 4] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 5] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 6] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 7] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 8] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
[_eArmPatrol, 9] setWPPos getMarkerPos _patrolwpts
_earmpatrolwpts=_earmpatrolwpts - [_patrolwpts]
_patrolwpts=_earmpatrolwpts select random (count _earmpatrolwpts)
exit
« Last Edit: 31 Oct 2005, 07:59:32 by bedges »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Random error message
« Reply #1 on: 31 Oct 2005, 08:01:30 »
right, well at first glance it's due to your defining ec as an array, then making a unit, calling it ec and trying to get it into a vehicle. flashpoint is looking for a unit rather than an array.

try taking out all the ec=[]'s.

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:Random error message
« Reply #2 on: 31 Oct 2005, 12:51:19 »
My first idea is that arm is an array instead of an object as the # is next to arm.

_eArmArray = ["BTRT_A_oliv","VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3_Arena","DKMM_GT12UM","DKMM_CT12UM"]


(count _eArmArray)=7 here,so:

_eRanArm = _eArmArray select random (count _eArmArray) becomes

_eRanArm = _eArmArray select random 7


You need a whole number from 0 to 6 if U want to pick an element in _eArmArray,but random 7 gives U something like 5.246

So it doesnt pick an element,Arm=nothing because the createvehicle line doesnt work,and then U have the error "ec moveindriver arm"

Try this:
_random = random (count _eArmArray)
_number = _random - (_random mod 1)
_eRanArm = _eArmArray select _number

Do it for every select command.

http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Random error message
« Reply #3 on: 31 Oct 2005, 18:54:33 »
You need a whole number from 0 to 6 if U want to pick an element in _eArmArray,but random 7 gives U something like 5.246

That's just not true. Select rounds the number given to it into an integer based on certain rules. Because of that you don't need to use integers with select.

Try this and you will believe me:

Code: [Select]
_array = ["1","2","3","4","5"]

_i = 0
_k = 1000

#Loop

_selection = _array select random 4
hint _selection

~1
_i = _i + 1

? _i < _k : goto "Loop"

When I run that script I get all the possible choices I have put to the _array, including "5".

But it should really be random 6 and not random 7 if there is 7 items in an array to choose from so we avoid the "zero divisor" error which will come at some point with random 7.
« Last Edit: 31 Oct 2005, 19:14:19 by Baddo »

Dane

  • Guest
Re:Random error message
« Reply #4 on: 31 Oct 2005, 20:11:02 »
Thanks for your suggestions :D, i will try them later tonight.
« Last Edit: 31 Oct 2005, 20:11:58 by DaneDK »

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:Random error message
« Reply #5 on: 31 Oct 2005, 21:05:44 »
Your correct Baddo,I didnt knew that,I taught u needed whole numbers.

But the method U use doesnt spread the chances equal...

If U check out your script u will see that Random 4 needs to give a value between:

0---0.5=1 (select 0)
0.501---1.499=2 (select 1)
1.5---2.5=3 (select 2)
2.501---3.499=4 (select 3)
3.5---4=5 (select 4)

To pick the selected element in _array

The first and last element (_array select 0 and _array select 4) have half that much a chance of appearance.
« Last Edit: 31 Oct 2005, 21:13:08 by Platoon Patton »
http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Dane

  • Guest
Re:Random error message
« Reply #6 on: 01 Nov 2005, 05:51:32 »
Quote
try taking out all the ec=[]'s

I thought these were nessesary when creating multiple units with the same name, but i removed them and it turns out they wasn't ::)

Quote
Try this:
_random = random (count _eArmArray)
_number = _random - (_random mod 1)
_eRanArm = _eArmArray select _number

I tried this and it works very well :P
And it works better, before, the same vehicles would often get selected for all groups, but now it's much more random and that is great.

So thanks alot all.