get/setData usage

  1. 7 years ago

    Hey all,

    Was looking into how to setup a database for my mission when I noticed that the inbuilt ALiVE saving can do custom variables .
    So i gave it a try but for some reason I can't get it to 'stick', attempting to create persistent 'factions' for my players, so when they join a faction via dialog, it gives them a loadout but then also ["Player_Rank", "Airman Basic"] call ALiVE_fnc_setData; ["Player_Faction", "United States Airforce"] call ALiVE_fnc_setData; .

    When a player dies, I want them to respawn at a faction specific place, so I have this in place;

    onPlayerRespawn.sqf

    getFaction = ["Player_Faction"] call ALiVE_fnc_getData;
    getRank = ["Player_Rank"] call ALiVE_fnc_getData;
    if (getFaction == "United States Air Force") then {
    	Player setPos (getMarkerPos "AviationSpawn");
    	comment "Remove existing items";
    removeAllWeapons player;
    removeAllItems player;
    removeAllAssignedItems player;
    removeUniform player;
    removeVest player;
    removeBackpack player;
    removeHeadgear player;
    removeGoggles player;
    
    comment "Add containers";
    player forceAddUniform "rhs_uniform_cu_ucp";
    player addHeadgear "rhsusf_patrolcap_ucp";
    
    comment "Add weapons";
    
    comment "Add items";
    player linkItem "ItemMap";
    player linkItem "ItemCompass";
    player linkItem "ItemWatch";
    };

    Am I using this wrong or is there something else at fault here perhaps?

    Thanks in advance (again)!

  2. The function needs to be ran on the server. Running it locally will yield no data retrieval or storage.

  3. So running it with the if (isDedicated) command will still save that player to that faction in your opinion?

  4. isDedicated only checks if the current environment is a dedicated server, it doesn't ensure the code is ran on the proper client. You need to use remoteExec/remoteExecCall for this purpose.

  5. Edited 7 years ago by uncreatedlemon

    Ugh, I don't know why, but remoteExec really screws with my mind on how to structure it xD

    Any chance of a script snippet or critique on this?:

    ["Player_Rank","Airman Basic"] remoteExec ["ALiVE_fnc_setData", *Target goes here* , false];
  6. Edited 7 years ago by SpyderBlack723
    ["Player_Rank","Airman Basic"] remoteExec ["ALiVE_fnc_setData",2];

    To force server execution

  7. Edited 7 years ago by SpyderBlack723

    You'll have to make sure data is unique for each player, like storing it in an array for example

    _playerRanks = [
        ["player1name", "player1rank"],
        ["player2name","player2rank"],
        ["player3name","player3rank"]
    ]
    _playerRanks pushback ["playername","playerrank"];
  8. Edited 7 years ago by uncreatedlemon

    Would that require naming each player controlled unit in the editor?

    not too sure how I would utilize that array...Sorry, still learning this stuff lol

    edit:

    Something similar to this perhaps?

    _playerName = name _caller;
    _player_rank = rank _caller;
    _playerRanksArray = [];
    
    _playerRanksArray pushback [_playerName,_playerRank];
    
    [_playerRanksArray] remoteExec ["ALiVE_fnc_setData", _caller]];

    _caller is the player with the interface (all this is done through a dialog)

  9. That is sort of the process yes, if you want to keep it a bit simpler and avoid doing remoteExecs, this is how you could handle it from the client view.

    private _name = name player;
    private _rank = rank player;
    
    // if the array doesn't exist yet, create it
    if (isnil "Persistent_Rank_Array") then {
    	Persistent_Rank_Array = [];
    };
    
    // check to see if data for this player exists already
    // if so, delete it
    {
    	if ((_x select 0) == _name) exitWith {
    		Persistent_Rank_Array deleteat (_forEachIndex);
    	};
    } foreach Persistent_Rank_Array;
    
    // add player data to array
    Persistent_Rank_Array pushback [_name, _rank];
    
    // broadcast updated array for other clients
    PublicVariable "Persistent_Rank_Array";
    
    // save array on server
    ["PlayerRanks", Persistent_Rank_Array] remoteExec ["ALiVE_fnc_setData", 2];
 

or Sign Up to reply!