Jump to content

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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058862537
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058863415
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058863619
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058863690
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058865249
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058865303
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058865477
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058865485
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058866234
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.

 

 

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058867179
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058867607
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058868135
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058868295
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
https://gtaforums.com/topic/390582-c-script-hook/page/5/#findComment-1058868484
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
  • 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.