Jump to content

Recommended Posts

Did you follow the instructions in the upgrade.txt when you compiled your asi against the newest scripthook ?

 

Otherwise try another mod, like ingame trainer or simple trainer, both work fully on the newest patch.

 

 

Edited by sjaak327
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059698718
Share on other sites

smile.gif Thx for this. But I still have a Windows 7 related prob.

 

2009-12-22 12:24:38 - Initializing ScriptHookDotNet v0.893 BETA (GTA IV version 1.0.3.0)2009-12-22 12:26:15 - Direct3D device created!2009-12-22 12:26:16 - SEARCHING FOR SCRIPTS...2009-12-22 12:26:16 - Loading scripts in Assembly 'scripts\UltimateBulletTimeMod.net.dll' ...2009-12-22 12:26:16 -  ...found script 'UBT.UBTScript'!2009-12-22 12:26:16 - DONE! 1 valid scripts found!2009-12-22 12:26:16 - STARTING SCRIPTS...2009-12-22 12:26:16 - Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.                        at unmanaged.MemoryAccess.GetPhoneNumber()                        at GTA.NetHook.CheckPhone()                        at GTA.NetHook.Tick()                        at StartupThreadC.RunTick(StartupThreadC* )

 

 

I'm using aru's scripthook.dll and hazardx's scripts folder. turn.gif

I'll wait for a new version which will fully work on new OS.

(It just crashes my game after loading saves.)

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059698748
Share on other sites

MadthatModsareDisabled

Sjaak,

 

 

Here's what I'm finding out. asilog shows this:

 

// -- GTA IV ASI LOADER LOG -- //

//-- © Alexander Blade 2008 -- //

C:\Windows\system32\dsound.dll is loaded, address 0x71230000

Hooking dsound proc named "DirectSoundCreate"

"DirectSoundCreate" hooked, address 0x71247A61

Hooking dsound proc named "DirectSoundEnumerateA"

"DirectSoundEnumerateA" hooked, address 0x71258A34

Hooking dsound proc named "DirectSoundEnumerateW"

"DirectSoundEnumerateW" hooked, address 0x71258A51

Hooking dsound proc named "DllCanUnloadNow"

"DllCanUnloadNow" hooked, address 0x7125C6D3

Hooking dsound proc named "DllGetClassObject"

"DllGetClassObject" hooked, address 0x712486D4

Hooking dsound proc named "DirectSoundCaptureCreate"

"DirectSoundCaptureCreate" hooked, address 0x71258364

Hooking dsound proc named "DirectSoundCaptureEnumerateA"

"DirectSoundCaptureEnumerateA" hooked, address 0x71258A6E

Hooking dsound proc named "DirectSoundCaptureEnumerateW"

"DirectSoundCaptureEnumerateW" hooked, address 0x71258A8B

Hooking dsound proc named "GetDeviceID"

"GetDeviceID" hooked, address 0x71258200

Hooking dsound proc named "DirectSoundFullDuplexCreate"

"DirectSoundFullDuplexCreate" hooked, address 0x712584CC

Hooking dsound proc named "DirectSoundCreate8"

"DirectSoundCreate8" hooked, address 0x71236D48

Hooking dsound proc named "DirectSoundCaptureCreate8"

"DirectSoundCaptureCreate8" hooked, address 0x71258412

Loading ASI C:\Program Files (x86)\Rockstar Games\Grand Theft Auto IV\FileCheckFix.asi

ASI loaded : C:\Program Files (x86)\Rockstar Games\Grand Theft Auto IV\FileCheckFix.asi, Address 0x00380000

Loading ASI C:\Program Files (x86)\Rockstar Games\Grand Theft Auto IV\SampleCustomFiber.asi

ASI loaded : C:\Program Files (x86)\Rockstar Games\Grand Theft Auto IV\SampleCustomFiber.asi, Address 0x00000000

 

 

I notice that the Address is blanked out for my SampleCustomerFiber.asi.

 

Do you have any idea why its not loading? Everything else seems to find its proper place.

 

You have been the biggest help and because of you I was able to create my first object spawner (remember that)?

 

