Home   Help Search Login Register  

Author Topic: script executed on four shots fired  (Read 2173 times)

0 Members and 1 Guest are viewing this topic.

Offline remcen

  • Contributing Member
  • **
  • a.k.a. hottentotten_mike
    • IM:UC
script executed on four shots fired
« on: 17 Feb 2005, 16:15:27 »
i'd like to have my unit executed a script every fourth time the units shoots - so something like [this] exec "fired.sqs" once the units fires four rounds.
how do i do this? i mean, it's easy to let the unit execute a script every time it shoots, but what about every fourth shot? i mean i can't pass a value from script to script which is executed via the fired-eventhandler, can i??? once the unit fires, the script is executed new, right?
we're looking for members: IM:UC MOD

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re:script executed on four shots fired
« Reply #1 on: 17 Feb 2005, 16:27:49 »
I believe the answer to your question is a game logic...

Make a EH type "fired". Make it set a variable to true instead of executing a script. Let's call the variable fired1.

Then make a gamelogic and give it 4 waypoints.
Give the first waypoint the condition: fired1 (the variable from the eventhandler).

In the activationfield of the waypoint you set: fired1=false; fired2=true

Next waypoints condition reads: fired1 AND fired2
Activation is fired1=false; fired3=true

Thus it will execute when the gun is fired again (because only after the second shot will fired1 and fired2 be true at the same time).

By constantly switching fired1 on/off this way you can make the trigger move to fired3, fired4... etc and then you tell the last wp to execute whatever you want to happen.

OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:script executed on four shots fired
« Reply #2 on: 17 Feb 2005, 18:05:56 »
How about using the Fired EH to run a little script which increments a global variable then runs the other script if it's >= 4 and resets the global variable to zero, else exits?

Burst will only count as one shot unless you extract the mode from the EH and add 3 to the global variable.  Can't remember how shots are handled in auto.

It'll need to be a tight script to make sure it doesn't trip over itself when firing fast.

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:script executed on four shots fired
« Reply #3 on: 17 Feb 2005, 20:52:08 »
There are a couple of tracer scripts/PBOs on the official forum that use a parameter in the command line that determines the amount of rounds fired before the next tracer is fired. Maybe you could open up one of those (one is by Wolfsbane and the other by bn880) and see how they made the tracers only fire after x amount of rounds.


                                                                  Wadmann
Check out my Camouflage Collection! New items added 31 July 2005.

Offline remcen

  • Contributing Member
  • **
  • a.k.a. hottentotten_mike
    • IM:UC
Re:script executed on four shots fired
« Reply #4 on: 17 Feb 2005, 21:19:25 »
@ nominesine: i want this script to handle the sequential muzzle flash/recoil of a gun with four barrels, so i have to implement the whole script thing in the config via an eventhandler, either fired or init.

if in the config burst is set to 1, and multiplier=4 it works fine, it just fires one round that counts as four and the fired-eventhandler is activated once, hence the muzzle/recoil script
(wait.... i made a vid of it - actually for mod-internal demo purposes:link )
this is how it works now: one round per shot fired, counts as four.
but with burst=4 (which is far more realistic!) the fired evenhandler is activated four times, hence my sequential effect is played four times

@ACF: but when i use a global variable, i can use only one of that units that execute the script, right? sorry again, seems i really should have given you a bit more information on this.

@wademan: yeah, that sounds like a solution, i'll look through those scripts when i get some more time...
we're looking for members: IM:UC MOD

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:script executed on four shots fired
« Reply #5 on: 18 Feb 2005, 00:05:15 »
Seemed far too easy . . .

OK, I haven't done this, but you might be able to dynamically define a global variable for each unit by Format-ting a tag with the unit name then passing this to your script.  The 'call' command seems to be the key to doing this.

Hope it helps . . .

Offline remcen

  • Contributing Member
  • **
  • a.k.a. hottentotten_mike
    • IM:UC
Re:script executed on four shots fired
« Reply #6 on: 18 Feb 2005, 01:30:21 »
sounds interesting but,... well,.. i mainly focus on modelling and texturing and i've no clue about functions to be honest. could you give me some more info on that??
is it possible to code a burst-mode for the weapon and detect it firing with the fired- eventhandler, so the eventhandler is only activated once? the prob might be that it is an static weapon...   (just an idea)
for a better understanding here's the relevant part of the config and the fired-eventhandler script. this is how it works like in the video. one shot counting as four, with a 4-step sequential effect script.
Code: [Select]
class cfgWeapons
{
   class Default{};
   class MGun: default{};
   class MachineGun7_6: MGun{};
   class MachineGun30: MachineGun7_6{};
   class ZSUCannon: MachineGun30{};
   class imuc_zpu4_Cannon: ZSUCannon
   {
     
      initSpeed=900;
      flashSize=1.20;
      reloadTime=0.10;
     
     ///  burst="4";  <--- making probs!!!
      maxLeadSpeed=600;      
     
      soundcontinous=0;
      canLock=2;
     
     
         ammo="imuc_14mm_Bullet";
         multiplier=4;
         
         displayName="14mm Burst";
         displayNameMagazine="14mm Shells";
         shortNameMagazine="14mm";
         dispersion=0.0300;
         sound[]={\imuc_zpu4\zpu4_fire,1,1};
         soundContinuous=0;
         
         
         
         aiRateOfFire=0.300000;
         aiRateOfFireDistance=2000
         
     

     

   };      
};

