Jump to content

Native storage 1.0.0

   (4 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

User Feedback

Create an account or sign in to leave a review

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

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

rootcause

   3 of 3 members found this review helpful 3 / 3 members

5/5 very clever

Link to review
×
×
  • Create New...