Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fx.DrawCorona bug #98

Closed
strejda603 opened this issue Aug 10, 2023 · 4 comments
Closed

Fx.DrawCorona bug #98

strejda603 opened this issue Aug 10, 2023 · 4 comments
Labels
type:bug Something isn't working

Comments

@strejda603
Copy link

Hello guys,

I'm using Cleo Redux for my GTA Vice City (Classic) with Ultra Mod installed, and I'm trying to create some mods with it...

I've encountered some problems with "Fx.DrawCorona" command: No matter how many coronas I create, it shows only one of them.. Does anyone have an idea, how to fix it?

Here's an example of my code:

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

import { KeyCode, ScriptSound, WaitState } from "./.config/enums";

if (HOST !== "vc" && HOST !== "reVC") {
  exit("Sorry, this script is for GTA VC only");
}

let player = new Player(0);
let playerChar = player.getChar();

const marinaDisco = {
    entryPos1: {
      x: -168.4236,
      y: -1284.7824,
      z: 10.423,
      r: 1.0,
    },
    entryPos2: {
      x: -159.935,
      y: -1283.3222,
      z: 10.423,
      r: 1.0,
    },
    entryPos3: {
      x: -169.9683,
      y: -1293.6324,
      z: 10.423,
      r: 1.0,
    },
    insidePos: {
      x: -118.543,
      y: -1311.32,
      z: -7.2693,
      a: 91.0,
    },
    exitPos1: {
      x: -116.854,
      y: -1309.5432,
      z: -7.2,
      r: 1.0,
    },
    exitPos2: {
      x: -116.854,
      y: -1313.4788,
      z: -7.2,
      r: 1.0,
    },
    outsidePos: {
      x: -171.443,
      y: -1284.22,
      z: 9.4307,
      a: 43.0,
    },
    barmaidPos: { x: -144.5299, y: -1311.16, z: -7.1, a: 271.0 },
    guardPos: { x: -142.8835, y: -1310.8981, z: -7.1, a: 90.0 },
    ped1Pos: { x: -133.5422, y: -1311.8502, z: -7.2, a: 140.0 },
    ped2Pos: { x: -129.123, y: -1311.845, z: -7.2, a: 40.0 },
    ped3Pos: { x: -131.541, y: -1309.5947, z: -7.2, a: 232.0 },
    ped4Pos: { x: -127.7548, y: -1309.8126, z: -7.2, a: 89.0 },
    ped5Pos: { x: -127.5602, y: -1305.7991, z: -7.2, a: 180.0 },
    ped6Pos: { x: -132.3991, y: -1304.9693, z: -7.2, a: 225.0 },
    ped7Pos: { x: -129.6877, y: -1301.1688, z: -7.2, a: 172.0 },
    ped8Pos: { x: -134.475, y: -1307.6766, z: -7.2, a: 264.0 },
    ped9Pos: { x: -132.9195, y: -1302.21989, z: -7.1, a: 311.0 },
    ped10Pos: { x: -135.5324, y: -1314.6976, z: -7.2, a: 334.0 },
    ped11Pos: { x: -126.4633, y: -1313.8886, z: -7.1, a: 2.0 },
    ped12Pos: { x: -131.4392, y: -1313.811, z: -7.1, a: 249.0 },
    ped13Pos: { x: -126.8095, y: -1303.7259, z: -7.1, a: 127.0 },
};

