Home   Help Search Login Register  

Author Topic: CAS script lag and problems  (Read 1040 times)

0 Members and 2 Guests are viewing this topic.

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
CAS script lag and problems
« on: 18 Sep 2005, 03:32:43 »
Hey all,

I'm working on a simple CAS (Combat Air Strike) script. For some reason, after I execute the script my game lags like **** and sometimes even freezes the game. Anyone got a clue what is up with this script?

Code: [Select]
;Written by Tyger
;Operation Flashpoint: Resistance v1.96 script
;Use at your own risk. This file was only intended for the mission it was in.
;This file is open source. All I ask is you give credit where it is due.

;ratelo_cas.sqs
setAccTime 1

_i = 0

? called_cas > 3: Hint "You have no remaining CAS missions to use."; exit
called_cas = called_cas + 1

_cas = "A10" createVehicle [getMarkerPos "CAS_Pos" select 0,getMarkerPos "CAS_Pos" select 1,300]
_casman = "SoldierWPilot" createUnit [[getMarkerPos "CAS_Pos" select 0,getMarkerPos "CAS_Pos" select 1,300],groupPilot,"this moveInDriver _cas "]
_casman Move [getPos player select 0,getPos player select 1,300]
@(_casman distance player) < 200
{_casman reveal _x} forEach list EastUnitsTrigger

#OpenFire
? _i > 60 : goto "ExitScript"
~1
_i = _i + 1
goto "OpenFire"

#ExitScript
_casman doMove [0,0,0]
@unitReady _casman
_cas setDammage 1
_casman setDammage 1
exit

called_cas is initalized in the init.sqs files as
Code: [Select]
called_cas = 0
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Kyle Sarnik

  • Guest
Re:CAS script lag and problems
« Reply #1 on: 18 Sep 2005, 04:18:32 »
I'm workin on some support scripts that are very similiar to yours. My CAS script works like a charm, I can post it here and maybe you can get some ideas from it. It has 2 parts:

CASHelo\radio_callmission.sqs
Code: [Select]
_unit = _this select 1
_obj = _this select 0
_ID = _this select 2

? _unit != player : exit

_holder = BD_SPRadioActions select 0
_array = BD_SPRadioActions - [_holder]
{_holder removeaction _X} foreach _array

? cadetmode : hint "Click on the map to select a CAS target.\nThe map click will expire in 30 seconds."
?! cadetmode : hint "Click on the map to select a target."

BD_SPMapClicker = _this select 0
BD_SPMapClick = []
_mapclick = 0
_n = 0
onMapSingleClick {[BD_SPMapClicker,_pos,_units,_shift,_alt] exec "Player\MapClick.sqs"}
#WaitForMapClick
~1
_n = _n + 1
_mapclick = BD_SPMapClicker call BD_SPFmap_click
? _n > 30 : goto "Expired"
? format ["%1",_mapclick] == "[]" : goto "WaitForMapClick"

?! ((secondaryweapon _holder) in BD_SPRadioWeapons) : hint "Cannot transmit message without a radio!"; exit

BD_SPHeloCASCalled = true
[] exec "Player\radio_actions.sqs"
_pos = _mapclick select 1
_units = _mapclick select 2
? format ["%1",_units] == "scalar bool array string 0xfcffffef" : _units = []
_randID = format ["%1",(random(20)-random(20))]
BD_SPRandomIDList = BD_SPRandomIDList + [_randID]
_mission = [_unit,_pos,_randID]
BD_SPCASHeloMissions = BD_SPCASHeloMissions + [[_unit,_pos,_randID]]
publicvariable "BD_SPCASHeloMissions"
_unit sidechat format ["This is %1 requesting clase air support at grid %2. I repeat, this is %1, I need close air support at %2. Over",_unit,_pos call BD_SPFgrid_pos]
? Daytime > 19 || Daytime < 5 : goto "Night"
_newsmokeY = "WeaponHolder" createvehicle (getpos _unit)
_newsmokeY setpos [getpos _unit select 0,getpos _unit select 1,0]
_newsmokeY addmagazinecargo ["BD_M18Yellow",1]
_newsmokeY setdir 90
BD_SPCurrentIDCASHelo = _randID
FiredEHIndexCAS = _unit addeventhandler ["fired",{[_this select 0,_this select 4,BD_SPCurrentIDCASHelo] exec "Player\SmokeEH_CAS.sqs"}]
? cadetmode : hint "Use yellow smoke grenades to mark specific targets for the CAS helo to attack."
?! cadetmode : hint "Use yellow smoke to mark targets."
exit

