Jump to content
Sign in to follow this  
BullyBoii

Script Error - add action and if

Recommended Posts

hi guys, im back again with a rather simple problem

im trying to add an action to a unit for the player to

activate when they are at a certain distance <=5meters

but im getting scripting errors this is what i wrote so far:


//////////////////////////////////////////////////////////////////
// Function file for Armed Assault 2 Operation Arrowhead
// Created by: TODO: Adam
// use: shop = [] execVM "shop.sqf" in the init box of shopman
//////////////////////////////////////////////////////////////////

//trigger to check whether player is close enough to shopman to use the action "Use Shop"

if (player distance shopman <= 5) then 
{
	_accessShop = shopman addAction ["Use Shop", "shop_access.sqf]
} 
else 
{
	shop removeAction _accessShop and hint "action removed"
};

im not great at coding and i cant see why this is going wrong so any help is

very much appreciated

thanks

Share this post


Link to post
Share on other sites

if (player distance shopman <= 5) then 
{
	_accessShop = shopman addAction ["Use Shop", "shop_access.sqf"];
} 
else 
{
	shopman removeAction _accessShop;
	hint "action removed";
};

Speaking of 5 meters distance, there is "condition" argument for addAction. Your script will actually do nothing since it will run check once and end.

Share this post


Link to post
Share on other sites

Missing the trailing " after shop_access.sqf

Also you don't need this at all since you can just have the distance check part of the addAction in the first place replacing your script call in shopman's init with this.

this addAction ["Use Shop","shop_access.sqf",[],1,false,true,"","_this distance _target <= 5"];

Share this post


Link to post
Share on other sites

thanks guys, really helpfull

i was quite sure on how to do that, the BI wiki doesnt really go into too much detail about that subject and im not great at these sort of things :)

Share this post


Link to post
Share on other sites
im not great at these sort of things :)

Heh, don't be hard on yourself, we're all still learning! :) That quote did make me think of this though.

Share this post


Link to post
Share on other sites

i would also like to mnow if its posible to add a weapon via variable

i have made an action for a man to be able to pick up an ammo box

which removes his weapon, but then i dont know how to add it back

into the inventory


ammo_1 attachTo [player, [0,1,1.6]];

_mainWeapon = weapons player;
removeallweapons player;
hintsilent "you can only carry onject for 10 seconds until you have to put it down\n\nIts rather heavy";
sleep 10;
detach ammo_1;
ammo_1 setpos [getpos ammo_1 select 0, getpos ammo_1 select 1, 0];
player addWeapon _mainweapon;

thanks

Share this post


Link to post
Share on other sites

init of the ammo box:

this addAction ["Carry","carrybox.sqf",[],1,false,true,"","_this distance _target <= 2"];

carrybox.sqf:

ammo_1 attachTo [player, [0,1,.6]];

_mainWeapon = primaryWeapon player;
player removeWeapon _mainWeapon;
hintsilent "You can only carry an object for 10 seconds until you have to put it down!\n\nIt's rather heavy.";
sleep 10;
detach ammo_1;
ammo_1 setpos (player modelToWorld [0, 1, 0]);
player addWeapon _mainWeapon;
player selectWeapon primaryWeapon player;

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  

×