Jump to content
Play3r

<SOLVED> Make unit have unlimited ammo but do still have to make a Magasin change

Recommended Posts

i have this Script that i put in a trigger or the Unit INIT field 

shotter dotarget t1; sleep 3; 
    while {alive t1 and alive shotter } do 
            {sleep 0.3; shots = shots +1; gl action ["useweapon",vehicle shotter,shotter,0]}; 

 

and i have found this script also 

 

shotter addeventhandler ["fired", {(this select 0) setvehicleammo 1}]; };

 

it gives the SHOTTER unlimited ammo if put inside the script above like this :

 

shotter dotarget t1; sleep 3; 
    while {alive t1 and alive shotter } do 
            {sleep 0.3; shots = shots +1; gl action ["useweapon",vehicle shotter,shotter,0]; shotter addeventhandler ["fired", {(this select 0) setvehicleammo 1}]; };

 

But what i need is the SHOTTER to make a magasin change when a amount of shots is fired.

the character is the Heavy gunner vanilia with a 130 round magasin on weapon.

if i leave the unlimited line out of the script he makes his MAG change  but he runs out of ammo after 3 MAG changes and stop to fire.

how do i make him get 3 new magasins when he is empty ??

 

Cherrs

Share this post


Link to post
Share on other sites

POLPOX 

thanks for the link but when i add it to the INIT of the UNIT i get a error

 Init:Generic error in expression

can you see what i do wrong 

this is put inside the INIT of the UNIT and NOT tru a trigger.

i know this is not the same script like my first post but after reading the post you linked to i put it inside the INIT on the UNIT and not a script run by a trigger.

 

T1 is the Target

GL is the name of my GameLogic put in by editor

 

null = this spawn {_this dotarget t1; sleep 0.5;  
 while {alive t1 and alive _this} do  
   {sleep 0.3; GL action ["useweapon",vehicle _this,_this,0]; }
this addEventHandler ["Reloaded",{ 
 _unit = _this select 0 ; 
 _mag = _this select 4 select 0 ; 
 _unit addMagazine _mag ; 
}] ;
};

Share this post


Link to post
Share on other sites
2 minutes ago, Play3r said:

thanks for the link but when i add it to the INIT of the UNIT i get a error

 Init:Generic error in expression

can you see what i do wrong 

3 problems there:

  1. Missing ;(semicolon) after the while
  2. You can't use this inside the spawn, use _this instead
  3. The addEventHandler will be executed after the while

Also, highly recommend to use forceWeaponFire or BIS_fnc_fire instead of action ["useWeapon"].

And yeah, your code is hard to read, so you'll need to think about indents and line breaks wisely.

null = this spawn {
	_this dotarget t1;
	sleep 0.5;
	_this addEventHandler ["Reloaded",{ 
		_unit = _this select 0 ; 
		_mag = _this select 4 select 0 ; 
		_unit addMagazine _mag ; 
	}] ;
	while {alive t1 and alive _this} do {
		sleep 0.3;
		[_this,currentWeapon _this] call BIS_fnc_fire;
	} ;
} ;

 

  • Thanks 1

Share this post


Link to post
Share on other sites
23 minutes ago, Play3r said:

POLPOX 

thanks for the link but when i add it to the INIT of the UNIT i get a error

 Init:Generic error in expression

can you see what i do wrong 

this is put inside the INIT of the UNIT and NOT tru a trigger.

i know this is not the same script like my first post but after reading the post you linked to i put it inside the INIT on the UNIT and not a script run by a trigger.

 

T1 is the Target

GL is the name of my GameLogic put in by editor

 

null = this spawn {_this dotarget t1; sleep 0.5;  
 while {alive t1 and alive _this} do  
   {sleep 0.3; GL action ["useweapon",vehicle _this,_this,0]; }
this addEventHandler ["Reloaded",{ 
 _unit = _this select 0 ; 
 _mag = _this select 4 select 0 ; 
 _unit addMagazine _mag ; 
}] ;
};

 

 

You have an alive check for two entities, but only one is defined. Try defining the entities more specifically

 

EDIT: Realized you were using "Shotter" (not shooter?) as an entity as well

 

 