Thanks again, man!

- Steve

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059698765
Share on other sites

The fact that the address is blanked out, means it did load with an exception, that is generally not good smile.gif

 

I suggest you first try and see if other mods do work on your game, and if that is the case, go through your trainer's source, and make sure you have followed aru's intructions in the upgrade.txt file, so that indeed it is referring to the new scriptthread instead of the old fiberthread.

 

 

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059698779
Share on other sites

MadthatModsareDisabled

Sjaak,

 

Thanks. Actually I'm trying to run a test on the file SampleCustom.dll included in the Script Hook and even then it does not work. I have checked everything against the UpdateGuide and Aru appears to have corrected this in the SampleCustom.dll file.

 

I may have missed a step or two, but do I need all 3 files:

 

SampleCustom.dll

SampleCustomFiber.dll

Speedo.dll

ScriptHook.dll

 

They all appear to return address 0. Since I am still a novice programmer in c++, I googled this. I learned that when Address 0x00000000 shows, it means there is a memory access violation because the pointer should always point to a valid variable's address.

 

I would like more to understand how the FileCheckFix.asi works too. Is there a tutorial on this? So that way if I get a strange error message, I might know what I need to do next.

 

I almost feel like I have to go back and reread the entire log for GTAIV/REL/SRC/C++ Script Hook just to understand what is happening. However, I don't have the time (or energy) to do this.

 

I have strongly depended upon feedback from other users (like you Sjaak) and the rewards were always good. As an example, because Patch 5 was added I had a very powerful trainer written (nearly 40 pages long). Thanks to help here and tremendous help from SneakyJanit0r, I was able to add just about anything to my trainer. Now I'm back at square 1. Sad.

 

Again my main focus now is to get the SampleCustomFiber.dll or CustomFiber.dll files working that came with the Script Hook. I will do my own conversations later, after I get success with this.

 

Thanks again, Steve

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059698843
Share on other sites

^ It seems to me that this is definitely a problem in your installation of GTAIV rather then anything else. Probably something is preventing successfull loading of mods on your machine, mabye post content of GTAIV directory, in any case if you want to run the provided sample ALL that is needed really is:

 

Asi loader

Scripthook.dll

samplecustom.dll > rename to .asi

 

this should at least allow you to use the sample in SP.

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059699180
Share on other sites

@MadthatModsareDisabled... I'd suspect that you are missing a DLL that SampleCustomFiber.asi is using. I'd use DependencyWalker to find out what you're missing: http://dependencywalker.com/

 

On an unrelated note, there is a new update of ScriptHook in the works to address some bugs/issues the current version has. Hopefully I'll have some time over the xmas break to finish it up and release it. Until then, Merry Christmas!

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059700138
Share on other sites

[tl;dr]

Okay, so I've decided to go back to my roots and first love, i.e., C++, and ditch C# and HazardX's wrapper for this. (Besides, though I have the highest respect, regard, and admiration for HazardX and his work, Lord knows he is not the most dependable person in regard to maintaining his mod. colgate.gif) Anyway, I got everything up and running, and the SampleCustomFiber sample DLL compiles and loads (in-game) as expected.

 

The problem with using a wrapper API (a.k.a., HazardX's .NET wrapper) is that while it makes the scripting incredibly convenient (that's the whole point, I know), you don't really know what's going on under the hood. So now with the core engine minus HazardX's wrapper, I have a question since there seems to zero documentation and not really any useful sample code. (The included sample code is akin to the standard "C" "Hello, World!" sample code which, obviously, is not too helpful when trying to learn an engine's API.)

[/tl;dr]

 

 

I just have a (hopefully) quick question. Looking over the scant sample code, tell me if I am understanding this correctly.

 

For each independent thread I want running:

  1. I create a class derived from ScriptHook;
  2. I define and implement RunScript() in that class (this serves as the entry function of the thread); and
  3. In DllMain(), register each thread via ScriptHookManager::RegisterThread().
Is that about right?

 

Also, off-topic, but is the source code for the ScriptHook.dll available, or is it strictly closed-sourced?

Edited by Zach
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059702863
Share on other sites

