Quantcast
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. Red Dead Redemption 2

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

    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. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    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

Is there some way to check if a vehicle exists(not model)? I'm asking this, because of my Car Spawner. I added the DLC bikes to the spawn list, but if someone without the DLC mod spawns any of them, it crashes.

 

I *think* checking for the models won't help, because HasModelLoaded returns true, since the model files are there, but not in the default.ide.

I was thinking if there was a way to apply another one of the existing bikes handling to them instead of using the .ide as it causes other problems in the game if you add the vehicle.ide or any of the .ide files to be exact. You end up with random map object spawning and sometimes crashes in worst cases.

Link to comment
Share on other sites

having trouble to get DisplayTextWithLiteralString to display dynamic information.

Such as u32and f32 values.

I was trying to format a string and convert it to a char but not much luck.

Has someone found a way?

Link to comment
Share on other sites

someone want to explain to me on how to Spawn a Vehicle and change your character, I'd like to play as Roman rolleyes.gif

? Example code for spawning a vehicle and changing character are included with the source.

Link to comment
Share on other sites

How would I do this in C++?

 

function BeepOn()   PushInt(3)   CallNative("PREVIEW_RINGTONE")   Wait(1300)   CallNative("STOP_PREVIEW_RINGTONE")end

 

Thanks

 

 

 

someone want to explain to me on how to Spawn a Vehicle and change your character, I'd like to play as Roman rolleyes.gif

? Example code for spawning a vehicle and changing character are included with the source.

Doesn't explain

 

...Unnecessary long code...

 

Yes it does

 

   m_SkinModel = MODEL_IG_JOHNNYBIKER;  RequestModel(m_SkinModel);  // Change our state so that we can change skin when available  m_State = StateChangeSkin;......................case StateChangeSkin: // Change the player skin when its available{ if (HasModelLoaded(m_SkinModel)) {  OutputDebugString(L"Skin model available... spawning it!\n");  u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId());  ChangePlayerModel(playerIndex, m_SkinModel);...........

 

 

That is for player model.

Edited by L0uNGeR
Link to comment
Share on other sites

 

How would I do this in C++?

 

function BeepOn()   PushInt(3)   CallNative("PREVIEW_RINGTONE")   Wait(1300)   CallNative("STOP_PREVIEW_RINGTONE")end

 

Thanks

 

 

Ok this is out of my head, check it first!

 

Add these to your Scripting.h

 

 

static void PreviewRingtone(u32 tone) { NativeInvoke::Invoke<scriptVoid>("PREVIEW_RINGTONE", tone);}static void StopPreviewRingtone() { NativeInvoke::Invoke<scriptVoid>("PREVIEW_RINGTONE");}

 

 

Then you can use then in your code.

 

PreviewRingTone(3);Sleep(1500) // C++ wait command if im correct (google it). Although Sleeps in Tick isnt coolStopPreviewRingtone();

 

Edited by Intosia
Link to comment
Share on other sites

Yah I know how to put the natives in my code, but

 

Although Sleeps in Tick isnt cool

That's the problem.

Link to comment
Share on other sites

 

Yah I know how to put the natives in my code, but

 

Although Sleeps in Tick isnt cool

That's the problem.

Use a timer... something like:

 

 

switch( m_State ){  case StateDefault:     if (someCheck)     {        PreviewRingTone(3);        SetTimerA(0);        m_State = StateBeep;     }     break;  case StateBeep:     if (TimerA() > 1500)     {        StopPreviewRingtone();        m_State = StateDefault;     }     break;  }

 

 

Maybe I'll get around to implementing a context switching solution for working with Wait(...) etc.

Edited by aru
Link to comment
Share on other sites

Ah thnx for the reply aru.

I have nearly put everything I had in LUA into C++ now.

All but the things that require Wait(), since it's kinda tricky.

 

I don't dream in C++ yet, but I did create my own files and a class.

But when it comes to certain things, I must go back to the RunTick() and do stuff like this:

 

       if(TimerA() > 720 || TimerB() > 1300)  // TimerA() = LouNGeRCrap::BeepOff()              StopPreviewRingtone();         // TimerB() = LouNGeRCrap::BeepOn()

 

 

How would I do stuff that needs a lot of waits, like this:

 

// Gently upApplyForceToPed(c, 1, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 7, 1, 1, 1)Wait(100)ApplyForceToPed(c, 1, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 7, 1, 1, 1)Wait(100)ApplyForceToPed(c, 1, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 7, 1, 1, 1)Wait(100)ApplyForceToPed(c, 1, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 7, 1, 1, 1)Wait(100)ApplyForceToPed(c, 1, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 7, 1, 1, 1)// Wait a bitWait(700)// Smash downApplyForceToPed(c, 1, 0.0, 0.0, -20.0, 0.0, 0.0, 0.0, 7, 1, 1, 1)

 

 