class CfgVehicles
{
   class All{};
   class AllVehicles : All{};
   class tank: AllVehicles{};
   class apc: tank{};
   class m113: apc{};
   class imuc_zpu4: m113
   {
      side=0;
      hideProxyInCombat=0;
      picture="\imuc_zpu4\izpu4.paa";
      crew="imuc_green_officer";
      hasDriver=0;
      hasGunner=1;
      hasCommander=0;
      castGunnerShadow=1;
      ejectDeadGunner=0;
      unitInfoType="UnitInfoSoldier";
      hideUnitInfo=1;
      irScanRangeMin=0;
      irScanRangeMax=1200;
      irTarget=0;
      maxSpeed=1;
      fuelCapacity=0;
      transportSolider=0;
      weapons[]={"imuc_ZPU4_Cannon"};
      magazines[]={"imuc_ZPU4_Cannon"};
      gunnerAction="ManActZPU4_Gunner";
      gunnerCanSee="31";
      class TransportMagazines {};
      cost=10000;
      class Turret
      {
         soundServo[]={"Vehicles\gun_elevate",0.03,1.0};
         minElev=-20;
         maxElev=90;
         minTurn=-360;
         maxTurn=+360;
         gunAxis="OsaHlavne";
         turretAxis="OsaVeze";
         gunBeg="usti hlavne";
         gunEnd="konec hlavne";
         body="OtocVez";
         gun="OtocHlaven";
      };
      armor=50;
      armorStructural=10.0;
      type=0;
      model="\imuc_zpu4\zpu4";
      icon="antiAC.paa";
      displayName="ZPU-4";
      nameSound="weapon";
      transportSoldier=0;
      vehicleclass= "IMUC - Armor";
      transportAmmo=0;
      accuracy=0.30;
      typicalCargo[]={};
      transportMaxMagazines=0;
      transportMaxWeapons=0;
      hiddenselections[]= {"flash1", "flash2", "flash3", "flash4"};
      class animations
      {
         class barrel1
         {
         type="rotation";
                  animPeriod=0.1;
                  selection="barrel1";
                  axis="axis_barrels";
                  angle0=0;
                  angle1=-0.001;
         };
         
         class barrel2
         {
         type="rotation";
                  animPeriod=0.1;
                  selection="barrel2";
                  axis="axis_barrels";
                  angle0=0;
                  angle1=-0.001;
         };
     
         class barrel3
         {
         type="rotation";
                  animPeriod=0.1;
                  selection="barrel3";
                  axis="axis_barrels";
                  angle0=0;
                  angle1=-0.001;
         };
   
         class barrel4
         {
         type="rotation";
                  animPeriod=0.1;
                  selection="barrel4";
                  axis="axis_barrels";
                  angle0=0;
                  angle1=-0.001;
         };
         
   
      };
   class eventhandlers
      {
     fired = "[_this select 0] exec ""\imuc_zpu4\sc\zpu4_fired.sqs"";";
       
      };

   };
};


zpu4-fired.sqs:
Code: [Select]
_zpu = _this select 0

#start

;;barrel1 animation plus flash
_14mmbullet = nearestobject [_zpu,"imuc_14mm_bullet"]
[_14mmbullet, _zpu] exec "\imuc_zpu4\sc\smoke.sqs"

_zpu setobjecttexture [0,"\imuc_zpu4\flash.paa"]
_zpu animate ["barrel1",1]

~0.02

_zpu setobjecttexture [0,""]
_zpu animate ["barrel1",0]


; ----------------------

;;barrel2 animation plus flash
;_bullet = nearestobject [imuc_14mm_bullet,"_zpu"]
;[_bullet] exec "\imuc_zpu4\sc\smoke.sqs"

_zpu setobjecttexture [1,"\imuc_zpu4\flash.paa"]
_zpu animate ["barrel2",1]

~0.02

_zpu setobjecttexture [1,""]
_zpu animate ["barrel2",0]


;-----------------

;barrel3 animation plus flash
;_bullet = nearestobject [imuc_14mm_bullet,"_zpu"]
;[_bullet] exec "\imuc_zpu4\sc\smoke.sqs"

_zpu setobjecttexture [2,"\imuc_zpu4\flash.paa"]
_zpu animate ["barrel3",1]

~0.02

_zpu setobjecttexture [2,""]
_zpu animate ["barrel3",0]


;-----------------

;;barrel4 animation plus flash
;_bullet = nearestobject [imuc_14mm_bullet,"_zpu"]
;[_bullet] exec "\imuc_zpu4\sc\smoke.sqs"

_zpu setobjecttexture [3,"\imuc_zpu4\flash.paa"]
_zpu animate ["barrel4",1]

~0.02

_zpu setobjecttexture [3,""]
_zpu animate ["barrel4",0]
;-----------------
exit
[code/]


« Last Edit: 18 Feb 2005, 01:44:33 by remcen »
we're looking for members: IM:UC MOD

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:script executed on four shots fired
« Reply #7 on: 19 Feb 2005, 09:19:00 »
Why bother with a script? You could just use a global variable and a fired event handler... eg

unit addEventHandler ["FIRED",{variable = variable + 1; if (variable == 4) then {variable = 0; [ arguement ] exec "script.sqs"}}]

Offline remcen

  • Contributing Member
  • **
  • a.k.a. hottentotten_mike
    • IM:UC
Re:script executed on four shots fired
« Reply #8 on: 19 Feb 2005, 20:22:28 »
well, it doesn't work. no error messages or something, the script just isn't executed. this is how i put it in the config:

Code: [Select]
class eventhandlers
      {
      fired = "{shots = shots +1; if (shots == 4) then {shots = 0; [_this select 0] exec ""\imuc_zpu4\sc\zpu_fired.sqs"";}}";
      
      };
we're looking for members: IM:UC MOD

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:script executed on four shots fired
« Reply #9 on: 20 Feb 2005, 02:06:26 »
Ahh ok...

that line would work in a mission, not sure about an addon...

Maybe if the thread was on the right board ;)

* Sui gently shunts the thread in the right direction