@Zach... this is essentially a very low level access to the game's scripting layer. It's original design was with the intention of calling game scripting functions as fast as (or faster than) the game's script engine executing scripts. I think at the current version, it does that pretty well.

 

HazardX's wrapper does make it incredibly easy, but its also possible to create similar wrappers in C++. This is something that I always wanted to do but never had the time for. I heard of a few people wanting to do start on something like it, but haven't really seen any concrete results. Perhaps all it takes it a little initiative? smile.gif

 

The samples included are just test suites for me for quickly run to make sure any updates I make didn't break the core code. I was hoping that other people would contribute samples, open source code their created mods, etc and some have, but I guess I was too optimistic on hoping for that.

 

As for documentation on the Scripting API/natives, well, there isn't much documentation on it since most of it comes out of guess work based on the decompilation of R*'s scripts... again, collaboration is the only way we'll ever fully document the API/natives (gtamodding.com has a good start on it.)

 

For your quick questions:

 

1. Create a class that derives from ScriptThread

 

2. RunScript() is not a heartbeat function.. its more like a main() function for the script thread. If you would like a heartbeat like approach where the function must terminate after execution, implement RunTick() instead of RunScript(). Internally, the default non-overridden implementation of RunScript() calls RunTick().

 

3. Yes, that's correct. You'll have to create a static instance of the thread and register it. If you heap allocate the instance (i.e. using new), make sure you pass the HMODULE of your dll to RegisterThread as well.

 

