Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Tuners
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    2. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    3. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    4. Bugs*

    1. Grand Theft Auto Series

      1. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    6. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

      1. GTANet 20th Anniversary
    2. Support

    3. Suggestions

C++ Script Hook


aru
 Share

Recommended Posts

 

Ok, but it cant have a difference of almost 600? Even if the coords are in the front or center or back of the car. 600 is to much... Thats almost the otherside of the map(?)

 

GetCarCoordinates(closeCar, &x, &y, &x);

 

Don't feel bad, I do dumb crap like that ALL the time. lol.gif

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

I have another question, I want to save the car into a local variable, but I'm not sure how to declare the variable, I tried INT but it cannot be converted, anyone can tell me how to define the variable ?

 

 

Link to comment
Share on other sites

Type of a car is "Vehicle".

 

 

Vehicle playerVeh;                         // Define variable "playerVeh" of type Vehicleif (IsCharInAnyCar(player)) {              // Check if "player" is in any car   GetCarCharIsUsing(player, &playerVeh);  // Puts the car into "playerVeh"   //....Do something with playerVeh

 

 

And if you actually want to know if "playerVeh" is not empty and if the vehicle isn't useless at the same time, you could use this function:

 

 

bool IsVehReady(Vehicle v) {   return (v.Handle != 0 && !IsCarDead(v));}

 

Edited by L0uNGeR
Link to comment
Share on other sites

Thanks, but that's not the question smile.gif

 

I want to store the value of the care into a variable, so that this can be used in another function.

 

Such a variable would have nul or blank at start, then whenever I press a key, the value is changed to whatever car I'm using at the moment, later on, this value is used.

 

To clarify, I would like to save the value of the car, so that later on (in a hour or whatever) I can warp into the car. This was something that I really liked about the Garage mod from GAK. Now the way I see this working is that you press a key to save the car you're in at the moment you press the key, into a global variable, later on when you press another key, you would then be warped into the car.

 

But I tried to declare the variable as char, int but the compiler cannot convert the value to the variable.

Edited by sjaak327
Link to comment
Share on other sites

Meh, you could try this, if you want to visibly see the value into a log or something.

 

char buff[15];sprintf(buff, "%i", closeVeh);  // Yes this gives a warning that it is unsafe

 

Edited by L0uNGeR
Link to comment
Share on other sites

 

But I tried to declare the variable as char, int but the compiler cannot convert the value to the variable.

ALWAYS declare your variables with the type that they'll be used as. So if I wanted to store the current player's car... I would declare the variable as Car (or Vehicle in 0.2)... not char or int!

Edited by aru
Link to comment
Share on other sites

 

To clarify, I would like to save the value of the car, so that later on (in a hour or whatever) I can warp into the car. This was something that I really liked about the Garage mod from GAK. Now the way I see this working is that you press a key to save the car you're in at the moment you press the key, into a global variable, later on when you press another key, you would then be warped into the car.

 

But I tried to declare the variable as char, int but the compiler cannot convert the value to the variable.

 

Well with my Vehicle playerVeh; you can always access the playerVeh later on, I don't see why you couldn't.

 

// Save vehiclePed p = PlayerChar();Vehicle superCoolCar;if(IsCharInAnyCar(p)) {   GetCarCharIsUsing(p, &superCoolCar);}// Go backPed p = PlayerChar();if(!IsCharInAnyCar(p)) {   TaskWarpCharIntoCarAsDriver(p, superCoolCar); // Probably doesn't work, but ou get the point}

 

 

 

But I tried to declare the variable as char, int but the compiler cannot convert the value to the variable.

ALWAYS declare your variables with the type that they'll be used as. So if I wanted to store the current player's car... I would declare the variable as Car (or Vehicle in 0.2)... not char or int!

Yup, unless you WANT to write it down as something readable. tounge2.gif

Link to comment
Share on other sites

Also if you guys are using stuff like

if (v.Handle != 0) ...

I'd strongly suggest that you wrap it into a #define macro like:

 

#define IsNull(x) (x.Handle == 0)

and use it like:

if (!IsNull(v)) ... 

 

The reason I suggest this is because I do not guarantee that structure of handles will be the same in future versions of the hook. Doing it like this will make it easier for you to adapt in newer versions. In fact, I might add this IsNull macro in the next version of the hook.

Link to comment
Share on other sites

