Coder Social home page Coder Social logo

Pools and callbacks about cleo-redux HOT 5 CLOSED

cleolibrary avatar cleolibrary commented on July 20, 2024
Pools and callbacks

from cleo-redux.

Comments (5)

x87 avatar x87 commented on July 20, 2024 2

some ideas:

addEventListener("onMount", () => { log("script has been reloaded") })
addEventListener("onUnMount", () => { log("script is about to be unloaded") })

from cleo-redux.

x87 avatar x87 commented on July 20, 2024

as I mentioned on Discord you can iterate pool using existing Memory command (not in DE for now).

Example script creating blips over police cars in GTA 3 1.0

/// <reference path=".config/gta3.d.ts" />

// wrapper over CPool class providing common interface for storing dynamically created entities (ped, vehicles, objects, etc)
function Pool(addr, entitySize) {
    this.addr = addr;
    this.entities = Memory.ReadU32(addr + 0, false);
    this.flags = Memory.ReadU32(addr + 4, false);
    this.size = Memory.ReadI32(addr + 8, false);
    this.entitySize = entitySize;
  }
  Pool.prototype = {
    getFlag: function (index) {
      return Memory.ReadU8(this.flags + index, false);
    },
    getIndex: function (struct) {
      return (struct - this.entities) / this.entitySize;
    },
    isFree: function (index) {
      return this.getFlag(index) & 0x80;
    },
    getHandle: function (struct) {
      var index = this.getIndex(struct);
      return (index << 8) + this.getFlag(index);
    },
    getEntity: function (index) {
      return this.entities + index * this.entitySize;
    },
    getEntities: function () {
      var result = [];
      for (var i = 0; i < this.size; i++) {
        if (!this.isFree(i)) {
          result.push(this.getEntity(i));
        }
      }
      return result;
    },
  };
  
  var BLIPS = 0x006ed5e0;
  var MI_POLICE = 116;
  
  function findThisEntityBlip(handle) {
    var COUNT = 32;
    var SIZE = 0x30;
    for (var i = 0; i < COUNT; i++) {
      var inUse = Memory.ReadU8(BLIPS + i * SIZE + 0x23, false);
      if (inUse) {
        var h = Memory.ReadU32(BLIPS + i * SIZE + 0x8, false);
        if (handle == h) {
          var blipIndex = Memory.ReadU16(BLIPS + i * SIZE + 0x20, false);
          ///  blipArrId | (CRadar::ms_RadarTrace[_index].m_nBlipIndex << 16);
          return i | (blipIndex << 16);
          // return blipIndex;
        }
      }
    }
  }
  
  
  if (GAME !== "gta3") {
    log("Sorry, this script is for GTA III only");
  } else {
    // create a function to get the vehicle pool address
    var GetVehiclePool = Memory.Fn.CdeclU32(0x00545300);
  
    // create a wrapper over the vehicle pool object
    var vehPool = new Pool(GetVehiclePool(), 0x5a8);
  
    while (true) {
      wait(500);
      // iterate over all created vehicles
      vehPool.getEntities().forEach(function (vehicle) {
        // create a new instance of a script vehicle
        var handle = vehPool.getHandle(vehicle);
        var v = new Car(handle);
  
        // v now can be used with script commands defined for Vehicle class
        // check that v is a police car with a driver and it has no blip yet
        if (
          !Car.IsDead(v) &&
          v.getModel() === MI_POLICE &&
          !Char.IsDead(v.getDriver()) &&
          !findThisEntityBlip(handle)
        ) {
          Blip.AddForCarOld(v, 2, 2);
        }
      });
    }
  }```

from cleo-redux.

x87 avatar x87 commented on July 20, 2024

Idea to create callbacks/hooks was briefly discussed here
#1 (reply in thread)

from cleo-redux.

x87 avatar x87 commented on July 20, 2024

WIP

addEventListener("OnVehicleCreate", ({ data }) => {
  let { address } = data;
  let handle = vehPool.getHandle(address);
  let c = new Car(handle);
  if (c.isModel(POLICE_MI)) {
    Blip.AddForCarOld(c, 2, BlipDisplay.BlipOnly);
  }
});

https://media.discordapp.net/attachments/914958450667175977/1053787400855359508/image.png

from cleo-redux.

x87 avatar x87 commented on July 20, 2024

Pools are available in scm.ts library
https://github.com/x87/scm.ts

Events are supported since 1.0.6
https://re.cleo.li/docs/en/events.html

from cleo-redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.