Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
thryckz

AddAction near object / unit / player ?

Recommended Posts

I saw this on the wiki that this is possible and also joined missions that use this.

But as I am new to vbs2 scripting, I do not know much <= Coming from a C# developer :)

So can someone, explain in detail on how I can lets say, make player2 die when player1 is looking at player2 ( not at a distance, but like close enough so "gear" will pop up. )

I already know the scripting for the death, just need the "looking at player" part.

Edited by ThRyCkz

Share this post


Link to post
Share on other sites

i dont knw vbs code ill assume its the same as arma 2 sqf and same code commands. SO

im assuming in your example you whant an addaction on player2 that leats another player kill him ???? right if so you use

in editor in your player2 init have

this addAction ["kill", "kill.sqf",player distance <3];// the 3 is the deistance in mtrs players have to be to get the addaction

kill.sqf

_player2 = _this select 0;// player with addaction
_player1 = _this select 1;// player who selects addaction
_addaction = _this select 2;// the aDDACTION

_player2 setDamage 1;
_player2 removeAction _addaction;

---------- Post added at 14:34 ---------- Previous post was at 14:32 ----------

addaction

Share this post


Link to post
Share on other sites

Thank you!

Sorry if I confused you about vbs2, I thought it was the same as Arma 2's Language.

But yea, thank you it works!

---------- Post added at 03:57 ---------- Previous post was at 03:47 ----------

Ah wait, I thought it worked but I forget to save the changes so it was my old code, but I still have some questions.

I named my unit as germanGuy and I noticed you put a underscore at _playerone and _playertwo

why?

And what do you mean by:

_addaction = _this select 2;// the aDDACTION

How do I name the addaction?

Edited by ThRyCkz

Share this post


Link to post
Share on other sites

You could name the addAction by using this:

namehere = this addAction ["kill", "kill.sqf",player distance <3];

Then you can simply use

_playerone removeAction nameHere;

to remove it.

Share this post


Link to post
Share on other sites

Its still not working! Lol.

I was pretty much debugging it at this point, so please excuse the pointless code.

gShowCars.sqf:

_germanCarDealer = germancarDealer;
_Polizei = Polizei;
_gShowCarsV = gShowCarsV;

_germanCarDealer = _this select 0;
_Polizei = _this select 1;
_gShowCarsV = _this select 2;
_germanCarDealer removeAction _gShowCarsV;
_germanCarDealer removeAction gShowCarsV;

germanCarDealer = _this select 0;
Polizei = _this select 1;
gShowCarsV = _this select 2;
germanCarDealer removeAction _gShowCarsV;
germanCarDealer removeAction gShowCarsV;

gCarDealer.sqf:

gShowCarsV = this addAction ["kill", "kill.sqf",player distance <3];
_gShowCarsV = this addAction ["kill", "kill.sqf",player distance <3];

And in the init of my "player2" ( germanCarDealer in my case ) I have the execution code of the script.

So yea, I'm really confused, most about local variables, but to sum it up this is what I am confused about:

*Why is a local variable used to define the playername and not "player2"?

*Can I define any object in-game as a local variable? What will be the purpose?

*Did you guys already define it for me in the given code above?

Sorry its just that there's not much documentation other than the wiki and the forum.

Edited by ThRyCkz

Share this post


Link to post
Share on other sites

a) you are saving as sqs BUT the code given is sqf as sqs is now old and crap.

b) *Why is a local variable used to define the playername and not "player2"?

well the player name is not being brought to the script throught the addaction so we are using _this select 1 to reference the player

so for the purpose of the script we name it i.e

plyr = _this select 1;
//or
_whatever = _this select 1;



in any addaction
_whohadit =  _this select 0;// so name the var name whatever you want this just references the object that had the addaction
_caller =  _this select 1;// so name the var name whatever you want this just references the unit that used/called the addaction
_theraddaction = _this select 2;/ so name the var name whatever you want this just references the addaction its self.

c) Can I define any object in-game as a local variable? What will be the purpose?

just give it a name then use the name to call the code i.e