if(!IsCharInAnyCar(p)) {

TaskWarpCharIntoCarAsDriver(p, superCoolCar); // Probably doesn't work, but ou get the point

Yeah, it's not nearly that easy. wink.gif

 

Just a note to everyone here, the scripting itself from III to IV hasn't really fundamentally changed all that much. Sure, it's been enhanced and added on to, but the rules of scripting are the mostly the same as they always have been. So if you're not getting something, head over to mission coding and have a look at the coding bibles and examples. Consider opcodes (old) and natives (new) to be interchangeable.

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

@aru: Alright, will do...

Glad I made my own IsVehReady() and IsPedReady(), so even now it's easy to change.

 

BTW, I have made my own class, where would I instantiate this class to be able to use the Wait() command?

At the moment my Class is instantiated at

 

class CustomFiberThread :  public NativeFiberThread {   private:     //here

 

I have no idea if this is good or bad, but it it works tounge2.gif

It's just that I can't use the Wait() command.

Edited by L0uNGeR
Link to comment
Share on other sites

 

Well with my  Vehicle playerVeh;  you can always access the  playerVeh  later on, I don't see why you couldn't.

 

// Save vehiclePed p = PlayerChar();Vehicle superCoolCar;if(IsCharInAnyCar(p)) {   GetCarCharIsUsing(p, &superCoolCar);}// Go backPed p = PlayerChar();if(!IsCharInAnyCar(p)) {   TaskWarpCharIntoCarAsDriver(p, superCoolCar); // Probably doesn't work, but ou get the point}

 

 

 

I tried this, but it won't compile.

 

I want to save the value of the car using k+num 1:

 

First I would declare the variable Saved_Car in the header and again at the top like:

Saved_Car=0

 

Then:

 

 

else if ((GetAsyncKeyState(VK_K)&&(GetAsyncKeyState(VK_NUMPAD1) & 0x8000) != 0)) 	{ 	Char c; 	Car car;   	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	if (IsCharSittingInAnyCar© == 1) 	{ 	GetCarCharIsUsing(c, &car);               Saved_Car=car               }               else 	{ 	DisplayTextWithLiteralString(0.5f, 0.25f, "STRING", "Not in Car"); 	}

 

 

 

I thought that using a variable Saved_Car=0, then store the value I get from getcarcharisusing. and then do the following:

 

 

 

else if ((GetAsyncKeyState(VK_K)&&(GetAsyncKeyState(VK_NUMPAD2) & 0x8000) != 0)) 	{ 	Char c; 	 	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	if (Saved_Car>0) 	{  	 	WarpCharIntoCarAsDriver(c, Saved_Car); 	} 	else 	{ 	DisplayTextWithLiteralString(0.5f, 0.25f, "STRING", "No Saved Car"); 	} 	}

 

 

Maybe I'm missing something here ?

Edited by sjaak327
Link to comment
Share on other sites

@L0uNGeR... if you inherit from NativeFiberThread, Wait(...) should be available. It shouldn't matter if you're calling it from a private/protected/public function (see SampleCustomFiber... it uses Wait in both a protected as well as a private function). The only thing you need to know when converting to NativeFiberThread from NativeThread is that the run function is now called RunScript()... not RunTick() anymore. What do you mean by instantiated?

 

@sjaak327, I hope you declared Saved_Car like this:

 

 

Car Saved_Car;

 

Link to comment
Share on other sites

 

I tried this, but it won't compile.

That's right, you don't have the PlayerChar() function.

 

 

Now, I cannot use Car later on, as it will be an undeclared variable.

You're right again.

 

Like we were just discussing here, you cannot do (Saved_Car > 0), you should do (Saved_Car.Handle != 0)

 

 

 

@L0uNGeR... if you inherit from NativeFiberThread, Wait(...) should be available. It shouldn't matter if you're calling it from a private/protected/public function (see SampleCustomFiber... it uses Wait in both a protected as well as a private function). The only thing you need to know when converting to NativeFiberThread from NativeThread is that the run function is now called RunScript()... not RunTick() anymore.

Ya I knew about RunScript(), but I only use it for keystates at the moment, everything that I do to the game is in it's own CPP with it's own H.

Yet, when I call Wait() from my own function, I get a nice "identifier not found".

 

 

What do you mean by instantiated?

As in, creating an instance?

 

A class is used to create new instances (objects) by instantiating the class.

tounge2.gif

Edited by L0uNGeR
Link to comment
Share on other sites

Got another question btw, would there be any difference in choosing f32 or float in my scripts?

In terms of precaution for future changes.

 

Or is this a safety measure so we can't trow doubles at native functions?

Edited by L0uNGeR
Link to comment
Share on other sites

 

everything that I do to the game is in it's own CPP with it's own H.

Yes, when I call Wait() from my own function, I get a nice "identifier not found".

aha... Wait(...) is a protected function inside NativeFiberThread... the real Wait native has been commented out since it won't work with the C++ threads. So you'll have to find a way to call the Wait function inside NativeFiberThread from your custom class. Maybe pass an instance to the custom class like this...

 

First change Wait(...) to public in NativeFiberThread.h

 

CustomFiberThread.h:

 

class CustomFiberThread :   public NativeFiberThread{  private:     MyCustomClass m_Custom;     ...  public:     CustomFiberThread();     ...}

 

 

CustomFiberThread.cpp:

 

CustomFiberThread::CustomFiberThread()  : m_Custom(this){  ...}

 

 

MyCustomClass.h:

 

class NativeFiberThread;class MyCustomClass{  private:     NativeFiberThread *m_pThread;     ...  public:     MyCustomClass(NativeFiberThread * thread);     DoStuff();}

 

 

MyCustoomClass.cpp

 

#include "../ScriptHook/NativeFiberThread.h"MyCustomClass::MyCustomClass(NativeFiberThread * thread){  m_pThread = thread;}MyCustomClass::DoStuff(){  m_pThread->Wait(100);}

 

 

 

Got another question btw, would there be any difference in choosing f32 or float in my scripts?

In terms of precaution for future changes.

 

No, theres no difference and probably wouldn't change... You can use float instead of f32. The only reason I use typedefs instead of using the real types is for ease of changing when targeting different platforms...

Edited by aru
Link to comment
Share on other sites

Thanks, seems like a lot of work colgate.gif

I know that the real Wait() native was disabled, so I already tried to call the NativeFiberThread into my own class but failed epically.

 

 

No, theres no difference and probably wouldn't change... You can use float instead of f32. The only reason I use typedefs instead of using the real types is for ease of changing when targeting different platforms...

Aha, seems logical.

 

 

m_bKillRequested = true;  // suicide!

LoL biggrin.gif

Link to comment
Share on other sites

 

Like we were just discussing here, you cannot do  (Saved_Car > 0), you should do (Saved_Car.Handle != 0)

 

 

 

 

Right, Now I tried that as follows:

 

 

else if ((GetAsyncKeyState(VK_K)&&(GetAsyncKeyState(VK_NUMPAD1) & 0x8000) != 0)) 	{ 	Char c; 	Car Saved_Car; 	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	if (IsCharSittingInAnyCar© == 1) 	{ 	GetCarCharIsUsing(c, &Saved_Car); 	DisplayTextWithLiteralString(0.5f, 0.25f, "STRING", "Car Saved");         	} 	else 	{ 	DisplayTextWithLiteralString(0.5f, 0.25f, "STRING", "Not in Car"); 	}

 

 

to save the car to Saved_Car.

 

Then:

 

 

else if ((GetAsyncKeyState(VK_K)&&(GetAsyncKeyState(VK_NUMPAD2) & 0x8000) != 0)) 	{ 	Char c; 	Car Saved_Car; 	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	if (Saved_Car.Handle != 0) 	{  	 	 	WarpCharIntoCarAsDriver(c, Saved_Car); 	} 	else 	{ 	DisplayTextWithLiteralString(0.5f, 0.25f, "STRING", "No Saved Car"); 	} 	}

 

 

If I press K+NUM 1 when not in a car, I will get the not in car message, so far it's great. I go into the car, and again press K+ num 1, and I get the car saved message, again great.

 

Now I get out of the car and press K+numpad 2, but no warping is happening, also if I press K+numpad 2 without first saving a car, I would expect to get the no saved car message, but it doesn't appear, maybe I cannot use the Saved_Car.handle !=0 ?

 

What does it signify ?

Link to comment
Share on other sites

Car Saved_Car;

You initialize the variable again.

 

 

@aru

 

 

CustomFiberThread::CustomFiberThread()   : LouNGeR(this){   SetName("CustomFiberThread");}

 

Yes, I actually called my class like LouNGeRClass LouNGeR; in "CustomFiberThread.h" tounge2.gif.

It tells me "warning C4355: 'this' : used in base member initializer list"

Anything I should worry about?

Edited by L0uNGeR
Link to comment
Share on other sites

Car Saved_Car;

 

You initialize the variable again.

That;s why I wanted to use a global variable defined in the header.

 

 

Link to comment
Share on other sites

 

Car Saved_Car;

 

You initialize the variable again.

That;s why I wanted to use a global variable defined in the header.

I meant to say that you would overwrite the var in any case.

But yes, you need a global, try this:

 

CustomFiberThread.h

 

class CustomFiberThread :    public NativeFiberThread{private:   ...protected:   ...public:   CustomFiberThread();   Car Saved_Car;};

 

 

CustomFiberThread.cpp

 

while(IsThreadAlive()) {  ...  GetCarCharIsUsing(c, &this->Saved_Car);  ....}

 

 

For the older Script Hook it's nearly the same.

Edited by L0uNGeR
Link to comment
Share on other sites

Won't work, as it doesn't accept Car as type specifier, it will only accept, int, char float and some others.

 

 

Link to comment
Share on other sites

It tells me "warning C4355: 'this' : used in base member initializer list"

Anything I should worry about?

Ideally you shouldn't be doing that, but you're just storing the value, not calling any functions from it in the constructor, so its fine and you can just ignore the warning.

 

If you want to be proper about it... instead of passing NativeFiberThread into the constructor, create a function to do store it... maybe like...

 

 

void LouNGeR::SetThread(NativeFiberThread *thread){  m_pThread = thread;}

 

 

Then call that function from CustomFiberThread's constructor.

Link to comment
Share on other sites

the real Wait native has been commented out since it won't work with the C++ threads.

Anything particular on why this is? Seems like a lot of trouble (on R*'s part I mean) to make a Wait so difficult to work out.

 

Also, any plans on a future version having something like you posted already implemented so anyone could just type Wait(Value)?

 

Thanks, and keep up the great work! smile.gif

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

@sjaak327: Add in the H:

 

using namespace Scripting;

 

 

@aru

I think it works now, without warning tounge.gif

 

(I know, I must think of some better names, but things like m_pThread just don't suite me tounge2.gif)

CustomFiberThread.h

 

class CustomFiberThread :    public NativeFiberThread {       private:           LouNGeRClass LouNGeR;           ...

 

CustomFiberThread.cpp

 

 

CustomFiberThread::CustomFiberThread() {   SetName("CustomFiberThread");   LouNGeR.SetThread(this);}

 

LouNGeRCrap.h

 

class NativeFiberThread;class LouNGeRClass {   private:       NativeFiberThread *m_pThread;   public:       void SetThread(NativeFiberThread *thread);

 

LouNGeRCrap.cpp

 

void LouNGeRClass::SetThread(NativeFiberThread *thread) {   m_pThread = thread;}

 

 

m_pThread->Wait(200);

 

Sounds about right?

Edited by L0uNGeR
Link to comment
Share on other sites

@sjaak327: Add in the H:

 

using namespace Scripting;

 

 

 

Great ! That did the trick, now it is working properly, Thanks very much !

 

 

Link to comment
Share on other sites

 

the real Wait native has been commented out since it won't work with the C++ threads.

Anything particular on why this is? Seems like a lot of trouble (on R*'s part I mean) to make a Wait so difficult to work out.

 

Also, any plans on a future version having something like you posted already implemented so anyone could just type Wait(Value)?

 

Thanks, and keep up the great work! smile.gif

Well, its not R*'s fault.. its just the way NativeFiberThread works... it requires a context switch to the game fiber from the script fiber inside Wait. I suppose you could implement a global Wait like this. I haven't tested this... but if it works, I guess I could include it with the next version.

 

 

void Wait(u32 timeMS){  GameTypes::scrThread *thread = Game::GetInstance()->Script_GetActiveThread();  NativeFiberThread *fiberThread = dynamic_cast< NativeFiberThread * >(thread);  if (fiberThread != NULL)  {     fiberThread->Wait(timeMS);  }}

 

 

It would still need NativeFiberThread::Wait(...) to be made public

 

 

@L0uNGeR... yes, sounds about right smile.gif

Edited by aru
Link to comment
Share on other sites

Well for me it seems to be working, damn you're good at this man wow.gif.

Are you making any mods yourself, or just the tools to mod?

I know, sometimes I have this feeling that building a mod is more fun than actually using it.

 

 

Edited by L0uNGeR
Link to comment
Share on other sites

Well, my intentions on starting this was to create custom mission mods... it was either this, or create a .sco compiler... this seemed easier than writing a compiler smile.gif And yeah, sometimes its more fun to create mods than to use them smile.gif

Link to comment
Share on other sites

@Sjakie (sry I had to)

No problem, glad it works now.

BTW, GTASA always removed your vehicle when you went away from it, does IV always keep it at that spot where you left it?

 

 

@aru

Hmm, a SCO compiler, isn't this C++ Hook much more useful than that?

Link to comment
Share on other sites

Create an account or sign in to comment

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

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
 Share

  • 2 Users Currently Viewing
    1 member, 0 Anonymous, 1 Guest

    • DDPUPS
×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.