Home   Help Search Login Register  

Author Topic: Counting script with eventhandler fired  (Read 797 times)

0 Members and 1 Guest are viewing this topic.

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Counting script with eventhandler fired
« on: 23 Jan 2005, 17:21:08 »
ok - im trying to make a script that makes bullets in an ammo belt dissapear as the weapon is fired... now my scripting is novice at best, so please excuse my attempt...

basically there are 33 rounds of this belt on show, and 17 'remaining' in the ammo box. So i've tried to set the script up to count to 17, and then on the 18th to start hiding the rounds, bullet by bullet.

what happens at the moment though is that the reload part of the script (very end) is firing way too early, and none of the rounds dissapear at all - so im assuming something is going wrong - very wrong.

I can guess there's a simpler way of writing what i have (most likely by adding 1 each time to the selection and to the whatnumber to look for) but i dont know how - oh, and my variable i've used _UKFHMGCount - will that actually work with more than one of these weapons placed? like i said, scripting isn't my forte...

UKF_HMGCount == 0 is added to the eventhandler init

Code: [Select]
_vehicle = _this select 0

_UKFHMGCount == _UKFHMGCount + 1

?(_UKFHMGCount < 17) : exit

?(_UKFHMGCount == 18) : _vehicle setobjecttexture [11,""] : exit

?(_UKFHMGCount == 19) : _vehicle setobjecttexture [12,""] : exit

?(_UKFHMGCount == 20) : _vehicle setobjecttexture [13,""] : exit

?(_UKFHMGCount == 21) : _vehicle setobjecttexture [14,""] : exit

?(_UKFHMGCount == 22) : _vehicle setobjecttexture [15,""] : exit

?(_UKFHMGCount == 23) : _vehicle setobjecttexture [16,""] : exit

?(_UKFHMGCount == 24) : _vehicle setobjecttexture [17,""] : exit

?(_UKFHMGCount == 25) : _vehicle setobjecttexture [18,""] : exit

?(_UKFHMGCount == 26) : _vehicle setobjecttexture [19,""] : exit

?(_UKFHMGCount == 27) : _vehicle setobjecttexture [20,""] : exit

?(_UKFHMGCount == 28) : _vehicle setobjecttexture [21,""] : exit

?(_UKFHMGCount == 29) : _vehicle setobjecttexture [22,""] : exit

?(_UKFHMGCount == 30) : _vehicle setobjecttexture [23,""] : exit

?(_UKFHMGCount == 31) : _vehicle setobjecttexture [24,""] : exit

?(_UKFHMGCount == 32) : _vehicle setobjecttexture [25,""] : exit

?(_UKFHMGCount == 33) : _vehicle setobjecttexture [26,""] : exit

?(_UKFHMGCount == 34) : _vehicle setobjecttexture [27,""] : exit

?(_UKFHMGCount == 35) : _vehicle setobjecttexture [28,""] : exit

?(_UKFHMGCount == 36) : _vehicle setobjecttexture [29,""] : exit

?(_UKFHMGCount == 37) : _vehicle setobjecttexture [30,""] : exit

?(_UKFHMGCount == 38) : _vehicle setobjecttexture [31,""] : exit

?(_UKFHMGCount == 39) : _vehicle setobjecttexture [32,""] : exit

?(_UKFHMGCount == 40) : _vehicle setobjecttexture [33,""] : exit

?(_UKFHMGCount == 41) : _vehicle setobjecttexture [34,""] : exit

?(_UKFHMGCount == 42) : _vehicle setobjecttexture [35,""] : exit

?(_UKFHMGCount == 43) : _vehicle setobjecttexture [36,""] : exit

?(_UKFHMGCount == 44) : _vehicle setobjecttexture [37,""] : exit

?(_UKFHMGCount == 45) : _vehicle setobjecttexture [38,""] : exit

?(_UKFHMGCount == 46) : _vehicle setobjecttexture [39,""] : exit

?(_UKFHMGCount == 47) : _vehicle setobjecttexture [40,""] : exit

?(_UKFHMGCount == 48) : _vehicle setobjecttexture [41,""] : exit

?(_UKFHMGCount == 49) : _vehicle setobjecttexture [42,""] : exit

?(_UKFHMGCount == 50) : _vehicle setobjecttexture [43,""]

~3

_vehicle animate ["ani_flap", 1]
@(_vehicle animationPhase "ani_flap" ) == 1
~0.5
_vehicle animate ["ani_flap", 0]
@(_vehicle animationPhase "ani_flap" ) == 0

_vehicle animate ["ani_flap", 1]
@(_vehicle animationPhase "ani_flap" ) == 1