Each registered thread will be registered into the game when it loads. The game will process each thread as if it were its own script thread. The processing is inherently single threaded on the system level (so multiple script threads won't run at the same time). Multitasking between threads is done in a cooperative manner where each thread calls Wait(ms) to relinquish control.

 

This project was originally fully open source under a ZLib license. Since then, I had to add checks for online play, and it's no longer open source. However, if you are interested in any parts of the code and would like to learn more about how it works internally, you can always shoot me an email.

Edited by aru
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059703151
Share on other sites

 

As for documentation on the Scripting API/natives, well, there isn't much documentation on it since most of it comes out of guess work based on the decompilation of R*'s scripts... again, collaboration is the only way we'll ever fully document the API/natives (gtamodding.com has a good start on it.)

Oh, yeah, I wasn't referring to natives per se, just the interface for your DLL and how to set up the framework.

 

 

1. Create a class that derives from ScriptThread

Right. I just misspoke. Sorry.

 

 

 

2. RunScript() is not a heartbeat function.. its more like a main() function for the script thread. If you would like a heartbeat like approach where the function must terminate after execution, implement RunTick() instead of RunScript(). Internally, the default non-overridden implementation of RunScript() calls RunTick().

Yeah, I was just speaking generically; in fact, after I reread it, I edited my post to remove the ambiguity. smile.gif

 

 

 

This project was originally fully open source under a ZLib license. Since then, I had to add checks for online play, and it's no longer open source. However, if you are interested in any parts of the code and would like to learn more about how it works internally, you can always shoot me an email.

Yeah, all the MP shenanigans I read about really bites. I don't play online; and given that my asi loader of choice is xliveless, I couldn't even if I wanted to since it disables online play altogether. smile.gif

 

Anyway, it's not too critical on my immediate to-do list. There were just a couple of implementation quirks I wouldn't mind changing, but it's strictly a personal preference thing and wouldn't merit a feature request or anything, so I was just wondering if I would be able to update the code myself. No worries, though.

 

Well, thanks for your speedy and thorough response!! It's much appreciated!

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059703322
Share on other sites

Oh, yeah, I wasn't referring to natives per se, just the interface for your DLL and how to set up the framework.

Ah, right... well, I figured it will be self evident from the samples. I'm not much of a technical writer.. sorry smile.gif

 

Feel free to recommend any changes. Even if its personal, you never know how many other people thought of the same thing. If it makes sense and can be easily added without breaking the existing API, I'll gladly include it with the next release.

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059703332
Share on other sites

 

HazardX's wrapper does make it incredibly easy, but its also possible to create similar wrappers in C++. This is something that I always wanted to do but never had the time for. I heard of a few people wanting to do start on something like it, but haven't really seen any concrete results. Perhaps all it takes it a little initiative? smile.gif

 

Well i have been playing with this, but its a bit over my head (& free time) to tell you the truth. http://www.gtaforums.com/index.php?showtopic=435532

Also there was a well designed start created by a bloke called diryboy, sadly he seems to have dissapeared & project is discontinued. http://ivscripting.codeplex.com/

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059703673
Share on other sites

MadthatModsareDisabled

Hi guys,

 

I just wanted to thank Sjaak and Aru for their help. I am now able to mod in multiplayer again. I had to reinstall GTA IV, the patch, add the dsound.dll file and add Alexander's FilecheckFix.asi.

 

I also rewrote my trainer by carefully following the steps in the UpdateGuide included with the updated Script Hook. This saved me alot of time otherwise I would have been forced to rewrite my 89 page trainer. It was great to be able to see my trainer in the game again.

 

However now alot of Natives are not functional. I figured out how to get God Mode to work. The problems I'm still having are getting the GodCar and Weapons Natives to work:

 

I am using SetCarStrong(vehicle, true, true);

 

My God Mode code is:

 

 

void CustomFiberThread::GodCar(){ if (IsCharInAnyCar(GetPlayerPed())) { Vehicle vehicle; //eVehicleTyre tyre; GetCarCharIsUsing(GetPlayerPed(), &vehicle); SetCarCanBeDamaged(vehicle, false); SetCarCanBeVisiblyDamaged(vehicle, false); SetCarStrong(vehicle, true, true);  ResetCarWheels(vehicle, true); SetCarCollision(vehicle, true); MarkCarAsConvoyCar(vehicle, true); //testing PrintStringWithLiteralStringNow("STRING", "Car is indestructable", 3000, true); //FixCarTyre(vehicle, tyre); //SetCarProofs(vehicle, true, true, true, true, true); //SetLoudVehicleRadio(vehicle, true); } else if (!IsCharInAnyCar(GetPlayerPed())) {  PrintStringWithLiteralStringNow("STRING", "You must be in a vehicle first", 3000, true); }}

 

 

 

Yet it does not work. GTA IV crashes on me.

 

Also in my weapons script, I have:

 

 

void CustomFiberThread::WeaponsLoadedSetOne(){GiveWeaponToChar(GetPlayerPed(),WEAPON_KNIFE,0,0,1);GiveWeaponToChar(GetPlayerPed(),WEAPON_MOLOTOV,30000,0, 1);GiveWeaponToChar(GetPlayerPed(),WEAPON_PISTOL,0,0,1);GiveWeaponToChar(GetPlayerPed(),WEAPON_SHOTGUN, 25000,0,1);GiveWeaponToChar(GetPlayerPed(),WEAPON_MICRO_UZI, 25000,0,1);GiveWeaponToChar(GetPlayerPed(),WEAPON_AK47,0,0,1);GiveWeaponToChar(GetPlayerPed(),WEAPON_RLAUNCHER, 25000,0,1);PrintStringWithLiteralStringNow("STRING", "Loading Weapons Set One",7500,1);}

 

 

 

It crashes however.

 

Anybody else notice alot of natives have been changed?

 

My final question is what application can I download to see the GTA IV code in c++ or something similar. I want to be able to see the changed Natives so I can update mine. If you can provide the link, that would be most helpful.

 

Let modding rule forever, but keep it under control so its power is not abused.

 

-StevorNtheHouse

Edited by MadthatModsareDisabled
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059704708
Share on other sites

SetCarStrong only has two parameters:

 

 

    static void SetCarStrong(Vehicle vehicle, b8 strong) { NativeInvoke::Invoke<NATIVE_SET_CAR_STRONG, ScriptVoid>(vehicle, strong); }

 

 

Also Giveweapontochar has only 4 parms ,not 5:

 

 

    static void GiveWeaponToChar(Ped ped, eWeapon weapon, u32 ammo, b8 unknown0) { NativeInvoke::Invoke<NATIVE_GIVE_WEAPON_TO_CHAR, ScriptVoid>(ped, weapon, ammo, unknown0); }

 

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059704740
Share on other sites

Speaking of SetCarStrong(), does the native NATIVE_SET_CAR_STRONG actually do anything? It's been a while, but I seem to recall it had no actual in-game effect on the vehicle.

 

In my old .Net mod, I remember trying to emulate GTA:VC's SetCarHeavy() command. Pure giggle factor, I admit, but it was so much fun racing down the highway, ramming cars, and having them bounce off me. Unfortunately, under GTA IV, to achieve that effect, I had to resort to physics calculations and manually calling ApplyForce() to cars around me, and it was never quite the same. sad.gif

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059705646
Share on other sites

HazardX's wrapper does make it incredibly easy, but its also possible to create similar wrappers in C++. This is something that I always wanted to do but never had the time for. I heard of a few people wanting to do start on something like it, but haven't really seen any concrete results. Perhaps all it takes it a little initiative? smile.gif

 

Well i have been playing with this, but its a bit over my head (& free time) to tell you the truth. http://www.gtaforums.com/index.php?showtopic=435532

Also there was a well designed start created by a bloke called diryboy, sadly he seems to have dissapeared & project is discontinued. http://ivscripting.codeplex.com/

Yep, saw that GhostGum. Pretty impressive work. Perhaps you could put it up on a public open source repository (googlecode/codeplex) so others can contribute as well if free time is an issue smile.gif

 

I glanced over diryboy's implementation... I do like how he split the basic API layer into a C# project rather than implementing it all in MC++.

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059705789
Share on other sites

Speaking of SetCarStrong(), does the native NATIVE_SET_CAR_STRONG actually do anything? It's been a while, but I seem to recall it had no actual in-game effect on the vehicle.

 

In my old .Net mod, I remember trying to emulate GTA:VC's SetCarHeavy() command. Pure giggle factor, I admit, but it was so much fun racing down the highway, ramming cars, and having them bounce off me. Unfortunately, under GTA IV, to achieve that effect, I had to resort to physics calculations and manually calling ApplyForce() to cars around me, and it was never quite the same. sad.gif

Set car strong does nothing, same as setcarheavy they seem to be doing nothing visibly.

 

 

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059706622
Share on other sites

 

Set car strong does nothing, same as setcarheavy they seem to be doing nothing visibly.

Good to know my memory isn't faulty. biggrin.gif

 

---

 

@anyone: I'm sure this has been figured out by now, so instead of spending hours or days doing tedious trial-and-error runs, I'll just ask and hope and pray someone is kind enough to share their knowledge. smile.gif

 

I know how to use PrintStringWithLiteralStringNow() to display messages with a specified time duration, but how do you display a message in the upper left-hand corner with a specified time duration?

 

For instance, if I use the "non-dirty" native DisplayTextWithLiteralString(), 1.) it only flashes the message (I presume just for a single frame), and 2.) it's huge.

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059707528
Share on other sites

Hi guys!

 

I have downloaded the Realizm 6.2 mod. I have installed GTA 4 again, I have applyed the 1.0.0.4 patch and i have installed the Ultimate Texture 2.0 mod. I have installed the Realizm Mod 6.2 mod, but when i start GTA 4 compare a WS10 error message, xnetstartup error. How can I solve it? I'm going crazy!

 

Maybe the ASI Loader and the ScriptHook in the realizm.rar are too old?

 

Please help me

 

P.S.: Sorry for my english, I'm Italian...

 

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059707817
Share on other sites

 

Set car strong does nothing, same as setcarheavy they seem to be doing nothing visibly.

Good to know my memory isn't faulty. biggrin.gif

 

---

 

@anyone: I'm sure this has been figured out by now, so instead of spending hours or days doing tedious trial-and-error runs, I'll just ask and hope and pray someone is kind enough to share their knowledge. smile.gif

 

I know how to use PrintStringWithLiteralStringNow() to display messages with a specified time duration, but how do you display a message in the upper left-hand corner with a specified time duration?

 

For instance, if I use the "non-dirty" native DisplayTextWithLiteralString(), 1.) it only flashes the message (I presume just for a single frame), and 2.) it's huge.

