CocaColaBear / types-ragemp-c

Rage:MP TypeScript type definition for Client-side
https://rage.mp/
MIT License
52 stars 60 forks source link

v2: Accessible Prototypes/Checkpoint & Markers Typings #85

Closed checkeredblast2914 closed 2 years ago

checkeredblast2914 commented 2 years ago

I made the different entity type classes accessible for extension because of July rage.mp update. It uses abstract class with declaration merging because developer should only create entity using pools. It has been tested and is backward compatible.

Now you can do something like this

// in *.d.ts
declare global {
  interface PlayerMp {
    newFunction(): void;
  }
}

// in gamemode
mp.Player.newFunction = function () {
  mp.gui.chat.push("hello");
}

You can still do example like

interface ExtendedPlayerMp extends PlayerMp {
  newProperty: boolean;
};

mp.events.add("playerReady", () => {
  let localPlayer: ExtendedPlayerMp = mp.players.local;
  localPlayer.newProperty = true;
});