#Night
_newsmokeY = "WeaponHolder" createvehicle (getpos _unit)
_newsmokeY setpos [getpos _unit select 0,getpos _unit select 1,0]
_newsmokeY addmagazinecargo ["BD_StrobeIR",1]
_newsmokeY setdir 55
BD_SPCurrentIDCASHelo = _randID
FiredEHIndexCAS = _unit addeventhandler ["fired",{[_this select 0,_this select 4,BD_SPCurrentIDCASHelo] exec "Player\SmokeEH_CAS.sqs"}]
? cadetmode : hint "Use IR strobes to mark specific targets for the CAS helo to attack."
?! cadetmode : hint "Use strobes to mark targets."
exit

#Expired
hint "30 seconds has expired with no map click.\nThe radio message was not sent."
?! ((secondaryweapon _unit) in BD_SPRadioWeapons) : exit
[] exec "Player\radio_actions.sqs"
exit

CASHelo\init.sqs
Code: [Select]
_helo = _this

BD_SPCASHelo = true; Publicvariable "BD_SPCASHelo"

_pos = (getpos _helo)
? _pos select 2 > 20 : goto "Standby"

#Base
_base = "HeliH" createvehicle [_pos select 0,_pos select 1,0]
_base setpos [_pos select 0,_pos select 1,0]

#WaitForMission
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
~3
_missions = BD_SPCASHeloMissions
? count _missions <= 0 : goto "WaitForMission"
_mission = _missions select 0
_caller = _mission select 0
~0.5
? (count BD_SPCASHeloList) == 1 : goto "StartMission"
_distances = [BD_SPCASHeloList,{_X distance _caller}] call BD_SPFcommand_foreach
~0.5
_lowest = _distances call BD_SPFlowest_number
~0.5
_closestnumber = [_distances,_lowest] call BD_SPFarray_number
~0.5
_closest = BD_SPCASHeloList select _closestnumber
~0.5
? _closest != _helo : goto "WaitForMission"
#StartMission
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
_pos = _mission select 1
_ID = _mission select 2
_mission call BD_SPFremove_CASHelo_mission
BD_SPCASHeloList = BD_SPCASHeloList - [_helo]
_helo setbehaviour "CARELESS"
_helo setcombatmode "YELLOW"
_helo setspeedmode "FULL"
_helo flyinheight 50
_logic = "Logic" createvehicle _pos
_logic setpos _pos
~1.5
_helo sidechat format ["Roger %1, this is %2 inbound for close air support at grid %3. Over.",driver _helo,_caller,_pos call BD_SPFgrid_pos]
#MoveToMission
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
? _ID call BD_SPFabort_mission == 1 : goto "Aborted"
_helo domove _pos
~3
? _helo distance _logic > 200 : goto "MoveToMission"
dostop _helo
_helo flyinheight 35
_helo setspeedmode "LIMITED"
_helo setcombatmode "YELLOW"
_helo setbehaviour "COMBAT"
_TOTAL = 0
#RandomCircle
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
? _ID call BD_SPFabort_mission == 1 : goto "Aborted"
? _TOTAL >= 3 : goto "RTB"
_TOTAL = _TOTAL + 1
?! someammo _helo : goto "RTB"
_coef = 1
? random(2) > 1 : _coef = -1
_xpos = (_pos select 0) + ((200+random(50)) * _coef)
_coef = 1
? random(2) > 1 : _coef = -1
_ypos = (_pos select 1) + ((200+random(50)) * _coef)
_t = 0
_helo setspeedmode "LIMITED"
#Circle
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
_helo domove [_xpos,_ypos]
? _ID call BD_SPFabort_mission == 1 : goto "Aborted"
?! someammo _helo : goto "RTB"
~5
_t = _t + 1
? _t >= 3 : goto "RandomCircle"
_smoke = _ID call BD_SPFfind_smoke
? format ["%1",_smoke] == "NoSmoke" : goto "Circle"
#SpotSmoke
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
? _ID call BD_SPFabort_mission == 1 : goto "Aborted"
?! someammo _helo : goto "RTB"
_smokepos = (getpos (_smoke select 1))
_helo sidechat format ["Roger that, I see %1, inbound on specified target!",(_smoke select 2)]
_TN = 0
#RandomTarget
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
? _ID call BD_SPFabort_mission == 1 : goto "Aborted"
?! someammo _helo : goto "RTB"
_targets = ["BD_EdTargetInf","BD_EdTargetArm","BD_EdTargetArm","BD_EdTargetInf","BD_EdTargetInf","BD_EdTargetArm"]
_rand = random ((count _targets)-1)
_rand = (_rand + 0.5) - ((_rand + 0.5) mod 1)
? _rand > ((count _targets)-1) : _rand = ((count _targets)-1)
? _rand < 0 : _rand = 0
_targtype = _targets select _rand
_target = _targtype createvehicle [0,0,0]
_n = 0
_TN = _TN + 1
? _TN > ((count _targets)/3) : _ID call BD_SPFremove_smoke; goto "RandomCircle"
#SmokeMove
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
? _ID call BD_SPFabort_mission == 1 : goto "Aborted"
?! someammo _helo : goto "RTB"
~5
_target setpos [(_smokepos select 0)+(random 15 - random 15),(_smokepos select 1)+(random 15 - random 15),0]
_helo domove (getpos _target)
_helo dotarget _target
_helo dofire _target
~15
_n = _n + 1
? _n > 3 : deletevehicle _target; goto "RandomTarget"
goto "SmokeMove"
exit

