Jump to content
Sign in to follow this  
PartyHead

Need help with my script.

Recommended Posts

Hello community I need your help again.

I'm trying to make a simple player save gear script for my SP mission but I'm having some trouble with part of it.

So far I have this as my save.sqf script.

sleep 1;

if (isNull player) exitWith {};

while {true} do
{
   waitUntil {alive player};

   while {alive player} do 
   {
    if (headGear player == "") then {player setVariable ["hgear",0]} else {player setVariable ["hgear",headGear player]};
    if (uniform player == "") then {player setVariable ["uform",0]} else {player setVariable ["uform",uniform player]};
    if (vest player == "") then {player setVariable ["bvest",0]} else {player setVariable ["bvest",vest player]};
    if (goggles player == "") then {player setVariable ["gogs",0]} else {player setVariable ["gogs",goggles player]};
    if (backpack player == "") then {player setVariable ["bpack",0]} else {player setVariable ["bpack",backpack player]};
    if (count items player == 0) then {player setVariable ["itms",0]} else {player setVariable ["itms",items player]};
    if (count magazines player == 0) then {player setVariable ["mags",0]} else {player setVariable ["mags",magazines player]};
    if (count weapons player == 0) then {player setVariable ["weaps",0]} else {player setVariable ["weaps",weapons player]};
    if (count primaryWeaponItems player == 0) then {player setVariable ["weapitems",0]} else {player setVariable ["weapitems",primaryWeaponItems player]};
    if (count handgunItems player == 0) then {player setVariable ["hangunitems",0]} else {player setVariable ["hangunitems",handgunitems player]};
       sleep 1;
   };
   sleep 2;
};

// Exit script
if (true) exitWith {};

No worries there.

But I cant get this highlighted part working in part of my respawn.fsm script.

_gogs = player getVariable "gogs";
_hgear = player getVariable "hgear";
_bpack = player getVariable "bpack";
_bvest = player getVariable "bvest";
_uform = player getVariable "uform";
_items = player getVariable "itms";
_mags = player getVariable "mags";
_weaps = player getVariable "weaps";
_weapitems = player getVariable "weapitems";
_hangunitems = player getVariable "hangunitems";

_oldgogs = _gogs;
_oldhgear = _hgear;
_oldbpack = _bpack;
_oldbvest = _bvest;
_olduform = _uform;

_olditems = _items;
_oldmags = _mags;
_oldweaps = _weaps;
_oldweapitems = _weapitems;
_oldhangunitems = _hangunitems;

hintSilent format ["%1\n\n%2\n\n%3\n\n%4\n\n%5\n\n%6\n\n%7\n\n%8\n\n%9\n\n%10",_oldgogs,_oldhgear,_oldbpack,_oldbvest,_olduform,_olditems,_oldmags,_oldweaps,_oldweapitems,_oldhangunitems];

removeGoggles player;
removeHeadgear player;
removeBackpack player;
removeVest player;
removeUniform player;

{player removeItem  _x} forEach items player;
{player removeMagazine _x} forEach magazines player;
{player removeWeapon _x} forEach weapons player;

[color="#FF0000"]
if (_oldgogs == 0) then {hintSilent "No googles"} else {player addGoggles _oldgogs};
if (_oldhgear == 0) then {hintSilent "No headgear"} else {player addHeadgear _oldhgear};
if (_olduform == 0) then {hintSilent "No uniform"} else {player addUniform _olduform};
if (_oldbvest == 0) then {hintSilent "No vest"} else {player addVest _oldbvest};
if (_oldbpack == 0) then {hintSilent "No backpack"} else {player addBackpack _oldbpack};
[/color]

if (count _olditems > 0) then {{player addItem _x} forEach _olditems};
if (count _oldmags > 0) then {{player addMagazine _x} forEach _oldmags};
if (count _oldweaps > 0) then {{player addWeapon _x} forEach _oldweaps};

removeAllPrimaryWeaponItems player;
removeAllHandgunItems player;

if (count _oldweapitems > 0) then {{player addPrimaryWeaponItem _x} forEach _oldweapitems};
if (count _oldweapitems > 0) then {{player addHandgunItem _x} forEach _oldhangunitems};