(yes this code does what you see in the YT video)

Edited by L0uNGeR
Link to comment
Share on other sites

I also have all my stuff from Lua (alice) into this hook. It still has to crash, which is pretty impressive, alice sometimes crashed on me (and always the first time when launching GTAIV).

 

 

All my stuff except for one smile.gif

 

I would like to write the char's coordinates on keypress to a file, I know how to get them, but I'm not sure how to output them.

 

I googled, and found a piece of code that would write something to a file, which indeed works.

 

 

ofstream myfile;  myfile.open ("Coords.txt");  myfile << "Writing this to a file.\n";  myfile.close();

 

 

Now, the question would be, how to write the float values from this into this file:

 

 

Char c; 	 	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	f32 x,y,z; 	GetCharCoordinates(c, &x, &y, &z);

 

 

Any help would be appreciated.

 

smile.gif

 

Okay, I now know how, but it replaces whatever is there, each time I press the button, I would like it to append not replace.

Edited by sjaak327
Link to comment
Share on other sites

@sjaak327: I'm trying to do the same, but with a nice filewriting code.

I doesn't give any compiler errors/warnings, yet the game crashes when I press the button.

Here's a snip:

 

 

void LouNGeRCrap::Log(char text) {       FILE *pFile;       errno_t err;       if( (err = fopen_s(&pFile, "LouNGeRCrap.log", "a+")) == 0 ) {               fprintf(pFile, "%s\n", text);       }       fclose(pFile);}void LouNGeRCrap::LogPlayerCoords() {       Char p = PlayerChar();       char buff;       f32 x, y, z;       GetCharCoordinates(p, &x, &y, &z);       sprintf_s(&buff, 70, "%f, %f, %f", x, y, z);       Log(buff);}

 

 

fprintf works fine when I put some static string in the place of "text".

"Log(char text)" is probably wrong.

 

NOTE: "a+" for fopen_s = Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn't exist.

 

 

Thanks, that would come with the models' textures as well?

I'm pretty sure it does, I don't think you can spawn a existing model without it's textures.

Edited by L0uNGeR
Link to comment
Share on other sites

 

@sjaak327: I'm trying to do the same, but with a nice filewriting code.

I doesn't give any compiler errors/warnings, yet the game crashes when I press the button.

Here's a snip:

 

 

void LouNGeRCrap::Log(char text) {       FILE *pFile;       errno_t err;       if( (err = fopen_s(&pFile, "LouNGeRCrap.log", "a+")) == 0 ) {               fprintf(pFile, "%s\n", text);       }       fclose(pFile);}void LouNGeRCrap::LogPlayerCoords() {       Char p = PlayerChar();       char buff;       f32 x, y, z;       GetCharCoordinates(p, &x, &y, &z);       sprintf_s(&buff, 70, "%f, %f, %f", x, y, z);       Log(buff);}

 

 

"fprintf" works fine when I put some static string in the place of "text".

"Log(char text)"  is probably wrong.

This is the code that I'm using now:

 

 

