Jump to content
RAGE Multiplayer Community

Native storage 1.0.0

   (3 reviews)

About This File

Installing

  • Put the files you downloaded in client_packages
  • Add require('gameStorage') to client_packages/index.js
  • All done

Notes

  • This storage is cleared only after a complete re-entry into the game

 

Client API

mp.gameStorage.setFloat(property, value);
mp.gameStorage.setInt(property, value);
mp.gameStorage.setString(property, value);

mp.gameStorage.getFloat(property);
mp.gameStorage.getInt(property);
mp.gameStorage.getString(property);


Examples
Setting and getting value:

mp.gameStorage.setFloat('floatKey', 0.51243);
mp.gameStorage.setInt('intKey', 15621);
mp.gameStorage.setString('stringKey', 'ragemp');

mp.gui.chat.push(`${mp.gameStorage.getFloat('floatKey')}`);
mp.gui.chat.push(`${mp.gameStorage.getInt('intKey')}`);
mp.gui.chat.push(`${mp.gameStorage.getString('stringKey')}`);

Deleting blips created with mp.game.ui.addBlipForCoord after reconnecting:

const PLAYER_READY_EVENT = 'playerReady';
const CREATED_BLIPS_KEY = 'createdBlips';
const F2_KEYCODE = 0x71;

const createdBlips = [];

const addHandle = (handle) => {
  createdBlips.push(handle);
  
  mp.gameStorage.setString(
    CREATED_BLIPS_KEY,
    JSON.stringify(createdBlips)
  );
};

const getDepricatedBlips = () => {
  try {
    return JSON.parse(mp.gameStorage.getString(CREATED_BLIPS_KEY));
  } catch {
    return [];
  }
};

const handlePlayerReady = () => {
  const blips = getDepricatedBlips();
  
  for (let handle of blips) {
    if (mp.game.ui.doesBlipExist(handle)) {
      mp.game.ui.removeBlip(handle);
    }
  }

  mp.gameStorage.setString(CREATED_BLIPS_KEY, '');
};

const handleCreateBlip = () => {
  const handle = mp.game.ui.addBlipForCoord(0, 0, 0);
  addHandle(handle);
};

mp.events.add(PLAYER_READY_EVENT, handlePlayerReady);
mp.keys.bind(F2_KEYCODE, true, handleCreateBlip);

 

Edited by hartority
Formatting

  • Like 3
 Share


User Feedback

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest

×
×
  • Create New...