Yes, so you need to use a bool to control the display. That's the way I build my entire menu system for instance, and the clock in the upper right corner. Alll using Displaytextwithliteralstring.

 

In this case you could use settimerA, (or settimerB), and once the timer is done, undisplay the message. Regarding the size, before you issue the displaytextblah, use settextscale.

 

 

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059707983
Share on other sites

 

HazardX's wrapper does make it incredibly easy, but its also possible to create similar wrappers in C++. This is something that I always wanted to do but never had the time for. I heard of a few people wanting to do start on something like it, but haven't really seen any concrete results. Perhaps all it takes it a little initiative? smile.gif

 

Well i have been playing with this, but its a bit over my head (& free time) to tell you the truth. http://www.gtaforums.com/index.php?showtopic=435532

Also there was a well designed start created by a bloke called diryboy, sadly he seems to have dissapeared & project is discontinued. http://ivscripting.codeplex.com/

Yep, saw that GhostGum. Pretty impressive work. Perhaps you could put it up on a public open source repository (googlecode/codeplex) so others can contribute as well if free time is an issue smile.gif

 

I glanced over diryboy's implementation... I do like how he split the basic API layer into a C# project rather than implementing it all in MC++.

I will do as you suggest & chuck it up onto a public open source repository (or private with acct at request if public turns out to be too much trouble, public for now though).

 

I too liked how diryboy split the api layer into another c# project, would make creating the api classes much quicker. It was prolly beyond my knowledge to do so with GTAScript.Net, but im happy with all in CLI C++, keeps flexibility & gives me a chance to improve my mediocre c++ skillz. Also i liked how he used a template class for handling all the script base types, rather than hardcoding for each individual one like i have done. But once again, my knowledge limits me, perhaps in the future i will have a crack at that.

 

 

Aru, i have a bit of a question: with my API classes , eg GameObject, i am storing the uint handle of the object as a member of GameObject. When i require a Scripting::Object for one of your Scripting functions, i have a member property of GameObject called Base, which when called creates a new Scripting::Object then manualy setting its Handle to my member handle. Im not sure that this is a good thing to do though. How would you suggest i go about having a Scripting::Object for my API class GameObject? Should i instead actualy create a Scripting::Object for each instance of GameObject? But still sometimes i do need to create a Scripting::Object with a specific handle anyway (eg. the world functions that are brute forcing the DoesObjectExist function, iterates through all the possible handles).

How would i go about calling the gta scripting functions & feeding them the actual handle instead of the scripting type? Would that be bad?

Edited by GhostGum
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059708572
Share on other sites

 

Yes, so you need to use a bool to control the display. That's the way I build my entire menu system for instance, and the clock in the upper right corner. Alll using Displaytextwithliteralstring.

So the function prototypes in Aru's Scripting.h header are wrong?

 

For instance, the prototype for DisplayTextWithLiteralString() (your example) is defined as the following:

 

 

void DisplayTextWithLiteralString(f32 x, f32 y, const ch *gxtName, const ch *literalStr); 

 

 

Where is it that you set this boolean value you speak of?

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059708632
Share on other sites

Yes, so you need to use a bool to control the display. That's the way I build my entire menu system for instance, and the clock in the upper right corner. Alll using Displaytextwithliteralstring.

So the function prototypes in Aru's Scripting.h header are wrong?

 

For instance, the prototype for DisplayTextWithLiteralString() (your example) is defined as the following:

 

 

void DisplayTextWithLiteralString(f32 x, f32 y, const ch *gxtName, const ch *literalStr); 

 

 

Where is it that you set this boolean value you speak of?

I would presume it only displays for 1 frame, so you would need to call it every tick.

 

so if you weant it to display for a certain amount of time, just set a counter that decreases every tick.

 

suedocode eg.

 

 

