Jump to content
maggot31

Help me with setWeaponReloadingTime for tanks please

Recommended Posts

I tried a lot of different things but it seems not to be working.  I want a 140k to reload twice faster so I paste "vehicle setWeaponReloadingTime [gunner (vehicle player), currentMuzzle (gunner (vehicle player)), 0.5]; " and it doesn't work. It always says "Missing ;" 
It's my 3rd time pasting scripts to the vehicles so I have no idea how to fix this.

Share this post


Link to post
Share on other sites

vehicle is a command, not a user variable name.

vehicle player setWeaponReloadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5];

or

_vehicle == anExistingVehicleVariableNameInYourMission;  // or a spawned one

_vehicle setWeaponReloadingTime [gunner (vehicle player), currentMuzzle (gunner (vehicle player)), 0.5];

 

Welcome to the forum btw.

Share this post


Link to post
Share on other sites
15 minutes ago, pierremgi said:

vehicle is a command, not a user variable name.

vehicle player setWeaponReloadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5];

or

_vehicle == anExistingVehicleNameInYourMission;  // or a spawned one

_vehicle setWeaponReloadingTime [gunner (vehicle player), currentMuzzle (gunner (vehicle player)), 0.5];

"vehicle player setWeaponReloadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5];" for this I have the same error "Missing ;"

Also the 2nd variant is not working for me too https://prntscr.com/tstr9v
 

Share this post


Link to post
Share on other sites

That's a problem of copy paste the code (probably from BIKI, then Forum).

So if you paste it in Notepad++, UTF-8 and all characters visible, you'll read:

v?ehicle player setWeaponRe?l?oadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5?]

? as 4 extra, unwanted, boring,well-known,invisible characters.

Delete them or write your line by hand.

Share this post


Link to post
Share on other sites
25 minutes ago, pierremgi said:

That's a problem of copy paste the code (probably from BIKI, then Forum).

So if you paste it in Notepad++, UTF-8 and all characters visible, you'll read:

v?ehicle player setWeaponRe?l?oadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5?]

? as 4 extra, unwanted, boring,well-known,invisible characters.

Delete them or write your line by hand.

Now it says "Type Bool,expected Nothing" in both variants

As I just looked up I tried
call {
vehicle player setWeaponReloadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5];
};
and 
0 = vehicle player setWeaponReloadingTime [gunner vehicle player, currentMuzzle (gunner vehicle player), 0.5];
and it is not working
UPD: Downloaded CBA_A3 from the workshop so now I won't have any dumb mistakes and it appears that scripts are not working for some reason.

Share this post


Link to post
Share on other sites

You need to start with basics. In init field of a unit/object, you can't use a _local variable.

Some editor fields (like init or trigger activation code) must return nothing. 

I don't know what you are trying exactly but your setWeaponReloadingTime will never work this way.

 

I suggest you to write in the init field of the vehicle:

this addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [_this#0,_this#2,0.5];
}];

 

 

Share this post


Link to post
Share on other sites
11 minutes ago, pierremgi said:

You need to start with basics. In init field of a unit/object, you can't use a _local variable.

Some editor fields (like init or trigger activation code) must return nothing. 

I don't know what you are trying exactly but your setWeaponReloadingTime will never work this way.

 

I suggest you to write in the init field of the vehicle:

this addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [_this#0,_this#2,0.5];
}];

 

 

So basically I paste this to the init field of the tank with no mistakes and invisible symbols https://prntscr.com/tsug3j . Press Ok and everything goes fine without mistakes. But it's just not working for some reason. Still have 5-6 sec reloading time of a cannon. Am I just  not getting a thing or it's really not working the way it should? 
this addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [_this#0,_this#2,0.5];
}];

Share this post


Link to post
Share on other sites

Bah, that worked for hunter...

Try:

this addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [gunner (_this#0),currentMuzzle gunner (_this#0),0.5];
}];

🤪

  • Like 1