// Marina Disco
    if (
      atFeet(player, interiors.marinaDisco.entryPos1) ||
      atFeet(player, interiors.marinaDisco.entryPos2) ||
      atFeet(player, interiors.marinaDisco.entryPos3)
    ) {
      fade(0, 500);
      loadAnim("STRIP");

      loadModel(55);
      loadModel(53);
      loadModel(51);
      loadModel(35);
      loadModel(30);
      loadModel(24);
      loadModel(15);
      loadModel(14);
      loadModel(11);
      loadModel(70);
      loadModel(13);
      loadModel(16);
      loadModel(73);
      wait(50);
      Streaming.LoadAllModelsNow();

      // prettier-ignore
      let barmaid = spawnPed(70, 7, interiors.marinaDisco.barmaidPos)
        .setHealth(200);
      // prettier-ignore
      let guard = spawnPed(73, 7, interiors.marinaDisco.guardPos)
        .setHealth(200);
      // prettier-ignore
      let ped1 = spawnPed(53, 4, interiors.marinaDisco.ped1Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped2 = spawnPed(51, 4, interiors.marinaDisco.ped2Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped3 = spawnPed(35, 4, interiors.marinaDisco.ped3Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped4 = spawnPed(30, 4, interiors.marinaDisco.ped4Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped5 = spawnPed(24, 4, interiors.marinaDisco.ped5Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped6 = spawnPed(15, 4, interiors.marinaDisco.ped6Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped7 = spawnPed(14, 4, interiors.marinaDisco.ped7Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped8 = spawnPed(11, 4, interiors.marinaDisco.ped8Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped9 = spawnPed(16, 4, interiors.marinaDisco.ped9Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped10 = spawnPed(13, 4, interiors.marinaDisco.ped10Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped11 = spawnPed(53, 4, interiors.marinaDisco.ped11Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped12 = spawnPed(55, 4, interiors.marinaDisco.ped12Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      // prettier-ignore
      let ped13 = spawnPed(14, 4, interiors.marinaDisco.ped13Pos)
        .setWaitState(WaitState.Stripper, 60000000);
      wait(200);

      let raiding = 0;
      let time = 0;
      Streaming.SetAreaVisible(17);
      // Game.SetIsInStadium(true);
      Weather.ForceNow(0);
      World.SwitchRubbish(false);
      movePlayer(player, interiors.marinaDisco.insidePos);
      fade(1, 500);

      while (true) {
        wait(0);
        time++;
        /* THIS WORKS FINE */
        // prettier-ignore
        Fx.CreateSingleParticle(27, -140.136, -1309.0, 0.3419, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(27, -140.136, -1314.2, 0.3419, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(27, -140.136, -1306.3, 0.3419, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(27, -140.136, -1304.0, 0.3419, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(27, -140.136, -1311.8, 0.3419, 0.0, 0.0, 0.0, 1.0);

        // prettier-ignore
        Fx.CreateSingleParticle(20, -120.736, -1319.2, -8.7581, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(20, -120.736, -1295.8, -8.7581, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(20, -137.836, -1295.8, -8.7581, 0.0, 0.0, 0.0, 1.0);
        // prettier-ignore
        Fx.CreateSingleParticle(20, -139.336, -1319.1, -8.7581, 0.0, 0.0, 0.0, 1.0);

        /* IN THIS SECTION ONLY ONE OF CORONAS IS SHOWN */
        if (time > 1000) {
          Fx.DrawCorona(-137.536, -1319.9, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-122.836, -1319.9, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-120.136, -1318.3, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-120.136, -1303.6, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-122.836, -1295.5, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-136.936, -1295.5, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-139.436, -1302.1, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-139.436, -1316.9, -3.1581, 1.0, 4, 1, 0, 0, 255);
        }
        if (time > 2000) {
          Fx.DrawCorona(-137.536, -1319.9, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-122.836, -1319.9, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-120.136, -1318.3, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-120.136, -1303.6, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-122.836, -1295.5, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-136.936, -1295.5, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-139.436, -1302.1, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-139.436, -1316.9, -3.1581, 1.0, 4, 1, 255, 0, 0);
        }
        if (time > 3000) {
          Fx.DrawCorona(-137.536, -1319.9, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-122.836, -1319.9, -3.1581, 1.0, 4, 1, 0, 255, 0);
          Fx.DrawCorona(-120.136, -1318.3, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-120.136, -1303.6, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-122.836, -1295.5, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-136.936, -1295.5, -3.1581, 1.0, 4, 1, 255, 0, 0);
          Fx.DrawCorona(-139.436, -1302.1, -3.1581, 1.0, 4, 1, 0, 0, 255);
          Fx.DrawCorona(-139.436, -1316.9, -3.1581, 1.0, 4, 1, 0, 255, 0);
        }
        if (time > 4000) {
          Fx.DrawCorona(-137.536, -1319.9, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-122.836, -1319.9, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-120.136, -1318.3, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-120.136, -1303.6, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-122.836, -1295.5, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-136.936, -1295.5, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-139.436, -1302.1, -3.1581, 1.0, 4, 1, 255, 255, 255);
          Fx.DrawCorona(-139.436, -1316.9, -3.1581, 1.0, 4, 1, 255, 255, 255);
        }
        if (time > 5000) {
          time = 0;
        }

        if (player.isShooting() && raiding == 0) {
          loadModel(279);
          loadModel(275);
          wait(50);
          Streaming.LoadAllModelsNow();

          if (!Char.IsDead(barmaid)) {
            barmaid
              .giveWeapon(21, 30)
              .setAccuracy(80)
              .setObjKillPlayerAnyMeans(player);
          }
          if (!Char.IsDead(guard)) {
            guard
              .giveWeapon(18, 30)
              .setAccuracy(80)
              .setObjKillPlayerAnyMeans(player);
          }

          ped1.clearWaitState();
          ped2.clearWaitState();
          ped3.clearWaitState();
          ped4.clearWaitState();
          ped5.clearWaitState();
          ped6.clearWaitState();
          ped7.clearWaitState();
          ped8.clearWaitState();
          ped9.clearWaitState();
          ped10.clearWaitState();
          ped11.clearWaitState();
          ped12.clearWaitState();
          ped13.clearWaitState();

          if (player.storeWantedLevel() < 3) {
            player.alterWantedLevel(3);
          }

          Streaming.MarkModelAsNoLongerNeeded(279);
          Streaming.MarkModelAsNoLongerNeeded(275);
          raiding = 1;
        }

        if (
          atFeet(player, interiors.marinaDisco.exitPos1) ||
          atFeet(player, interiors.marinaDisco.exitPos2) ||
          !player.isPlaying()
        ) {
          fade(0, 500);

          barmaid.markAsNoLongerNeeded().delete();
          guard.markAsNoLongerNeeded().delete();
          ped1.markAsNoLongerNeeded().delete();
          ped2.markAsNoLongerNeeded().delete();
          ped3.markAsNoLongerNeeded().delete();
          ped4.markAsNoLongerNeeded().delete();
          ped5.markAsNoLongerNeeded().delete();
          ped6.markAsNoLongerNeeded().delete();
          ped7.markAsNoLongerNeeded().delete();
          ped8.markAsNoLongerNeeded().delete();
          ped9.markAsNoLongerNeeded().delete();
          ped10.markAsNoLongerNeeded().delete();
          ped11.markAsNoLongerNeeded().delete();
          ped12.markAsNoLongerNeeded().delete();
          ped13.markAsNoLongerNeeded().delete();

          Streaming.SetAreaVisible(0);
          // Game.SetIsInStadium(false);
          Weather.Release();
          World.SwitchRubbish(true);
          // World.ClearExtraColors(true);
          movePlayer(player, interiors.marinaDisco.outsidePos);
          fade(1, 500);

          continue main;
        }
      }
    }

// Functions
/**
 * @param {{x: float, y: float, z: float}} pos
 * @param {string} spec solid/car/char/object/particle
 */
function areaOccupied(pos, spec) {
  if (spec === "solid") {
    return World.IsAreaOccupied(
      pos.x - 2.0,
      pos.y - 2.0,
      pos.z - 2.0,
      pos.x + 2.0,
      pos.y + 2.0,
      pos.z + 2.0,
      true,
      false,
      false,
      false,
      false
    );
  } else if (spec === "car") {
    return World.IsAreaOccupied(
      pos.x - 2.0,
      pos.y - 2.0,
      pos.z - 2.0,
      pos.x + 2.0,
      pos.y + 2.0,
      pos.z + 2.0,
      false,
      true,
      false,
      false,
      false
    );
  } else if (spec === "char") {
    return World.IsAreaOccupied(
      pos.x - 2.0,
      pos.y - 2.0,
      pos.z - 2.0,
      pos.x + 2.0,
      pos.y + 2.0,
      pos.z + 2.0,
      false,
      false,
      true,
      false,
      false
    );
  } else if (spec === "object") {
    return World.IsAreaOccupied(
      pos.x - 2.0,
      pos.y - 2.0,
      pos.z - 2.0,
      pos.x + 2.0,
      pos.y + 2.0,
      pos.z + 2.0,
      false,
      false,
      false,
      true,
      false
    );
  } else if (type === "particle") {
    return World.IsAreaOccupied(
      pos.x - 2.0,
      pos.y - 2.0,
      pos.z - 2.0,
      pos.x + 2.0,
      pos.y + 2.0,
      pos.z + 2.0,
      false,
      false,
      false,
      false,
      true
    );
  } else {
    return false;
  }
}

/**
 * @param {(number|string)} id
 * @param {boolean} [special=false]
 * @param {int} [slot=null]
 */
export function loadModel(id, special = false, slot = null) {
  if (typeof id === "string" && special == true && slot != null) {
    Streaming.LoadSpecialCharacter(slot, id);

    while (!Streaming.HasSpecialCharacterLoaded(slot)) {
      wait(100);
    }
  } else {
    Streaming.RequestModel(id);

    while (!Streaming.HasModelLoaded(id)) {
      wait(100);
    }
  }
}

/**
 * @param {string} name
 */
function loadAnim(name) {
  Streaming.RequestAnimation(name);

  while (!Streaming.HasAnimationLoaded(name)) {
    wait(100);
  }
}

/**
 * @param {int} inout 0 - out, 1 - in
 * @param {int} time in ms
 */
function fade(inout, time) {
  if (inout == 0) {
    // Game.SetPoliceIgnorePlayer(player, true);
    // Game.SetEveryoneIgnorePlayer(player, true);
    player.setControl(false);
    Camera.DoFade(time, 0);
    wait(time);
  } else if (inout == 1) {
    Camera.DoFade(time, 1);
    wait(time);
    player.setControl(true);
    // Game.SetPoliceIgnorePlayer(player, false);
    // Game.SetEveryoneIgnorePlayer(player, false);
  }
}

/**
 * @param {Player} player
 * @param {{x: float, y: float, z: float, r: {x: float, y: float, z: float} | float}} pos
 */
function atFeet(player, pos) {
  if (isObject(pos.r)) {
    return player.locateOnFoot3D(
      pos.x,
      pos.y,
      pos.z,
      pos.r.x,
      pos.r.y,
      pos.r.z,
      false
    );
  } else {
    return player.locateOnFoot3D(
      pos.x,
      pos.y,
      pos.z,
      pos.r,
      pos.r,
      pos.r,
      false
    );
  }
}

/**
 * @param {Player} player
 * @param {{x: float, y: float, z: float, a?: float}} pos
 */
function movePlayer(player, pos) {
  let ground = World.GetGroundZFor3DCoord(pos.x, pos.y, pos.z);

  player.setCoordinates(pos.x, pos.y, ground);
  if (pos.hasOwnProperty("a")) {
    player.setHeading(pos.a);
  }
  Camera.SetBehindPlayer();
  Camera.RestoreJumpcut();
}

/**
 * @param {int} id Needs to be loaded first via "loadModel"! / "Streaming.MarkModelAsNoLongerNeeded" not needed
 * @param {int} type
 * @param {{x: float, y: float, z: float, a?: float}} pos
 */
function spawnPed(id, type, pos) {
  let ped;
  // loadModel(id);

  if (areaOccupied(pos, "char")) {
    World.ClearAreaOfChars(
      pos.x - 0.5,
      pos.y - 0.5,
      pos.z - 0.5,
      pos.x + 0.5,
      pos.y + 0.5,
      pos.z + 0.5
    );
  }

  let ground = World.GetGroundZFor3DCoord(pos.x, pos.y, pos.z);

  ped = Char.Create(type, id, pos.x, pos.y, ground);
  if (pos.hasOwnProperty("a")) {
    ped.setHeading(pos.a);
  }

  Streaming.MarkModelAsNoLongerNeeded(id);

  return ped;
}
@x87
Copy link
Contributor

x87 commented Aug 11, 2023

Thank you for reporting this issue. I know where the problem is, but unfortunately a fix is not trivial. I will be looking into it as my time permits.

@x87 x87 added the type:bug Something isn't working label Aug 11, 2023
@x87
Copy link
Contributor

x87 commented Aug 13, 2023

I think I found a way to fix this.

Can you test your script again with this build?

@strejda603
Copy link
Author

I think I found a way to fix this.

Can you test your script again with this build?

Thank you, this build works great!

@x87
Copy link
Contributor

x87 commented Aug 13, 2023

Fixed in 1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants