Jump to content

Recommended Posts

..., 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.

Well, Tick() / RunScript() running only in-game is sufficient enough for me to make the assumptions I was wanting to make in my implementation.

 

GetPlayerChar() will only ever get called from somewhere inside Tick() / RunScript() (directly or indirectly), so based on your assertion, I would think it is safe to assume it will always return a valid handle, i.e., if the game is running, there has to be a player character, yes? smile.gif

 

 

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

 

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.

So I create a new Tick() based script and implemented DisplayTextWithLiteralString() similar how you suggest, but there's two problems.

 

1.) Using your (24,24) as the coordinates displays nothing, or it's being displayed off-screen somewhere. If I go back to using (0.0, 0.0), it prints up in the left-hand corner as expected. Don't I recall something about the engine using normalized coordinates (0.0 --> 1.0) in certain cases to account for the varying screen resolutions? Maybe this is one of those cases? Update: Yes, DisplayTextWithLiteralString() definitely uses normalized coordinates. Using 0.5,0.5 makes it display in the center of my screen. wink.gif

 

2.) The text still flickers.

 

Now, with the use of my high resolution timer (search MSDN for QueryPerformanceCounter), I have found that, on average, Aru calls Tick() every 17.5 ms. So, apparently, the game engine itself is displaying the text for less than 17.5 ms, hence why I am seeing the flicker.

 

So I know this isn't the optimal solution because with HazardX's implementation, the text message is displayed just like any other system generated message: nice and steady for a finite duration. So how does he do it?

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

Now, with the use of my high resolution timer (search MSDN for QueryPerformanceCounter), I have found that, on average, Aru calls Tick() every 17.5 ms. So, apparently, the game engine itself is displaying the text for less than 17.5 ms, hence why I am seeing the flicker.

 

So I know this isn't the optimal solution because with HazardX's implementation, the text message is displayed just like any other system generated message: nice and steady for a finite duration. So how does he do it?

Aru doesn't call Tick(), the game does.. the function is called directly from the game's execution. 17.5ms here just means that your game is running at 57fps.

 

Now, it flickers due to a bug in the latest version... so ignore it for now, it will hopefully get fixed with the next update of ScriptHook which isn't that far off.

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

 

Aru doesn't call Tick(), the game does.

Well, whatever. I just meant it is being called by something beyond my scope of control. tounge.gif (Remember, you know your library. I only see the exposed ScriptThread::Tick() method.)

 

 

 

Now, it flickers due to a bug in the latest version...

Oh, good to know. Now excuse me while I go kick myself for wasting an entire day trying fix the flicker problem. suicidal.gifbiggrin.gif (Edit: Oh, wait. You mean a bug in your code? Sorry. I thought there you meant a bug in Patch 5. Never mind.)

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

The crashing problems i have with the latest version of the C++ scripthook and the .Net scripthook seem to come from ScriptThread:OnKill not being called or being called too late. When loading a savegame i always get a crash amidsts the loading process... without OnKill ever being called. I do not know whether or not this is the root of the problem, but it seems strange.

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

 

So I create a new Tick() based script and implemented DisplayTextWithLiteralString() similar how you suggest, but there's two problems.

 

1.) Using your (24,24) as the coordinates displays nothing, or it's being displayed off-screen somewhere. If I go back to using (0.0, 0.0), it prints up in the left-hand corner as expected. Don't I recall something about the engine using normalized coordinates (0.0 --> 1.0) in certain cases to account for the varying screen resolutions? Maybe this is one of those cases? Update: Yes, DisplayTextWithLiteralString() definitely uses normalized coordinates. Using 0.5,0.5 makes it display in the center of my screen. wink.gif

 

well i did say it was suedo code! I havnt played with screen drawing functions for long time, i was thinking in pixels. As you say, it is a float between 0.0F & 1.0F for the sceeen coords.

I was trying to give a example of displaying text for x ms as that is what i thought you were asking.

 

The flicker issue has been mentioned numerous times already, sjaak even provided a temp fix a few pages back.

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

the latest scrpthook.dll makes my game lock up during the loading of the mission.

im using 1.0.4.0 and not 1.0.0.4.

is that why?

 

i really dont intend to move to 1.0.0.4 cuz i like the 1.0.4.0 mods i have that dont support the 5th patch. is there a way i can cause my game to run the latest hook?

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

So, apparently, there is no way to fetch (from the game) the Player's maximum health? I know it's 200, but I detest hard-coded constants in my programs, and it just seems odd that there is no way to query this info (via some native).

 

I've looked through Scripting.h, ScriptingDirty.h, and even the Wiki (that claims to be a "complete list").

 

Am I missing something?

 

Also, I know for previous GTA games, a Player's maximum health would increase after doing special missions (Ambulance Driver??), but for GTA IV, does it at least stay constant throughout the entire game? (I've played through the game 3 or 4 times now, so I feel silly for having to ask that, but each play-through it always seemed harder to die at the end than at the beginning which at least hints that the maximum health may have been increased at some point.)

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

So, apparently, there is no way to fetch (from the game) the Player's maximum health? I know it's 200, but I detest hard-coded constants in my programs, and it just seems odd that there is no way to query this info (via some native).

 

I've looked through Scripting.h, ScriptingDirty.h, and even the Wiki (that claims to be a "complete list").

 

Am I missing something?

 

Also, I know for previous GTA games, a Player's maximum health would increase after doing special missions (Ambulance Driver??), but for GTA IV, does it at least stay constant throughout the entire game? (I've played through the game 3 or 4 times now, so I feel silly for having to ask that, but each play-through it always seemed harder to die at the end than at the beginning which at least hints that the maximum health may have been increased at some point.)

Max health is 200 normally, but can be set higher (native=increaseplayermaxhealth) whenever that native is issued, the increased health will show when you issue the getcharhealth native.

 

 

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

 

Max health is 200 normally, but can be set higher (native=increaseplayermaxhealth) whenever that native is issued, the increased health will show when you issue the getcharhealth native.

I know how to set it, and I know how to retrieve a ped's current health, but none of that has anything to do with either of my questions. sly.gif

 

Also, you say it's 200 normally. That implies it is not 200 at times. When would that be?

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

 

Max health is 200 normally, but can be set higher (native=increaseplayermaxhealth) whenever that native is issued, the increased health will show when you issue the getcharhealth native.

I know how to set it, and I know how to retrieve a ped's current health, but none of that has anything to do with either of my questions. sly.gif

 

Also, you say it's 200 normally. That implies it is not 200 at times. When would that be?

Maybe I am not understanding you, but you were wondering if there was a way to see if the maxhealth was increased, and I told you there was, by using getcharhealth. If whoever increased that max health, it will show by using getcharhealth.

 

If you are asking IF that happens by the game, I don't have a clue, of course it's pretty easy to find out I would think, by simply using getchar health and monitor if it ever goes over 200, which it will if the maxcharhealth was increased at any point.

 

Edit to add, I don't think the game actually increases it, at least not that I have ever noticed. Maybe replay one of those final missions and see if it does what you suspect it does.

 

 

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

 

but you were wondering if there was a way to see if the maxhealth was increased

That's not at all what I asked and you know it. tounge.gif

 

To quote myself:

 

 

So, apparently, there is no way to fetch (from the game) the Player's maximum health?

 

Which word it tripping you up? Maybe I can help. cool.gif

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

but you were wondering if there was a way to see if the maxhealth was increased

That's not at all what I asked and you know it. tounge.gif

 

To quote myself:

 

 

So, apparently, there is no way to fetch (from the game) the Player's maximum health?

 

Which word it tripping you up? Maybe I can help. cool.gif

Ok ok smile.gif

 

No native will get you the current maximum player health, but I do know that normally it's 200, unless someone increased it (obviously), but to do that, I would assume someone would actually set the health higher then 200 for it to have any real use.

 

IF that happens, it will register with getchar health smile.gif

 

 

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

I guess as "I'm too stubborn to use hard-coded constants" workaround, I suppose I can create a trivial one-shot thread that simply reads in the player's current health (it is always at max after loading a savegame), stores it in some global, and then exits.

 

More information than you want to know, I'm sure, but the reason why I care is because I want my mod auto-heal me, but only while not in combat. So after combat, my script needs to know what to pass to SetCharHealth().

 

Wait.. typing that made me think of something, and I just tested it, and it worked. Apparently, the game engine has an internal check and will clip the health at the max. smile.gif So I don't really need to even know. In other words, calling SetCharHealth(5000) (or whatever) is good enough as the game will just set it to the current max, i.e., 200. Good deal.

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

I just discovered another interesting thing.

 

Is there some hidden multiplier being applied to the player's health?

 

The health meter on-screen is tracking a health range of 100 to 200, not 0 to 200. Internally, GetCharHealth() tracks SetCharHealth(), but setting the health to anything below 100 kills you.

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

 

on my gtaIV game im using scripthook with GTAIV NATIVE TRAINER V4.9 and when im switching games online almost every time the game crashes,  can you please help me?  cryani.gif

Check out this thread: http://www.gtaforums.com/index.php?showtopic=422999 (at the very bottom).

the trainer only works on single player, free mode, and party mode. when i reload the game, i can go into the other persons game just fine

 

and on GTAIV NATIVE TRAINER V4.9 look near the last post, the creator told me to go here

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

 

the trainer only works on single player, free mode, and party mode

Well, read Section 6.0 of the rules again. It's very, very short, and it specifically addresses that claim. dozingoff.gif

 

 

Look, I'm not trying to be an ass, but online cheating and Rockstar's compulsive need to address it since the game's release and in almost every patch is what has made modding this game such an ordeal. That's why that forum rule was put in place from the get-go. You may or may not agree with it, but that's irrelevant.

 

Anyway, with that pet peeve off my chest, whatever. Hang tight. I'm sure some less principled person will answer you shortly. They always do. smile.gif

 

 

 

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

I've been toying around with this for the past few days, and someone correct me if I'm wrong (I hope to God I am!), but there does not seem to be a way to update a vehicle's velocity vector (speed != velocity), nor its current rotation vector (pitch and roll). How can that be?

 

The best one can seem to do is change the speed and the heading, and that is equivalent to a 2D velocity vector (XY plane), but it won't work (properly) if the vehicle is on a incline of any sort. (Example: The vehicle is driving up a hill or an on-ramp.)

 

For pitch and roll, I can think of no workaround. sad.gif For example, how can I stop a vehicle from 1.) flipping end over end, and 2.) put it back upright?

 

Sure, I could use a fat-finger approach and do something like:

 

 

// assume v is the Vehicle object in questionif( IsCarUpsidedown(v) ){   FreezeCarPosition( v, true  ); // stop all motion   FreezeCarPosition( v, false ); // allow it to move again   (void) SetCarOnGroundProperly( v );}

 

 

Certainly there is something more elegant? (I've played around with all the natives [even several "dirty" object natives] with no luck, so I'm guessing there's not.)

 

----------

 

For the "TL;DR" crowd:

 

How does one set a vehicle's 3D positional velocity vector? (aka, speed + direction)

How does one set a vehicle's 3D angular velocity vector? (aka, (yaw, pitch, roll) or "spin")

How does one set a vehicle's 3D rotation vector (i.e., angle car is facing, including Z axis) Note: the native SetHeading only affects XY direction, not Z direction!

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

damn that sucks hey. For full control i think we would prolly need to modify the memory values directly.

 

But heres some random UNTESTED GUESSES that may help using scripting functions:

 

* GET_VEHICLE_QUATERNION & SET_VEHICLE_QUATERNION could be used for rotation.

* i see GET_CAR_FORWARD_VECTOR & GET_CAR_SPEED_VECTOR, not sure what they do, but they sound useful for getting positional velocity vector.

* freeze/unfreeze car position like you have, then use APPLY_FORCE_TO_CAR and you should be able to set the positional velocity vector & angular velocity vector (as they are both part of that function if i remember right).

 

 

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

 

damn that sucks hey. For full control i think we would prolly need to modify the memory values directly.

 

But heres some random UNTESTED GUESSES that may help using scripting functions:

 

* GET_VEHICLE_QUATERNION & SET_VEHICLE_QUATERNION could be used for rotation.

* i see GET_CAR_FORWARD_VECTOR & GET_CAR_SPEED_VECTOR, not sure what they do, but they sound useful for getting positional velocity vector.

* freeze/unfreeze car position like you have, then use APPLY_FORCE_TO_CAR and you should be able to set the positional velocity vector & angular velocity vector (as they are both part of that function if i remember right).

About the GET_CAR_SPEED_VECTOR and such, I know, but that was my point: there is no corresponding SET_CAR_SPEED_VECTOR. tounge.gif

 

I didn't notice the quaternion natives in the dirty list, though. suicidal.gif With that, I should be able to mathematically derive most anything else I need to move the vehicle in any direction I want.

 

That doesn't solve the problem of rotational velocity, though. APPLY_FORCE_TO_CAR doesn't seem achieve the desired results. It's an external force applied to the vehicle, after which you pretty much lose control of the vehicle during the effect.

 

 

But your first statement jogged my memory! That's how I did it with GTA:SA and GTA:VC: I wrote a trainer to directly update the values. (heh, in fact, for SA, I did it to ace all those car and boat challenges turn.gif) I've seen questions above about this, I don't recall. Are globals directly accessible via aru's hook, or will I need to write a trainer to run along side my mod? brain unfroze ... realized I could just look at the headers to answer my own stupid question

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

I had the same problems with rotation while creating my fly mod and I finally used ApplyForce because updating the rotation gave me weird rotation behaviour. Sometimes there was no way to change the direction in one way, it was blocked and sometimes it just was crazy, car was turning around etc. I think this was because the engine changed the direction too and so I got these errors. So don't wonder if the car won't use the rotation you set. But as you said controlling ApplyForce ist hard, so I freezed the position every few ms, it then worked but I doesn't look smooth.

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

 

on my gtaIV game im using scripthook with GTAIV NATIVE TRAINER V4.9 and when im switching games online almost every time the game crashes,  can you please help me?

i went to the gtaIV file where you put scripthook, i looked at the scripthook.txt and found

 

[WARN] [simpleTrainer] Thread instance is being deleted while still hooked

[iNFO] [simpleTrainer] Thread killed

[iNFO] Script Hook - Shutdown

 

maybe this is causing my crashes?

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

As a matter of fact I cant seem to use the global commands at all even to set none array global values.

Is this still fixed or currently broken?

Is this on Windows 7 , seem to remember hazardx claiming he cannot get any global values when running on Windows 7.

 

 

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

Well, I just got a x64 install of Win7 going.... going to need some time to figure this out, but its fairly odd that it worked just fine in Vista x64.

 

Also, Zach... there's no way to set the velocity through the script code as far as I know. You could use the force thing... essentially, a force just gives the vehicle some acceleration, so if you know the current velocity, and the desired velocity, you should be able to determine how much acceleration (or deceleration) is required to modify the velocity to one you need. Provided you can do this in delta time (i.e. ~0 time), it should just be as good as setting the velocity. Just look at some force/acceleration/speed/time equations in any basic physics book.

Edited by aru
Link to comment
https://gtaforums.com/topic/390582-c-script-hook/page/43/#findComment-1059726855
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.