else if ((GetAsyncKeyState(VK_NEXT) & 1) != 0) 	{ 	Char c; 	 	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	f32 x,y,z; 	GetCharCoordinates(c, &x, &y, &z); 	 	using namespace std;  	ofstream myfile ("Coords.txt", ios::app);        myfile <<"x=" <<x; 	myfile <<"\n"; 	myfile <<"y=" <<y;  	myfile <<"\n"; 	myfile <<"z=" <<z; 	myfile <<"\n"; 	myfile.close();    	DisplayTextWithLiteralString(0.5f, 0.25f, "STRING", "Coordinates Written !");

 

 

This works fine, when I press Pagedown, the coordinates are written to the file, I'm now searching for a way to write this to the end of the file, affectively apending the file instead of writing it at the beginning. Apparently seekp might be able to do the trick, I'm trying now.

 

Edit: it works, the following code will get the x,y and z coordinates to the file specified with append.

 

it will put the coordinates in the file in just the way I prefer:

 

x=-606

y=-753

z=65.9908

 

smile.gif

 

 

Edited by sjaak327
Link to comment
Share on other sites

 

Can someone show me how to use "CreateRandomChar" please?

I am not sure how to get the "Char *pChar".

*pChar is a pointer, call the function and add "&" to the variable.

 

Char myNewRandomChar;CreateRandomChar(0.0, 0.0, 0.0, &myNewRandomChar);

 

myNewRandomChar now contains (hopefully) data, that is of type Char (not Char as in text but Char as a person ofcourse)

Edited by L0uNGeR
Link to comment
Share on other sites

Aru: how do i declare a var of type Car in my .h file?

 

If i do:

 

Private: Scripting::Car myCar;

 

 

I get error C2039: 'Car' : is not a member of 'Scripting'. Although Car is shown in the autocompletion... Wierd.

Link to comment
Share on other sites

I think you should add
#include "Scripting.h"

or

#include "ScriptingTypes.h"

at the beginning of your code

Yeah, it now works. But im not allowed to make a vector of cars somehow, i get massive errors. Anyway, time for beer biggrin.gif

Link to comment
Share on other sites

 

Thanks, but I dont' know how to do this in C++, I guess I need to declare the parms to pass, I have declared Car car;

 

but I'm having trouble with the two colour parms.

Just declare them as normal, in this case, ints.

 

int color1, color2;

 

Then when using them in the native, slap an ampersand (&) in front of them (&color1). When you use whatever to read the values to another native (like SET_CAR_COLOURS, without the ampersand), they will be filled with the info you "got" previously.

Link to comment
Share on other sites

how to use this

if (IsCharInAnyCar© = 1)

is this right?

if in lua

 

Pushint(PLAYER_CHAR)

Callnative(is_char_in_any_car)

If ((Getintresult)=1)

Like this, How to use like that in c++

 

Edit : Nothing, Just a secret

 

 

Edited by aceship
Link to comment
Share on other sites

New version: 0.2.0. Download on first post.

 

Features:

 

- Solution reorganized... ScriptHook now compiles as a .lib, and the samples are in separate projects that compile to a .dll linking against that .lib. Full source is still included.

 

- New NativeFiberThread base class lets you do linear programming instead of tick-based programming. This should allow you to use things like Wait(). See the SampleCustomFiber project for more details.

 

- Reorganized Scripting types... Char is now Ped (like it should be), and Car is now Vehicle (like it should be), and PlayerIndex is a real type now (Player) instead of just a u32. You don't have to replace the declarations in your existing code if you're porting to the new version of the hook... they should still compile as is.

 

- Cleaned up new native functions in Scripting.h totaling about 650 natives now (still lots more to go). Each sample project has its own Scripting.h allowing me to update the main Scripting.h going forward without messing up your own declarations.

 

- Added basic logging functionality. See the sample projects for more information if you would like to consume this in your own code.

 

-------

 

@Intosia

 

#include <vector>

#include "ScriptingTypes.h"

 

then:

 

std::vector<scripting::Car> vectorOfCars;

 

@L0uNGeR... Try the NativeFiberThread thing in 0.2.0 for your code with lots of Wait()s smile.gif

 

@Sacky... I thought about it for a bit... I think an approach like this should do:

 

1. Change NativeInvoke::Invoke(ch *, NativeContext *) to store the name/context somewhere, and then go into a loop until the code is executed.

 

2. Create a NativeThread that properly invokes the stored name/context (if available) and sets a flag for the parent thread to exit the loop.

 

Its somewhat hacky, and it blocks the caller thread but thats probably the best approach.

Edited by aru
Link to comment
Share on other sites

Im not using the 0.2 now, Its make your script messed up(If you are editing the script.h) when you are building it and not done yet, I think you must use it AFTER your Script done(If you are editing the script.h), am i right?

Link to comment
Share on other sites

I tested the 0.2.0, SampleCustomFiber.asi. It seems all function would become unavailable when I reload the game from gamesaves. Will you fix this? tounge2.gif

Link to comment
Share on other sites

Thanks, but I dont' know how to do this in C++, I guess I need to declare the parms to pass, I have declared Car car;

 

but I'm having trouble with the two colour parms.

Just declare them as normal, in this case, ints.

 

int color1, color2;

 

Then when using them in the native, slap an ampersand (&) in front of them (&color1). When you use whatever to read the values to another native (like SET_CAR_COLOURS, without the ampersand), they will be filled with the info you "got" previously.

Thanks, I tried that like this:

 

 

Char c; Car car; int colour1,colour2	  u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); GetPlayerChar(playerIndex, &c); 	 if (IsCharSittingInAnyCar© == 1) { GetCarCharIsUsing(c, &car); GetCarColours(car,&colour1,&colour2);

 

 

And I'm getting the following error:

 

Scripting::ChangeCarColour' : cannot convert parameter 2 from 'int' to 'Scripting::eColour and

Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)

 

So This must have to do with the enumeration in scriptingenums.h. I guess I have two options, either do that enumeration, or change the native to not include enumeration.

 

 

Link to comment
Share on other sites

i am making some Quick EVADE in gta now, maybe it make 1 weeks to done.

using coord as script

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

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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