i name a vehicle rover in game to use it in a script i use its name rover like

 _deploy = "USBasicWeaponsBox" createVehicle (getPos rover); // notice the _deploy thats just a var name i give the ammobox local to this script.

i hope this helps

Share this post


Link to post
Share on other sites

So the _deploy is more of a handle for the statement that follows? I'm at school right now so I cannot test it yet, but it would see to make sense.

But this morning, I changed all files to .sqf and they still did not work, but above it looks as if I did not use the local var correctly at all; am I correct?I

Share this post


Link to post
Share on other sites

Some/most scripting functions returns something. E.g. createVehicle would return a reference to the vehicle that you just created, so _deploy is actually that vehicle. _deploy is also a local variable so it will be destroyed when the script finish running.

Share this post


Link to post
Share on other sites

maybe try this?

scripts\killinit.sqf

//Eggbeast kill action - inspired by DayZ scripts by Rocket

if (not (local player)) exitwith {};

player_kill = -1;
EB_myCursorTarget3 = objNull;

for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{
_player = player;
_vehicle = vehicle _player;
_inVehicle = (_vehicle != _player);
_hasknife = "M9" in (weapons _player); //etc - you can check for presence of specific weapon e.g. "m9" or take this out as you see fit
//	if (_hasknife) then {hintsilent "armed with knife"};
if ( (!isNull cursorTarget) and (!_inVehicle) and (_player distance cursorTarget < 3) and (_hasknife) ) then 
{
	_isMan = cursorTarget isKindOf "Man";
	_isAlive = alive cursorTarget;
	_text = getText (configFile >> "CfgVehicles" >> typeOf cursorTarget >> "displayName");
	//hintsilent format ["vec: %1", _text];
///////##################################
//Allow player to kill man
///////##################################
	if ( (_hasknife) and (_isMan) and (_isAlive) ) then 
	{
		if (player_kill < 0) then 
		{
			_vehicle = cursorTarget;
			EB_myCursorTarget3 = _vehicle;
			_fstring0 = format["kill ",_text];//kill name of type of man
			_ficon = "<img image='\ca\ui\data\ui_action_getingunner_ca.paa' size='1.0' shadow='false' />";
			_fstring = format ["<t color='#f79b31'>" +"%1 %2"+ "</t>",_ficon,_fstring0];
			player_kill = EB_myCursorTarget3 addAction [_fstring, "scripts\kill.sqf",[_vehicle,_player], 3, true, true,"",""];//assumes you have a kill.sqf in the folder of your mission in a folder called \scripts
		};
	} else 
	{
		EB_myCursorTarget3 removeAction player_kill;
		player_kill = -1;
	};
} else 
///////##################################
{
	EB_myCursorTarget3  removeAction player_kill; player_kill = -1;
};
sleep 1;
};

scripts\kill.sqf

//Eggbeast kill action - inspired by DayZ scripts by Rocket

//kill target 
Tman = _this select 0;
_player = _this select 1;

Tman removeAction player_kill;
player_kill = -1;

playsound "kill";//you need to define this in description.ext
_player playActionNow "GesturePoint";
Tman setdamage 1;

then just run this on the client (in init line of player or in spawn.sqf etc)

_monitor = [] execVM "scripts\killinit.sqf"

it works a treat - just needs some work to name the target properly

screenies

icon/action placed on target

http://i162.photobucket.com/albums/t247/eggbeast/kill1.jpg

killing a cow with your magic finger

http://i162.photobucket.com/albums/t247/eggbeast/kill2.jpg

to restrict kill to one named player "GEEZER"

just add this into line above

_vehicle = cursorTarget;

if _vehicle ="GEEZER" then{##move the callaction script in here##};

it's actually kind of fun using Dim Mak on stuff... may have to add it to my mission!

EDIT: we've now added it to Evolution for the spy to use wit ha Fairbairn commando knife in his possession - works a treat although wedon't have a model/anim for the weapon, so using point anim and the knife is a magazine.

Edited by eggbeast

Share this post


Link to post
Share on other sites
Sign in to follow this  

×