#RTB
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
_helo flyinheight 55
_helo setbehaviour "CARELESS"
_helo setcombatmode "BLUE"
_helo sidechat format ["This is %1, guns are dry, returning to base. Out.",driver _helo]
#RTBLoop
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
_helo domove (getpos _base)
~3
? _helo distance _base > 150 : goto "RTBLoop"
~0.5
_helo land "LAND"
@ (getpos _helo select 2) < 7
BD_SPCASHeloList = BD_SPCASHeloList + [_helo]
~5
goto "WaitForMission"

#Aborted
?! (alive _helo) || !(canmove _helo) || (count crew _helo < 1) : goto "OutOfAction"
BD_SPHeloEvacCalled = false
~0.5
_helo sidechat format ["Roger %1, aborting air support mission, %2 returning to base.",_caller,_helo]
_aborted = true
goto "RTBLoop"

#OutOfAction
? _helo in BD_SPCASHeloList : BD_SPCASHeloList = BD_SPCASHeloList - [_helo]; publicvariable "BD_SPCASHeloList"
BD_SPHeloCASCalled = false
exit

Of course I do use alot of my own functions, but this still should help you a bit, no? If all else fails, just wait till I am finished and release this. Its kind of similiar to the RHS/Chaos radio thingy, where it optimizes the use of a squad RTO to call in support options.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:CAS script lag and problems
« Reply #2 on: 18 Sep 2005, 07:19:37 »
I suspect the problem might be here:

Code: [Select]
_casman doMove [0,0,0]
@unitReady _casman
_cas setDammage 1
_casman setDammage 1
exit

The guy is flying a plane so I doubt he will ever get to [0,0,0].

Try replacing
Code: [Select]
@unitReady _casman
_cas setDammage 1
_casman setDammage 1

with:
Code: [Select]
@((player distance _casman) > 1000)
deleteVehicle _casman
deleteVehicle _cas

Bye the way:
Quote
#OpenFire
? _i > 60 : goto "ExitScript"
~1
_i = _i + 1
goto "OpenFire"

would this not be the same as:

Code: [Select]
~60?
« Last Edit: 18 Sep 2005, 07:32:21 by THobson »

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:CAS script lag and problems
« Reply #3 on: 18 Sep 2005, 11:51:37 »

Bye the way:
#OpenFire
? _i > 60 : goto "ExitScript"
~1
_i = _i + 1
goto "OpenFire"

would this not be the same as:

Code: [Select]
~60?


Lol, yes it is. I was using this for something else before I removed that something else. Just never changed it.

Thanks for the help guys. If you don't mind Kyle, might borrow a few things from your scripts. ;)
« Last Edit: 18 Sep 2005, 11:57:24 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Kyle Sarnik

  • Guest
Re:CAS script lag and problems
« Reply #4 on: 18 Sep 2005, 20:25:51 »
Thanks for the help guys. If you don't mind Kyle, might borrow a few things from your scripts. ;)

Not at all, I'm glad it can help  ;)

rudyvarner

  • Guest
Re:CAS script lag and problems
« Reply #5 on: 20 Sep 2005, 20:35:16 »
I get the same with my script.  I narrowed it down to that the lag is when the createvehicle command loads the unit.  It's the textures being loaded.  You can test this by placing a unit of the same type somehwere on the island and then trying your script.

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:CAS script lag and problems
« Reply #6 on: 20 Sep 2005, 23:57:50 »
Actually, I did that before I even executed the script for the first time, and it had no effect.

Thankfully, I found a workaround, and now I don't need to createVehicle/camCreate the units anymore - I just use a real plane and have it
Code: [Select]
myPlane action ["LAND"] when it needs to return then doStop it.
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08