Jump to content
Sign in to follow this  
yibbachester

Need help creating a "Battery charge" script for Uavs

Recommended Posts

So I have an idea in mind that I have no clue how to make, so I'd thought I'd ask you guys.

I have searched online for a script like this, but all of them recharge the batteries on the small uavs without using an item, which I do not like. Also I do not desire to use a "Charge pad" script, because this is out in the field.

My idea includes the following:

-Designator batteries are used to recharge the uavs

-Will be avaiable as an addaction while looking at the drone (assembled)

-Some stock action to represent installing the batteries.

-One Designator battery removed per charge.

 

I am not that great of a scripter so I am hoping to see one of you guys come up with something. I would love to see how this script would look  and hope to learn something from this

Share this post


Link to post
Share on other sites

I am currently trying to research to see how I can do this myself for the effort of learning, but Most of what I do not know how to do is how to have the "server" (not always going to be a dedi) monitor when a uav is assembled, and then add the action to it. I have a hunch that the eventhandler WeaponAssembled will need to be used, but I have no idea at this moment how to use it in syntax

 

 

It needs to be run globally. Will try and figure out but if you have any suggestions that would be greatly appreciated.

Edited by yibbachester
Clarification

Share this post


Link to post
Share on other sites

If you want to have the option to recharge one Drone in the entire mission place it and put this into the init:

Spoiler

this addAction ["<t color='#e5b348'>Recharge</t>",
{
	_nul = [_this select 0] spawn
	{
		player playAction "Medic";
		sleep 5;
		player removeItem "Laserbatteries";
		_this select 0 setFuel 1;
	};
}, [], 0, false, true, "", "'Laserbatteries' in magazines player"];

 

 

If you want this on every eg. AR-2 Darter in every mission even if you pick it from the VirtualArsenal I think you need something bigger if not a config addon.

Share this post


Link to post
Share on other sites
19 minutes ago, Ian Bones said:

If you want to have the option to recharge one Drone in the entire mission place it and put this into the init:

  Reveal hidden contents


this addAction ["<t color='#e5b348'>Recharge</t>",
{
	_nul = [_this select 0] spawn
	{
		player playAction "Medic";
		sleep 5;
		player removeItem "Laserbatteries";
		_this select 0 setFuel 1;
	};
}, [], 0, false, true, "", "'Laserbatteries' in magazines player"];

 

 

If you want this on every eg. AR-2 Darter in every mission even if you pick it from the VirtualArsenal I think you need something bigger if not a config addon.

It will be every darter that is put down. That is why I have no clue where to start :/

Share this post


Link to post
Share on other sites
player addEventHandler ["weaponAssembled", {
  	if (typeOf (_this select 1) in ["B_UAV_01_F", "O_UAV_01_F", "I_UAV_01_F"] && {_this select 1 getVariable ["rechargeActionNeeded", true]}) then {
  		_this select 1 setVariable ["rechargeActionNeeded", false]; 
  		_this select 1 addAction ["<t color='#e5b348'>Recharge</t>", {
 			 [_this select 0] spawn { 
 				 player playAction "Medic"; 
 				 sleep 5; 
 				 player removeItem "Laserbatteries";
  				 [_this select 0, 1] remoteExec ["setFuel", _this select 0]; 
			}; 
		}, [], 0, false, true, "", "'Laserbatteries' in magazines player"];
	}
}];

Puts a local recharge action on the drone for the one who assembles it. Easiest way to use it is to put it into initPlayerLocal.sqf, and onPlayerRespawn.sqf if you got a respawn on your mission.

 

"Some event handlers are persistent (i.e. they stay attached to a unit, even after it dies and respawns)." Need to try that one yourself.

Edited by kauppapekka

Share this post


Link to post
Share on other sites

It works! That a bunch dude! Will credit you for this code. Mind if i upload this script to Armaholic and credit you for it?

Share this post


Link to post
Share on other sites

Well if you're going to start credit people then put Ian Bones too, as I just wrapped his action code into a condition. :drinking2:

Also put a remoteExec on to it, so you might want to use the new edit I've done.

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
Sign in to follow this  

×