Jump to content
  • 0

help with this script whats wrong with this if statement


calamity

Question

im trying to allow players to re-arm  the AH6J_EP1_DZE

since I cannot find the 4000Rnd_762x51_M134 (just wont spawn)

I would like  to use 2 2000 rnd mags to give littlebird 4000 rounds

 

no matter what I try it will show add M134 ammo option in scroll, even if player only has 1 mag

 

whats wrong with this?????????

 

_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
    if ("2000Rnd_762x51_M134" in magazines Player) and ("2000Rnd_762x51_M134" in magazines Player) then {
       _hasmags = true;
    } else {
       _hasmags = false;
    };
if (_isalb and _hasmags) then {
        if (s_player_litl < 0) then {
  //          s_player_litl = player addAction [("<t color=""#39C1F3"">" + ("add M134 ammo x2") +"</t>"), "custom\littlebird.sqf",_cursorTarget, 0, true, false, "",""];
s_player_litl = player addAction ["add M134 ammo","custom\littlebird.sqf",cursorTarget, 0, false, true, "",""];
        };
    } else {
        player removeAction s_player_litl;
        s_player_litl = -1;
    };

I have tried a few wayz...

 

    if (cursorTarget isKindOf "AH6J_EP1_DZE" && ("2000Rnd_762x51_M134" in magazines player) and ("2000Rnd_762x51_M134" in magazines player) and (player distance cursorTarget < 5) and _canDo) then {
if (s_player_litl < 0) then {
            s_player_litl = player addAction ["add M134 ammo x2","custom\littlebird.sqf",cursorTarget, 0, false, true, "",""];
        };
    } else {
        player removeAction s_player_litl;
        s_player_litl = -1;
    };

any help would be great..

 

I just cant see the problem

Link to comment
Share on other sites

17 answers to this question

Recommended Posts

  • 0

Do it like this:
 

_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;

if (_mgQTY == 2 and  _isalb) then {
    if (s_player_litl < 0) then {
        s_player_litl = player addAction ["add M134 ammo x2","custom\littlebird.sqf",cursorTarget, 0, false, true, "",""];
    };
} else {
        player removeAction s_player_litl;
        s_player_litl = -1;
};

Dont forget to add : s_player_litl = -1;   in your variables.sqf

And also "_isalb","_mgQTY"  at the top of your fn_selfactions.sqf inside the private declaration

Link to comment
Share on other sites

  • 0
_hasmags = (({_x == "2000Rnd_762x51_M134"} count (magazines player)) >= 2);

The reason it wasn't working was because you were performing the same check twice without editing the player's inventory in between checks. So if they only had 1 item the first check would return true, they would keep the item, then the second check would also return true. The code I provided here will work just fine for you.

 

EDIT: Sandbird's suggestion is the way to go, but note there is a tiny oversight in there-