Share this post


Link to post
Share on other sites
5 minutes ago, pierremgi said:

Bah, that worked for hunter...

Try:

this addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [gunner (_this#0),currentMuzzle gunner (_this#0),0.5];
}];

🤪

Yep . This finally works! Thank you!

  • Like 1

Share this post


Link to post
Share on other sites
On 8/2/2020 at 11:17 PM, pierremgi said:

 

How do i make this script work on server? this is in a sqf file

 

its like the new leopard 2 a rc 3.0 😄 

 

_veh = _this #0; _veh addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [gunner (_this#0),currentMuzzle gunner (_this#0),0.5];
}];

 

 

---------------------------

 

if (!isServer) exitWith {};


//main gun

_veh = _this #0; _veh removeWeaponTurret ["cannon_120mm_long",[0]];       
_veh = _this #0; _veh removeMagazinesTurret ["20Rnd_120mm_APFSDS_shells_Tracer_Yellow",[0]]; 
_veh = _this #0; _veh removeMagazinesTurret ["12Rnd_120mm_HE_shells_Tracer_Yellow",[0]]; 
_veh = _this #0; _veh removeMagazinesTurret ["12Rnd_120mm_HEAT_MP_T_Yellow",[0]];
_veh = _this #0; _veh removeWeaponTurret ["LMG_coax",[0]];
_veh = _this #0; _veh removeMagazinesTurret ["200Rnd_762x51_Belt_Yellow",[0]];

_veh = _this #0; _veh addWeaponTurret ["cannon_125mm_advanced",[0]];
{ _veh addMagazineTurret ["16Rnd_125mm_APFSDS_T_Red",[0]] } count [1];
{ _veh addMagazineTurret ["12Rnd_125mm_HE_T_Red",[0]] } count [1,2];
{ _veh addMagazineTurret ["4Rnd_125mm_cannon_missiles",[0]] } count [1];

_veh = _this #0; _veh addWeaponTurret ["HMG_127_APC",[0]];
{ _veh addMagazineTurret ["200Rnd_127x99_mag_Tracer_Red",[0]] } count [1,2,3];  


_veh = _this #0; _veh addWeaponTurret ["SmokeLauncher",[0]];
{ _veh addMagazineTurret ["SmokeLauncherMag",[0 ]] } count [1];

//commander    
 
_veh = _this #0; _veh removeWeaponTurret ["HMG_127_APC",[0,0]];
_veh = _this #0; _veh removeMagazinesTurret ["200Rnd_127x99_mag_Tracer_Yellow",[0,0]];
_veh = _this #0; _veh addWeaponTurret ["MMG_02_coax",[0,0]]; 
{ _veh addMagazineTurret ["200Rnd_338_Mag",[0,0]] } count [1,2,3];

_veh = _this #0; _veh removeWeaponTurret ["SmokeLauncher",[0,0]];

_veh = _this #0; _veh addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [gunner (_this#0),currentMuzzle gunner (_this#0),0.5];
}];

[West, -33] call BIS_fnc_respawnTickets;


East addScoreSide 3;

Share this post


Link to post
Share on other sites

_veh = _this #0; ?

What is _this?  (where are you executing this sqf ?)

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

_veh = _this #0; ?

What is _this?  (where are you executing this sqf ?)

This is a Kuma, this is run in a respawn script called JEBUS/Gaia. 

It works the same in respawn vehicle module.

 

kuma object

0 = [this,"DELAY=",300, "INIT=", "[vehicle _proxyThis] execVM 'XMkuma18r.sqf' "]  spawn jebus_fnc_main;

 

XMKuma18r.sqf

 

You taught me sometime 5-7 years ago that I should use that code for respawned vehicles, but it doesn't work on a server always, at least not this one, most script with addEventHandler's in them dont work. 

Share this post


Link to post
Share on other sites

I'm not Jebus and I can't say how this function works. The fact is a local variable refers to something defined, object or else.

