Quantcast

Jump to content

» «
Photo

unstable script

6 replies to this topic
nordi
  • nordi

    Square Civilian

  • Members
  • Joined: 17 Mar 2014
  • France

#1

Posted 24 August 2014 - 01:46 PM Edited by nordi, 24 August 2014 - 04:23 PM.

Hey

 

I'm trying to spawn an ambulance, with 2 paramedic inside when I press numpad 1. But for some reason, sometimes it works just fine, but most of the time, it just crash ! (crash to desktop, without any error message) ... Any idea what i'm doing wrong ?

 

thanks.


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#2

Posted 24 August 2014 - 03:07 PM Edited by LetsPlayOrDy, 24 August 2014 - 03:08 PM.

Ok, 1. You are making infinite loops. This is not good practice, because if for some reason the car/peds didn't spawn, your GTA IV would freeze. Instead of

while (!Game.Exists(ambulance))
                {
                    Wait(5);
                }

use

for (int i = 0; i < 600; i++)
                {
                    if (!Game.Exists(ambulance)) break;
                    Wait(5);
                } //will wait for 3 seconds (600 x 5 = 3000)

2. Try and single out the problem. Comment out bits of code (like everything except for the spawn ambulance code), then try the code. If it crashes, then it is the part that you didn't comment. If it doesn't crash, then un-comment the next part (like the spawn ped part) and then comment the last part.

  • nordi likes this

nordi
  • nordi

    Square Civilian

  • Members
  • Joined: 17 Mar 2014
  • France

#3

Posted 24 August 2014 - 04:25 PM Edited by nordi, 24 August 2014 - 04:26 PM.

Ok, 1. You are making infinite loops. This is not good practice, because if for some reason the car/peds didn't spawn, your GTA IV would freeze. Instead of

while (!Game.Exists(ambulance))
                {
                    Wait(5);
                }

use

for (int i = 0; i < 600; i++)
                {
                    if (!Game.Exists(ambulance)) break;
                    Wait(5);
                } //will wait for 3 seconds (600 x 5 = 3000)

2. Try and single out the problem. Comment out bits of code (like everything except for the spawn ambulance code), then try the code. If it crashes, then it is the part that you didn't comment. If it doesn't crash, then un-comment the next part (like the spawn ped part) and then comment the last part.

 

Thanks for the tips about the loop.

I managed to get it to work: As stated, it was randomly working: sometimes it worked perfectly, but sometimes it crashed. So I figured i would use a different way to get it done: I spawn the ped using world.createped, and then i WarpIntoVehicle the ped: works like a charm !


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#4

Posted 24 August 2014 - 04:27 PM

Glad you got it to work! I thought that may be the problem, but I didn't say anything because I wasn't 100% sure.


leftas
  • leftas

    unknown

  • Members
  • Joined: 13 Jun 2013
  • Lithuania

#5

Posted 24 August 2014 - 07:19 PM Edited by leftas, 24 August 2014 - 07:21 PM.

Nordi,
It would be better to use CreatePedOnSeat as this creates peds on seat with car model spec. Peds like police car will spawn with police peds and etc. You may used that function, as you deleted code(not good thing) I don't know if you used or not, now.

Best regards,
Paul.

please_man2001
  • please_man2001

    Crying

  • BUSTED!
  • Joined: 24 Aug 2014
  • None

#6

Posted 25 August 2014 - 06:07 PM

SA Syntax

// No Opcodes
$Actor_Sweet = Actor.CreateasDriver(SPECIAL,#WMYST,$Car_Greenwood)

hope this helped

c# syntax would be similar


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#7

Posted 25 August 2014 - 06:11 PM

SA Syntax

// No Opcodes
$Actor_Sweet = Actor.CreateasDriver(SPECIAL,#WMYST,$Car_Greenwood)

hope this helped

c# syntax would be similar

This is the IV forum, not SA. This code would not help out unless this was about SA





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users