Useful Player Storage Procedures

Discussion in 'CommandHelper Scripts' started by EDawg878, Dec 23, 2012.

  1. EDawg878

    EDawg878 Member

    Here I'll post some very useful storage procedures if you want to store information for a specific player. Each value will be stored under a subkey under the player's main key. This also supports arrays within the subkeys. This was made to be error free so you can directly check a players key and if empty it will return an empty array. It also supports temporary storage via import() and export(), you just need to append true to the last argument. It also auto-cleans itself, when the array of values become empty it will clear itself.
    Some straightfoward usage:
    _playerStoreValue(player(), 'sub_key_name', value) or _playerStoreValue(player(), ''sub_key_name', value, true)
    _playerGetValue(player(), 'sub_key_name') or _playerGetValue(player, 'sub_key_name', true)
    _playerHasValue(player(), 'sub_key_name') or _playerHasValue(player, 'sub_key_name', true)
    _playerClearValue(player, 'sub_key_name') or _playerStoreValue(player(), ''sub_key_name', value, true)
    For arrays within a subkey:
    _playerSubKeyClearValue(player(), 'sub_key_name', value) or _playerSubKeyClearValue(player(), 'sub_key_name', true)
    _playerPushValue(player(), 'sub_key_name', value) or _playerPushValue(player(), 'sub_key_name', value, true)
    If you wanted to get an array of all the player's values:
    _playerGetValues(player()) or _playerGetValues(player(), true)

    I'm not sure if this still works but I thought it might be helpful for some people

    After usage with several scripts a player's key should look something like this:
    {"muted":1352424477069,"spouse":"username","gender":"male", "vote_time":1352507539871,marry_home":[-124,64,-405,"default"],"plots":[[-2,-5], [-1,1]]}
  2. RataRataData

    RataRataData Member

    Thank you, this helped me allot and i now use modified version of this.

    @tag = substr(to_lower(@player), 0, 1)  if (@tag == '_') { @tag = concat(@tag.'symbols') }
    now just add @tag before @player when u call or store stuff inside proc.
    all data is now stored likeso: or
    But i store all in:
    store_value(concat('playerdatabase.'[email protected]tag.'.', @player), @player_data)
    I have different file for every letter, number and one file for symbols.