The hint returns this as an example.

p><p>The script breaks and I

The error message says.

Error in expression <player addGoggles _oldgogs};
if (_oldhgear == 0) then {hintSilent "No headgear"} else {player addHeadgear _ol>
 Error position: <== 0) then {hintSilent "No headgear"} else {player addHeadgear _ol>
 Error Generic error in expression

Does anyone have any ideas what I've done wrong ?

Cheers.

Edited by PartyHead

Share this post


Link to post
Share on other sites

Its because you are comparing a string to a number. As there is actually some headgear "H_HelmetB". "H_HelmetB" == 0 results in a generic error. Instead of using 0 as an indication of no item use nil instead then you can just say

save

if (headgear player != "") then {player setvariable ["hgear",headgear player]};

load

if (!(isnil {player getVariable ["hgear",nil]})) then {player addHeadGear (player getVariable ["hgear",nil])};

Or some variation of

OR

save

player setVariable ["hgear", headGear player];

load

if ( (player getVariable "hgear") != "" ) then {player addHeadGear (player getVariable "hgear")}

Edited by Larrow

Share this post


Link to post
Share on other sites

Thanks Larrow I had that all ass about face.

Ended up with the following changes and all works now.

Save.sqf

sleep 1;

if (isNull player) exitWith {};

while {true} do
{
   waitUntil {alive player};

   while {alive player} do 
   {
    player setVariable ["hgear",headGear player];
    player setVariable ["uform",uniform player];
    player setVariable ["bvest",vest player];
    player setVariable ["gogs",goggles player];
    player setVariable ["bpack",backpack player];
    player setVariable ["itms",items player];
    player setVariable ["mags",magazines player];
    player setVariable ["weaps",weapons player];
    player setVariable ["weapitems",primaryWeaponItems player];
    player setVariable ["hangunitems",handgunitems player];
       sleep 1;
    };
   sleep 2;
};

// Exit script
if (true) exitWith {};

Respawn.fsm

_hgear = player getVariable "hgear";
_uform = player getVariable "uform";
_bvest = player getVariable "bvest";
_gogs = player getVariable "gogs";
_bpack = player getVariable "bpack";

_items = player getVariable "itms";
_mags = player getVariable "mags";
_weaps = player getVariable "weaps";
_weapitems = player getVariable "weapitems";
_hangunitems = player getVariable "hangunitems";

_oldgogs = _gogs;
_oldhgear = _hgear;
_oldbpack = _bpack;
_oldbvest = _bvest;
_olduform = _uform;

_olditems = _items;
_oldmags = _mags;
_oldweaps = _weaps;
_oldweapitems = _weapitems;
_oldhangunitems = _hangunitems;

removeGoggles _obj;
removeHeadgear _obj;
removeBackpack _obj;
removeVest _obj;
removeUniform _obj;

{_obj removeItem  _x} forEach items _obj;
{_obj removeMagazine _x} forEach magazines _obj;
{_obj removeWeapon _x} forEach weapons _obj;

if (_oldgogs != "" ) then {_obj addGoggles _oldgogs};
if (_oldhgear != "" ) then {_obj addHeadGear _oldhgear};
if (_olduform != "" ) then {_obj addUniform _olduform};
if (_oldbvest != "" ) then {_obj addVest _oldbvest};
if (_oldbpack != "" ) then {_obj addBackpack _oldbpack};

if (count _olditems > 0) then {{_obj addItem _x} forEach _olditems};
if (count _oldmags > 0) then {{_obj addMagazine _x} forEach _oldmags};
if (count _oldweaps > 0) then {{_obj addWeapon _x} forEach _oldweaps};

removeAllPrimaryWeaponItems _obj;
removeAllHandgunItems _obj;

if (count _oldweapitems > 0) then {{_obj addPrimaryWeaponItem _x} forEach _oldweapitems};
if (count _oldhangunitems > 0) then {{_obj addHandgunItem _x} forEach _oldhangunitems};

Thanks again for your help Larrow, I really appreciate it mate.

Edited by PartyHead

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  

×