_this is a "magic" one but local. As you can read on this link, this is also a "magic" one, working, for example, in init field of an edited object.

 

When you write _this#0 , that means _this is an array (of anything).

So:

this addEventHandler ["Fired",{
 _this#0 setWeaponReloadingTime [gunner (_this#0),currentMuzzle gunner (_this#0),0.5];
}];

makes sense when written in an init field of an edited vehicle (this), and _this #0 is the first parameter of the passed parameters inside the event handler (here : params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; so  _this #0 is _unit or if you prefer :the vehicle.)

Read also what is on BIKI for this EH.

  • Like 2

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

I would like to apologize for my poor communication, the script works fine, even in jebus, it not a problem, my problem in a server, how do i run this script on clients on server it dont get it.

i on work on server if the vehicle is there at start, when it respawns it downt work.

https://community.bistudio.com/wiki/Multiplayer_Scripting

Share this post


Link to post
Share on other sites

When you write on an init field of a vehicle (using this), in MP, the code fires on server... and each (joining) client.

So a multiple command code may have different behaviors depending on commands themselves. Most of yours are LA GE, (like addMagazineTurret). That means, at each JIP :

if the argument is local (LA) (_veh so the vehicle), the command will re-add magazine on turret, everywhere (GE).

Usually not a problem for a joining player because the vehicle is supposed to be owned by someone else or server. But that point at a potential issue, using init fields in MP, without filter. You could test that with addMagazineCargoGlobal GA GE command. Each JIP will re-add magazine on cargo.

 

Now, addEventHandler "fired" is GA LE. That's OK using it on an init field, but the effect is local (so the code is). It's fine for LA commands because you don't need to check if local or not.

setWeaponReloadingTime is LA LE. OK, but you keep a local effect. If I'm right, only the local machine (where the vehicle is owned), will see the reloading time effect.

At this moment, I can't say how things work with bullets. It's weird, imho.
Test it as is, and if you get some trouble, test a remote execution, like:

[_this#0,[gunner (_this#0),currentMuzzle gunner (_this#0),0.5]] remoteExec ["setWeaponReloadingTime",0,true];

but no guarantee for fine synchronization on all PCs.

 

Then, respawning vehicle...
Try to find a respawn system (Jebus?) able to re-run an init field.
 

Spoiler

 

In my own respawn vehicle module (see MGI ADVANCED MODULES), I added a custom code variable replacing the init field. Example:


this spawn {hint "blahblah", sleep 3, hint ""};

This will work once, at start, and never more on respawn.

If you are using my respawn module, you can add:


this setVariable ["MGICustomCode", "_newVeh spawn {hint 'blahblah'; sleep 3; hint''}",true];

The code must be stringified and the vehicle is always _newVeh

Note : Don't do that for addAction code(s) as far as they are already taken into account by my functions.

 

 

  • Like 3

Share this post


Link to post
Share on other sites
On 6/18/2024 at 6:53 AM, pierremgi said:

 

 

I really appreciate you telling me this in such detail, I now understand why a lot of my missions don't work on a server, if I had known this before, I would have avoided a lot of headaches.

 I think I understand it, but still there is much more I need to understand.

 

from what i've tested projectiles/bullets are GE Maybe, when they spawn in the server mission they always show up scripted pos.

 

It doesn't work, I put it in the sqf.file, something tells me it can't be done, setWeaponReloadingTime

is supposed to work GE

 

[ _this #0,[gunner (_this#0),currentMuzzle gunner (_this#0),0.5]] remoteExec ["setWeaponReloadingTime",0,true];

 

 

I just need to understand it correctly, If use your respawn script, is it possible to make this work, it repeats all codes to all clients on the server by design. 

 

 

 

Share this post


Link to post
Share on other sites

Tangential to the topic, but why do you continually define the variable _veh?

//snip
_veh = _this #0; _veh removeWeaponTurret ["cannon_120mm_long",[0]];       
_veh = _this #0; _veh removeMagazinesTurret ["20Rnd_120mm_APFSDS_shells_Tracer_Yellow",[0]]; 
_veh = _this #0; _veh removeMagazinesTurret ["12Rnd_120mm_HE_shells_Tracer_Yellow",[0]]; 
_veh = _this #0; _veh removeMagazinesTurret ["12Rnd_120mm_HEAT_MP_T_Yellow",[0]];
_veh = _this #0; _veh removeWeaponTurret ["LMG_coax",[0]];
_veh = _this #0; _veh removeMagazinesTurret ["200Rnd_762x51_Belt_Yellow",[0]];
//

_veh is defined at the beginning and will remain so in that scope, there is no need to redefine it before every use. That's what variables are for.

//snip
_veh = _this #0; 
_veh removeWeaponTurret ["cannon_120mm_long",[0]];       
_veh removeMagazinesTurret ["20Rnd_120mm_APFSDS_shells_Tracer_Yellow",[0]]; 
_veh removeMagazinesTurret ["12Rnd_120mm_HE_shells_Tracer_Yellow",[0]]; 
_veh removeMagazinesTurret ["12Rnd_120mm_HEAT_MP_T_Yellow",[0]];
_veh removeWeaponTurret ["LMG_coax",[0]];
_veh removeMagazinesTurret ["200Rnd_762x51_Belt_Yellow",[0]];
//

 

  • Like 2

Share this post


Link to post
Share on other sites
11 hours ago, JIMMI DEE BILLY BOB said:

from what i've tested projectiles/bullets are GE Maybe, when they spawn in the server mission they always show up scripted pos.

 

The best answer about that is probably this topic on KK's blog:

http://killzonekid.com/arma-scripting-tutorials-fired-projectiles/

 

 

11 hours ago, JIMMI DEE BILLY BOB said:

It doesn't work, I put it in the sqf.file, something tells me it can't be done, setWeaponReloadingTime

is supposed to work GE

 

setWeaponReloadingTime is LA LE. I don't have a clear understanding why. Probably an old command. So, need to be broadcast or not?. Probably yes. I don't want to test it deeper.

Anyway, the remote execution makes sense for scripting from server only (where _veh is, for example, spawning it during mission)!

You don't have to broadcast anything like that, if you can write in init field of an edited vehicle, because  your code runs everywhere:

so:

this addEventHandler ["Fired", { _this #0 setWeaponReloadingTime [gunner (_this #0), currentMuzzle gunner (_this #0), 0.5]}];

 

Even if the EH "fired" is LE (as most of EHs), it fires everywhere independently (for the same effect), and it's performance saving.

But, when you respawn the vehicle, usually by new creation for this vehicle, this code is lost.

 

I can't say if Jebus did something for vehicle respawn. Anyway, using my module, you need to add, in init field of the vehicle :

this setVariable ["MGICustomCode", "_newVeh addEventHandler ['Fired',{ (_this #0) setWeaponReloadingTime [gunner (_this #0), currentMuzzle gunner (_this #0), 0]}]",TRUE];

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 6/20/2024 at 12:44 PM, pierremgi said:

 

 

I appreciate you trying, you are helpful as always, I had another solution before I brought the problem before you, the solution is a bit silly. 
 

I just add two guns, 125mm gives 10% more damage than 120mm, and you just press key 1 between the 2 guns, it gives an option for 2 burst shots and it gives 18RPM.


I wonder if it could even be done in reality with the Cased Telescoped Cannon, 2 rounds Reading two fire fast.
 

cannon_120mm_long

12Rnd_120mm_APFSDS_shells_Tracer_red

12Rnd_120mm_HE_shells_Tracer_Red

 

cannon_125mm

16Rnd_125mm_APFSDS_T_red

12Rnd_125mm_HE_T_red

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×