null = this spawn {this dotarget t1; sleep 0.5;  
 while {alive t1, shotter} do  
   {sleep 0.3; GL action ["useweapon",vehicle t1, vehicle shotter, 0]; }
this addEventHandler ["Reloaded",{ 
 _unit = _this select 0 ; 
 _mag = _this select 4 select 0 ; 
 _unit addMagazine _mag ; 

 

 

You can try the code above but I'm not sure it will work. Honestly you need it defined in a trigger like this

 

Map wide trigger - "If BluFor Present" *Repeatable

 

Create a script in your mission folder \Documents\Arma3\Profile\%YourMissionName%

Save the file as "Reload.sqf" (make sure all files is selected when you save

 

Place this code into the file  EDIT: (Do the script twice and replace T1 with shotter, otherwise it will do a check and if only one is alive it will stop reloading for both or either. Since you left _this dotarget t1; in I assume t1 is the target being reloaded, so if he's dead it shouldn't really matter if he's being reloaded. )

null = this spawn {_this dotarget t1; sleep 0.5;  
 while {alive t1} do  
   {sleep 0.3; GL action ["useweapon",vehicle _this,0]; }
this addEventHandler ["Reloaded",{ 
 _unit = _this select 0 ; 
 _mag = _this select 4 select 0 ; 
 _unit addMagazine _mag ; 
}] ;
};

 

Then go back to your mission, open up the trigger you made and type

nul = execVM "Reload.sqf";

 

Every time the trigger is triggered, the reload script will be called. You can put a timeout to not overload the server, to reload them every 5 seconds do a mag check, or 10, 15, 60 etc.

 

 

This post might contain some useful code for your problem as well.

 

https://forums.bohemia.net/forums/topic/147595-unlimited-ammo-for-all-units-including-units-created-during-the-mission/

  • Confused 2

Share this post


Link to post
Share on other sites
8 minutes ago, POLPOX said:

3 problems there:

  1. Missing ;(semicolon) after the while
  2. You can't use this inside the spawn, use _this instead
  3. The addEventHandler will be executed after the while

Also, highly recommend to use forceWeaponFire or BIS_fnc_fire instead of action ["useWeapon"].

And yeah, your code is hard to read, so you'll need to think about indents and line breaks wisely.


null = this spawn {
	_this dotarget t1;
	sleep 0.5;
	_this addEventHandler ["Reloaded",{ 
		_unit = _this select 0 ; 
		_mag = _this select 4 select 0 ; 
		_unit addMagazine _mag ; 
	}] ;
	while {alive t1 and alive _this} do {
		sleep 0.3;
		[_this,currentWeapon _this] call BIS_fnc_fire;
	} ;
} ;

 

POLOX i do still get the error..

 

Init:Generic error in expression

 

i have put it inside the INIT of the UNIT

 

 

 

Share this post


Link to post
Share on other sites
2 minutes ago, Play3r said:

POLOX i do still get the error..

 

Init:Generic error in expression

 

i have put it inside the INIT of the UNIT

 

 

 

 

That kind of code just won't work in a units init. It's defining variables that have to be in an SQF, and "this" can't be "_this" in a units init or it doesn't read correctly

  • Thanks 1
  • Confused 1
  • Sad 1

Share this post


Link to post
Share on other sites

will have a look later thanks for the reply.

Share this post


Link to post
Share on other sites
8 minutes ago, Play3r said:

Init:Generic error in expression

 

i have put it inside the INIT of the UNIT

Sorry, it got some characters those shouldn't be there and make it trash.

null = this spawn {
	_this dotarget t1;
	sleep 0.5;
	_this addEventHandler ["Reloaded",{ 
		_unit = _this select 0 ; 
		_mag = _this select 4 select 0 ; 
		_unit addMagazine _mag ; 
	}] ;
	while {alive t1 and alive _this} do {
		sleep 0.3;
		[_this,currentWeapon _this] call BIS_fnc_fire;
	} ;
} ;

Here's the correct one.

  • Thanks 1

Share this post


Link to post
Share on other sites
20 minutes ago, POLPOX said:

Sorry, it got some characters those shouldn't be there and make it trash.


null = this spawn {
	_this dotarget t1;
	sleep 0.5;
	_this addEventHandler ["Reloaded",{ 
		_unit = _this select 0 ; 
		_mag = _this select 4 select 0 ; 
		_unit addMagazine _mag ; 
	}] ;
	while {alive t1 and alive _this} do {
		sleep 0.3;
		[_this,currentWeapon _this] call BIS_fnc_fire;
	} ;
} ;

Here's the correct one.

This one works like a charme thanks a lot for your help..

 

Share this post


Link to post
Share on other sites

Help me Please AddEventHandler

Could you give me some help?
I want to know how this works, and if this works in ARMA 2

It's about the infinite refills script
where should i put this

What should I do?
Create which files or where to put them in the game

 

this addEventHandler ["Reloaded",
{
_unit = _this select 0;
_mag = _this select 4 select 0;
_unit addMagazine _mag ;
}];


or this
 

null = this spawn {
	_this dotarget t1;
	sleep 0.5;
	_this addEventHandler ["Reloaded",{ 
		_unit = _this select 0 ; 
		_mag = _this select 4 select 0 ; 
		_unit addMagazine _mag ; 
	}] ;
	while {alive t1 and alive _this} do {
		sleep 0.3;
		[_this,currentWeapon _this] call BIS_fnc_fire;
	} ;
} ;


 

Share this post


Link to post
Share on other sites
20 hours ago, kaique_ks said:

Help me Please AddEventHandler

Could you give me some help?
I want to know how this works, and if this works in ARMA 2

It's about the infinite refills script
where should i put this

What should I do?
Create which files or where to put them in the game

 


this addEventHandler ["Reloaded",
{
_unit = _this select 0;
_mag = _this select 4 select 0;
_unit addMagazine _mag ;
}];


or this
 


null = this spawn {
	_this dotarget t1;
	sleep 0.5;
	_this addEventHandler ["Reloaded",{ 
		_unit = _this select 0 ; 
		_mag = _this select 4 select 0 ; 
		_unit addMagazine _mag ; 
	}] ;
	while {alive t1 and alive _this} do {
		sleep 0.3;
		[_this,currentWeapon _this] call BIS_fnc_fire;
	} ;
} ;


 

in the INIT of the unit that need to shoot alot

just use this one:

 

null = this spawn { _this dotarget t1;
sleep 0.5; _this addEventHandler ["Reloaded",{ _unit = _this select 0 ;
_mag = _this select 4 select 0 ;
_unit addMagazine _mag ; }] ;
while {alive t1 and alive _this} do { sleep 0.3;
[_this,currentWeapon _this] call BIS_fnc_fire; } ;
} ;

 

Remember to give your target the varibel name  T1

Share this post


Link to post
Share on other sites
On 06/03/2022 at 08:40, Play3r said:

no INIT da unidade que precisa atirar muito

é só usar este:

 

null = this spawn { _this dotarget t1;
dormir 0,5; _this addEventHandler ["Recarregado",{ _unit = _this select 0 ;
_mag = _this select 4 select 0 ;
_unit addMagazine _mag ; }] ;
enquanto {vivo t1 e vivo _this} faça { sleep 0.3;
[_this,currentWeapon _this] chamar BIS_fnc_fire; };
};

 

Lembre-se de dar ao seu alvo o nome de varibel T1



Inside the game ?
Don't need to put anything in the game's quest folder?
It doesn't seem to work on ARMA 2 ???

Share this post


Link to post
Share on other sites
14 minutes ago, kaique_ks said:

It doesn't seem to work on ARMA 2 ???

 

Arma 2 does not have a "Reloaded" Event Handler.

 

This is the Arma 3 forum.

Share this post


Link to post
Share on other sites
14 minutes ago, Harzach said:

 

Arma 2 does not have a "Reloaded" Event Handler.

 

This is the Arma 3 forum.


I'm not blind, I know it's Arma 3 forum.
But both games work in the same way, as it has the same engine. Arma3 as 2 Arma2 use script from ArmA1 still.
If Arma2 doesn't have "Reloaded" Event Handler, that must be why it's not working.

Is there any way to make something similar work in Arma 2?
See:
https://community.bistudio.com/wiki/setWeaponReloadingTime

Share this post


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

But both games work in the same way

 

Well, no. The scripting command, function, and event handler libraries of A3 are greatly expanded over those of A2, none of which is backward-compatible, and some A2 commands are not forward-compatible with A3 (which caused quite a commotion back in late-alpha/early-beta).

 

9 minutes ago, kaique_ks said:

Is there any way to make something similar work in Arma 2?
See:
https://community.bistudio.com/wiki/setWeaponReloadingTime

 

 

That has more to do with how fast you can fire. I don't see its relevance RE: the topic.

 

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, Harzach said:

 

Bem não. As bibliotecas de comandos de script, funções e manipuladores de eventos do A3 são bastante expandidas sobre as do A2, nenhuma das quais é compatível com versões anteriores, e alguns comandos A2 não são compatíveis com versões anteriores do A3 (o que causou uma grande comoção no final do alfa /beta precoce).

 

 

 

Isso tem mais a ver com a rapidez com que você pode disparar. Não vejo sua relevância RE: o tópico.

 


So there is no way I can use something similar in ARMA2 ?

Thanks anyway, at least now I won't be racking my brains over it

One more thing:
There's a way for me to record the movements, shots and put it on the AI for it to do the same as I did, as if it were a replay.
I know have this, in Arma 2 it works for vehicles

Video:

 

Share this post


Link to post
Share on other sites
20 minutes ago, kaique_ks said:

So there is no way I can use something similar in ARMA2 ?

 

There might be, but I suspect most folks here haven't done any scripting for A2 for many years, which is why I mentioned that this is the A3 forum. You might find better help over at the A2 forum.

 

https://forums.bohemia.net/forums/forum/90-arma-2-oa-missions-editing-scripting/

  • Like 1

Share this post


Link to post
Share on other sites

For unlimited ammo, @avibird 1 posted this release at the beginning of January.

 

And it can still work in A2 if the private variables, params and remote execution get reverted back to the A2 old school methods.

For instance, where A3 uses remoteExec, A2 uses the RE function, as in "Call RE" or "Spawn RE", with its associated rCommands.

 

 

  • Like 1

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

×