if (_mgQTY == 2 and  _isalb) then {

Should ideally be-

if (_mgQTY >= 2 and  _isalb) then {

Else, player's with more than 2 mags on them will not get the option which isn't logical.

Link to comment
Share on other sites

  • 0

thanks for this. I see your way is better but whats wrong with this way ??

 

if ("2000Rnd_762x51_M134" in magazines Player) and ("2000Rnd_762x51_M134" in magazines Player)

 

is it because it checks for the item and then checks for item again not actually totalling 2  magazines ??

 

your way works great and will be how I do it from now on but still wonder why mine didnt work...

 

 

edit...

I guess I got my answer thankz CordAsis

Link to comment
Share on other sites

  • 0

now correct me if i'm wrong

but with epoch 1.0.5 onwards, you cant use if (_this and _that) then

i was under the impression 'and' now had  to be &&
and
or had to be ||

so i would try

if ((_mgQTY >= 2) && (_isalb)) then { 
Link to comment
Share on other sites

  • 0

thankz guyz....

 

now i have issues with littlebird.sqf

what im trying to do is allow player to add ammo to the AH6J_EP1_DZE

 

it works but I have to do it 2 times. first time nothing happends it just removes two 2000 rnd mags

second time it works...

 

this all started when another admin asked in scripting help 

 

I could use help helping them....

 

what I have tried for littlebird.sqf

private ["_lilbird","_vehicle","_mgQTY"];

_vehicle = vehicle player;
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;


// if ("2000Rnd_762x51_M134" in magazines player) then {
if (_mgQTY >= 2) then {
player playActionNow "PutDown";
player removeMagazine "2000Rnd_762x51_M134";
player removeMagazine "2000Rnd_762x51_M134";
_lilbird = nearestObject [player, "AH6J_EP1_DZE"];
_vehicle _lilbird addMagazine "4000Rnd_762x51_M134";


systemchat "You have added a magazine to the little bird.";
} else {
systemchat "You do not have 2000 Round M134 ammo in your inventory.";
};

tried it a few ways with not working correctly ;(

 

seems should be as simple as 

remove 2 2000rnd mags

add one 4000 rnd mag

 

 

 

Link to comment
Share on other sites

  • 0

 

any one see why I have to add m134 x2 two times ?

I select add M134 ammo x2 first time, but it only takes ammo does not place in little bird

I do it a second time and it works so it costs me 4,  2000Rnd_762x51_M134

 

fn_SelfActions

_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;


if (_mgQTY >= 2 and  _isalb) then {
    if (s_player_litl < 0) then {
        s_player_litl = player addAction ["add M134 ammo x2","custom\littlebird.sqf",cursorTarget, 0, false, true, "",""];
    };
} else {
        player removeAction s_player_litl;
        s_player_litl = -1;
};

 

 

 

littlebird.sqf

private ["_lilbird","_vehicle","_isalb","_mgQTY"];

_lilbird = nearestObject [player, "AH6J_EP1_DZE"];
// _isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;

if (_mgQTY >= 2) then {

player removeMagazine "2000Rnd_762x51_M134";
player removeMagazine "2000Rnd_762x51_M134";
_lilbird addMagazine "4000Rnd_762x51_M134";

systemchat "You have added a magazine to the little bird.";

} else {
systemchat "You do not have two 2000 Round M134 ammo in your inventory.";
};
Link to comment
Share on other sites

  • 0

ok for those that want this option

fn_selfActions.sqf

 

_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;


if (_mgQTY >= 2 and  _isalb) then {
    if (s_player_litl < 0) then {
        s_player_litl = player addAction ["add M134 ammo x2","custom\littlebird.sqf",cursorTarget, 0, false, true, "",""];
    };
} else {
        player removeAction s_player_litl;
        s_player_litl = -1;

custom\littlebird.sqf

 

private ["_lilbird","_isalb","_mgQTY"];


_lilbird = nearestObject [player, "AH6J_EP1_DZE"];
_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;
// if (_mgQTY >= 2 and _lilbird) then {
if (_mgQTY >= 2) then {

player removeMagazine "2000Rnd_762x51_M134";
player removeMagazine "2000Rnd_762x51_M134";

_lilbird addMagazine "4000Rnd_762x51_M134";
_lilbird addMagazine "4000Rnd_762x51_M134";

systemchat "You have added a magazine to the little bird.";

} else {
systemchat "You do not have 2000 Round M134 ammo in your inventory.";
};

not sure why I had to add magazine twice

maybe since there are two turrets, but this is working now

 

I had tried  but it didnt work....

 

_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[0]];
_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[1]];

thankz for your help guyz......

 

now to add movement and sound...

 

Link to comment
Share on other sites

  • 0

Hey calamity, you can use [-1] for the driver's seat turret path. This might remove the need for you add the ammo twice to get it to show up.

EDIT: Also, after a quick check you can add the 2000rnd ammo variant to the little bird also, that is with the AH6J_EP1/_DZ/_DZE models, just in case you want them as an option.

Link to comment
Share on other sites

  • 0

this works also but still requires doing it twice

_lilbird removeMagazinesTurret ["4000Rnd_762x51_M134",[0]];
_lilbird removeMagazinesTurret ["4000Rnd_762x51_M134",[1]];
// _vehicle _lilbird addMagazine "4000Rnd_762x51_M134";
//_lilbird addMagazine "4000Rnd_762x51_M134";
//_lilbird addMagazine "4000Rnd_762x51_M134";
_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[0]];
_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[1]];
Link to comment
Share on other sites

  • 0

I have no idea but just from viewing this i would say that the [0] is an array. So why not doing [0,1] in the addmagazin turret? Does that not work or what do you mean by doing it twice?

this seems to work.

by needing to do it twice I mean I scroll choose add ammo, system chat says ammo added, removes players 2 magz, does not give litttlebird ammo

repeat same steps and it works...

 

im guessing it needs 2 times since there are two turrets

 

this seems to work first try....

 

littlebird.sqf

private ["_lilbird","_isalb","_mgQTY"];

_lilbird = nearestObject [player, "AH6J_EP1_DZE"];
_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;
_sounddist = 20;
_dis=100;
if (_mgQTY >= 2) then {

player playActionNow "Medic";
sleep 1;
[player,"combo_unlock",0,false] call dayz_zombieSpeak;
sleep 1;
playsound "MinigunReload";
[player,_dis,true,(getPosATL player)] spawn player_alertZombies;

player removeMagazine "2000Rnd_762x51_M134";
player removeMagazine "2000Rnd_762x51_M134";

_lilbird removeMagazinesTurret ["4000Rnd_762x51_M134",[0]];
_lilbird removeMagazinesTurret ["4000Rnd_762x51_M134",[1]];

_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[0]];
_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[1]];