_vehicle setobjecttexture [11,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [12,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [13,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [14,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [15,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [16,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [17,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [18,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [19,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [20,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [21,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [22,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [23,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [24,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [25,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [26,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [27,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [28,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [29,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [30,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [31,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [32,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [33,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [34,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [35,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [36,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [37,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [38,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [39,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [40,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [41,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [42,"\UKF_HMG\50cal.paa"]
_vehicle setobjecttexture [43,"\UKF_HMG\50cal.paa"]

_vehicle animate ["ani_flap", 0]
@(_vehicle animationPhase "ani_flap" ) == 0
~0.5

_vehicle animate ["ani_cock1", 1]
@(_vehicle animationPhase "ani_cock1" ) == 1
_vehicle setobjecttexture [7,""]
_vehicle setobjecttexture [8,""]
_vehicle setobjecttexture [9,"\UKF_HMG\handle.pac"]
_vehicle setobjecttexture [10,"\UKF_HMG\strut.pac"]
_vehicle animate ["ani_cock2", 1]
@(_vehicle animationPhase "ani_cock2" ) == 1
_vehicle animate ["ani_cock2", 0]
@(_vehicle animationPhase "ani_cock2" ) == 0
_vehicle setobjecttexture [9,""]
_vehicle setobjecttexture [10,""]
_vehicle setobjecttexture [7,"\UKF_HMG\handle.pac"]
_vehicle setobjecttexture [8,"\UKF_HMG\strut.pac"]
_vehicle animate ["ani_cock1", 0]
@(_vehicle animationPhase "ani_cock1" ) == 0

exit

cheers for any help
Proud Member of the Volunteer Commando Battalion

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:Counting script with eventhandler fired
« Reply #1 on: 24 Jan 2005, 14:23:12 »
Code: [Select]
_UKFHMGCount == _UKFHMGCount + 1
_UKFHMGCount = _UKFHMGCount + 1      I think
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 Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:Counting script with eventhandler fired
« Reply #2 on: 24 Jan 2005, 14:59:59 »
(Raises hand) Oh, Mr Messiah, Sir, I have a possible solution  ;D

First of all, the script you listed fails for several reasons, the major being you trying to assign a local variable a new value which is, in short "scalar bool array..." + 1.  :-X

Now, have a look at the following. It is
  • Lean & mean and works in OFP 1.94 and up (init event being broadcast)
  • Saves CPU cycles
  • Should work with more than one HMG being fired and reloaded
Tricks used:
  • init EH-loaded slim(ish) code string for the fired EH which is a high frequency event.
  • The ammo script command to get the rounds remaining in the HMG belt.
Global variables introduced:
    UKFHMGInit:
boolean, indicates wether the init.sqs has run or not. This is in order to load the fired EH code only once.
UKFHMG_fired: string, holds the fired EH code
UKFHMGreloading: array of objects: list of HMG:s currently being reloaded. Used to keep the reload script from running more than once on a certain HMG. (avoid race conditions)[/list]


1 - config.cpp, class  EventHandlers:
Code: [Select]
class EventHandlers
{
        init = "_this exec""\UKF_HMG\init.sqs""";
        fired = "_this call UKFHMG_fired";
};
2 -  the script "\UKF_HMG\init.sqs"
Code: [Select]
?UKFHMGInit:exit
UKFHMGInit=true
?format["%1",count UKFHMGreloading]=="scalar": UKFHMGreloading=[]
UKFHMG_fired = loadFile "\UKF_HMG\scripts\fired.sqf"
3 - the script "\UKF_HMG\fired.sqf"
Code: [Select]
comment {
   _mg = object: firer
   _w  = string: weapon
   _m  = string: muzzle
   _md = string: mode
   _a  = string: ammo
   
   _al = integer: rounds remaining in the current magazine
};
private["_mg","_w","_m","_md","_a","_al"];
_mg=_this select 0;
_w=_this select 1;
_m=_this select 2;
_md=_this select 3;
_a=_this select 4;
comment{ How many rounds left in the current magazine? };
_al=(_mg ammo _m)-1;
if(_al<33)then
{
   _mg setObjectTexture[43-_al,""];
   if(_al==0&&!(_mg in UKFHMGreloading))then{[_mg]exec"\UKF_HMG\scripts\reload.sqs"};
};
4 - the script "\UKF_HMG\reload.sqs":
Code: [Select]
_hmg=_this select 0

; Flag this HMG as undergoing a reload sequence
call{UKFHMGreloading=UKFHMGreloading+[_hmg]}

gunner _hmg sideChat format ["Reloading %1...",typeof _hmg]
~3

_hmg animate ["ani_flap", 1]
@(_hmg animationPhase "ani_flap" ) == 1
~0.5
_hmg animate ["ani_flap", 0]
@(_hmg animationPhase "ani_flap" ) == 0

_hmg animate ["ani_flap", 1]
@(_hmg animationPhase "ani_flap" ) == 1

_hmg setObjectTexture [11,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [12,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [13,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [14,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [15,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [16,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [17,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [18,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [19,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [20,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [21,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [22,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [23,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [24,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [25,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [26,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [27,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [28,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [29,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [30,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [31,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [32,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [33,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [34,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [35,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [36,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [37,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [38,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [39,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [40,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [41,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [42,"\UKF_HMG\50cal.paa"]
_hmg setObjectTexture [43,"\UKF_HMG\50cal.paa"]

_hmg animate ["ani_flap", 0]
@(_hmg animationPhase "ani_flap" ) == 0
~0.5

_hmg animate ["ani_cock1", 1]
@(_hmg animationPhase "ani_cock1" ) == 1
_hmg setObjectTexture [7,""]
_hmg setObjectTexture [8,""]
_hmg setObjectTexture [9,"\UKF_HMG\handle.pac"]
_hmg setObjectTexture [10,"\UKF_HMG\strut.pac"]
_hmg animate ["ani_cock2", 1]
@(_hmg animationPhase "ani_cock2" ) == 1
_hmg animate ["ani_cock2", 0]
@(_hmg animationPhase "ani_cock2" ) == 0
_hmg setObjectTexture [9,""]
_hmg setObjectTexture [10,""]
_hmg setObjectTexture [7,"\UKF_HMG\handle.pac"]
_hmg setObjectTexture [8,"\UKF_HMG\strut.pac"]
_hmg animate ["ani_cock1", 0]
@(_hmg animationPhase "ani_cock1" ) == 0

; Un-flag the "undergoing reload" status and exit
call{UKFHMGreloading=UKFHMGreloading-[_hmg]}
gunner _hmg sideChat "...done"
exit

Yes...that ought to do it nicely...  (knocks on wood)
« Last Edit: 24 Jan 2005, 15:38:53 by Killswitch »