u32 displaycounter;string Text;void PrintString(string text, u32 time){  displaycounter = time;  Text = text;}void Tick(){   if (displaycounter > 0)   {       displaycounter--;       DisplayTextWithLiteralString(24,24,"STRING",Text); // (24,24 for top left)   }}

 

 

something like that would display you 1 string in top left, just call Tick() every tick, and PrintString() to print your string.

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059708672
Share on other sites

 

Aru, i have a bit of a question: with my API classes , eg GameObject, i am storing the uint handle of the object as a member of GameObject. When i require a Scripting::Object for one of your Scripting functions, i have a member property of GameObject called Base, which when called creates a new Scripting::Object then manualy setting its Handle to my member handle. Im not sure that this is a good thing to do though. How would you suggest i go about having a Scripting::Object for my API class GameObject? Should i instead actualy create a Scripting::Object for each instance of GameObject? But still sometimes i do need to create a Scripting::Object with a specific handle anyway (eg. the world functions that are brute forcing the DoesObjectExist function, iterates through all the possible handles).

How would i go about calling the gta scripting functions & feeding them the actual handle instead of the scripting type? Would that be bad?

So, the Scripting::Ped, Scripting::Object, etc types were created to ensure that you don't pass invalid types into scripting functions... its sort of like a "compiler enforced security". What really matters in all this is the integer Handle value... which is all you really need to store.

 

So for your brute force case, I would go ahead and create instances of Scripting::Object from the Handle value... that's fine, it was just my design choice to wrap the handle in a struct, but you can pass in an int if you really want!

 

But, for the general implementation, what I would probably try is:

- Inherit GameObject from Scripting::Object, or Ped from Scripting::Ped

- You probably will have to use multiple inheritance because you want Player to inherit from Ped as well... not sure how well this will work with MC++.

- When you call the native function, just pass (*this) for the reference.

- For functions which return a Scripting::Object... make them static and return a concrete class.... so: static ScriptingObject^ Scripting::CreateObject( xyz ) {}

 

If that doesn't work.. you can do one of the following:

1. Store the Scripting::Object value as part of the class itself.

2. Store the handle value (integer) from the Scripting::Object and create a new Scripting::Object every time from this handle value for every native call (don't worry... it doesn't cost any CPU/memory if you do it in the non-managed layer... its a very tiny struct with one variable)

 

 

@danutzu259, maybe smile.gif

Edited by aru
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059708910
Share on other sites

AFAIK, sadly a CLI managed class cannot inherit from an unmanaged native class. So i must create a new class with the scripting class as a member & create wrapper functions in my new class which just call the native class functions.

 

Unless there is a way for me to inherit from the scripting classes, (which would indeed make things easier) & if it does not cause any trouble (which was my worry) then i will keep it as it is, with member property Base to create a new instance of Scripting class every time.

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059708982
Share on other sites

In general, is it safe to assume ScriptThread's Tick() or RunScript() are only called while the game is actually running? (as opposed to while in the Main Menu before a game has been loaded, or during game loads themselves for that matter)

 

Also, I'm wondering if I can code my cPlayer wrapper class in such a way where I can presume there actually is a player. smile.gif Or even more specifically, can I assume that the native Scripting::GetPlayerChar(...) will always return a valid handle?

Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059709070
Share on other sites

 

Ah damn, that sucks... Well, in that case, you can either store the Scripting class like you are doing now, or you can change the typedefs for Sccripting::Object, Scripting::Ped to an u32... and store the handle instead.

k, ill leave as is for now then. Changing the scripting types typedefs to u32 is an interesting idea, but i'd prolly like to stay true to your original scripthook headers if a can. Cheers for the help & info.

 

 

  In general, is it safe to assume ScriptThread's Tick() or RunScript() are only called while the game is actually running? (as opposed to while in the Main Menu before a game has been loaded, or during game loads themselves for that matter)

 

Also, I'm wondering if I can code my cPlayer wrapper class in such a way where I can presume there actually is a player. smile.gif Or even more specifically, can I assume that the native Scripting::GetPlayerChar(...) will always return a valid handle?

 

Yes it is safe to assume RunScript() & Tick() are only called when game is running, as year script is created in dllmain, the constructor for your script will be called on startup before game is running though. Im not sure about if GetPlayerChar() will always return a valid handle.

Edited by GhostGum
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/42/#findComment-1059709279
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
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

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