_lilbird addMagazine "4000Rnd_762x51_M134";
_lilbird addMagazine "4000Rnd_762x51_M134";


systemchat "You have added a magazine to the little bird.";

} else {
systemchat "You do not have 2000 Round M134 ammo in your inventory.";
};
Link to comment
Share on other sites

  • 0

 

now correct me if i'm wrong

but with epoch 1.0.5 onwards, you cant use if (_this and _that) then

i was under the impression 'and' now had  to be &&

and

or had to be ||

so i would try

if ((_mgQTY >= 2) && (_isalb)) then { 

That's just personal preference. There is no reason to do this beyond making your code look fancier and it maybe (?) is slightly faster than using or / and

Link to comment
Share on other sites

  • 0

You save 1 character in the file, that's all ;)

 

But as far as I understand it...for this:

 

_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;
if (_mgQTY >= 2 and  _isalb) then {

 

...you evaluate _isalb with the code 'cursorTarget isKindOf "AH6J_EP1_DZE";' And you evaluate _mgQTY with the code '{_x == "2000Rnd_762x51_M134"} count magazines player;'.

 

 

If you would do it like:

if (_isalb && ( {_x == "2000Rnd_762x51_M134"} count magazines player; >=2 ) ) then {

 

...then you save the evaluation of the second part if _isalb is already false. The second part/code in the if will only be executed if the first part is already true. So the command which creates less load should be always first and more expensive code second. I did not check if the systax is really correct here (with brackets and so on)...just as an example.

 

Depending on the code used as part a or b in the condition I guess this can really save some performance by avoiding unnecessary statements.

But ok, it's easier to read if you evaluate the expressions first and then do the if ,)

Link to comment
Share on other sites

  • 0

Dirty and fast:

/*Written by StiflersM0M on the 08.11.2014*/
/*Variables, paste it under if (DZE_ActionInProgress) exitWith {}; // Do not allow if any script is running.*/

_cursorTarget = cursorTarget;
_cttype = typeOf _cursorTarget;
_ctdistance = player distance _cursorTarget;
if(isnil "s_player_rearm_vehicle") then {s_player_rearm_vehicle = -1;};

/*Add Self action to rearm the armed littlebird maybe paste it under if (!DZE_ForceNameTagsOff) then { selfaction*/

if ((!isNull _cursorTarget) && (_cttype == "AH6J_EP1_DZE") && (_ctdistance < 5) && (!_inVehicle) && (_canDo)) then {
s_player_rearm_vehicle = player addAction ["Rearm AH6J", "scripts\rearm.sqf", [_cursorTarget,_cttype]];
} else {
player removeAction s_player_rearm_vehicle;
s_player_rearm_vehicle = -1;
};

/*rearm.sqf Code*/
_cursorTarget = _this select 0;
_cttype = _this select 1;
_2000rnd = {_x == "2000Rnd_762x51_M134"} count magazines player;
if (_cttype == "AH6J_EP1_DZE") then {

	if ((_2000rnd >= 1) && (!DZE_ActionInProgress)) then {
	DZE_ActionInProgress = true;
	[player,"2000Rnd_762x51_M134"] call BIS_fnc_invRemove;
	cutText [format["1x 2000Rnd_762x51_M134 has been added to your %1!", _cttype], "PLAIN DOWN"];
	_cursorTarget addMagazine "2000Rnd_762x51_M134";
	DZE_ActionInProgress = false;
	} else {
	if (_2000rnd < 1) then {
	cutText [format["%1, you are missing 1x more of 2000Rnd_762x51_M134 ammo to rearm your %2", name player,_cttype], "PLAIN DOWN"];
	DZE_ActionInProgress = false;
	};
	if (!DZE_ActionInProgress) then {
	cutText [format["Action allready in progress!"], "PLAIN DOWN"];
	DZE_ActionInProgress = false;
	};
	};
} else {
cutText [format["%1, cant be rearmed, only the AH6J_EP1_DZE",_cttype], "PLAIN DOWN"];
DZE_ActionInProgress = false;
};

I dont tested it. if you got any bugs, tell me it.

Link to comment
Share on other sites

  • 0

thankz for all your help with this...

next step...

should this work to check if already has mag installed ???

 

private ["_lilbird","_isalb","_mgQTY","_hasm134mag"];

_lilbird = nearestObject [player, "AH6J_EP1_DZE"];
_isalb = cursorTarget isKindOf "AH6J_EP1_DZE";
_mgQTY = {_x == "2000Rnd_762x51_M134"} count magazines player;
_sounddist = 20;
_dis=100;

if (dayz_combat == 1) exitWith {
_msg = "You cant ADD M134 Ammo while in combat.";
cutText [_msg, "PLAIN DOWN"];
};

_hasm134mag = _Vehicle getVariable["m134installed",0];    // added to check if Variable m134installed exists ???????
if(_hasm134mag == 1)exitwith{cutText ["This little bird already has 4000 rnd mag installed", "PLAIN DOWN"];};

if (_mgQTY >= 2) then {

player playActionNow "Medic";
sleep 1;
[player,"combo_unlock",0,false] call dayz_zombieSpeak;
sleep 1;
playsound "MinigunReload";
[player,_dis,true,(getPosATL player)] spawn player_alertZombies;

player removeMagazine "2000Rnd_762x51_M134";
player removeMagazine "2000Rnd_762x51_M134";

_lilbird removeMagazinesTurret ["4000Rnd_762x51_M134",[0]];
_lilbird removeMagazinesTurret ["4000Rnd_762x51_M134",[1]];

_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[0]];
_lilbird addMagazineTurret ["4000Rnd_762x51_M134",[1]];

_lilbird addMagazine "4000Rnd_762x51_M134";
_lilbird addMagazine "4000Rnd_762x51_M134";
_lilbird setVariable ["m134installed", 1, true];      // added to setVariable m134installed     ???????
systemchat "You have added a magazine to the little bird.";

} else {
systemchat "You do not have 2000 Round M134 ammo in your inventory.";
};

edit... _hasm134mag variable not working, actually doesnt matter  then it has an extra mag to reload...

would still like to know how to set a variable like this

if anyone can explain it

Link to comment
Share on other sites

  • 0

maybe (?) is slightly faster than using or / and

imo there's probably minor and irrelevant difference, because alias like and / or have to be "translated" (interpreted?) into && / || by engine, so an extra step needs to be done.... you get the idea

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...