Search In
• More options...
Find results that contain...
Find results in...

# [BETA] GTAIV .Net ScriptHook

## Recommended Posts

Ok, this is a noob question i feel it: how can i get the distance between 2 coords(vec)? For ex. i want to detect if a player is close a this end point.

it is, somewhat.

Thats the basic math:

`distance = (pos1-pos2).Length`

The length of the difference between two positions is the distance.

But i've included the DistanceTo function for readability:

`distance = pos1.DistanceTo(pos2)`

##### Share on other sites
Ok, this is a noob question i feel it: how can i get the distance between 2 coords(vec)? For ex. i want to detect if a player is close a this end point.

it is, somewhat.

Thats the basic math:

`distance = (pos1-pos2).Length`

The length of the difference between two positions is the distance.

But i've included the DistanceTo function for readability:

`distance = pos1.DistanceTo(pos2)`

See! LOL. Yeah basic math sure (although i stink at math), i know a-b But i didnt thought it would work with vectors, because it has 3 axis. Thanks for the DistanceTo function

##### Share on other sites

Hey hazard.. how would you play a mp3 or wav file. I got something working(my.computer.audio.play) and it plays wav sounds. But only pcm wav ( which is like windows wav file) if i try to play other wav than a sound from windwos i get an error. Also i tried wmp.dll and that did not work... so you know any way to play a mp3 or wav file other than my.computer.audio.play

##### Share on other sites

Hey hazard.. how would you play a mp3 or wav file. I got something working(my.computer.audio.play) and it plays wav sounds. But only pcm wav ( which is like windows wav file) if i try to play other wav than a sound from windwos i get an error. Also i tried wmp.dll and that did not work... so you know any way to play a mp3 or wav file other than my.computer.audio.play

`Dim wav As New System.Media.SoundPlayerwav.SoundLocation = "filename.wav"wav.Play()`

Enjoy!

##### Share on other sites

Hey hazard.. how would you play a mp3 or wav file. I got something working(my.computer.audio.play) and it plays wav sounds. But only pcm wav ( which is like windows wav file) if i try to play other wav than a sound from windwos i get an error. Also i tried wmp.dll and that did not work... so you know any way to play a mp3 or wav file other than my.computer.audio.play

`Dim wav As New System.Media.SoundPlayerwav.SoundLocation = "filename.wav"wav.Play()`

Enjoy!

Thanks can you play mp3s?

*********EDIT THIS DOESNT WORK

IT gives me an error just like other one. IT can only play PCM wave files

ALso i think this is the same thing as doing my.computer.audio.play("FILE.wav")

Edited by boomer678

##### Share on other sites

Hey hazard.. how would you play a mp3 or wav file. I got something working(my.computer.audio.play) and it plays wav sounds. But only pcm wav ( which is like windows wav file) if i try to play other wav than a sound from windwos i get an error. Also i tried wmp.dll and that did not work... so you know any way to play a mp3 or wav file other than my.computer.audio.play

`Dim wav As New System.Media.SoundPlayerwav.SoundLocation = "filename.wav"wav.Play()`

Enjoy!

Thanks can you play mp3s?

*********EDIT THIS DOESNT WORK

IT gives me an error just like other one. IT can only play PCM wave files

ALso i think this is the same thing as doing my.computer.audio.play("FILE.wav")

I don't know what else to suggest except get an audio converter to convert the wav files to a valid format.

EDIT:

I suppose you could use the managed directx to play mp3 files.

You could also just use google to see what else there is to find.. http://www.google.com/search?hl=en&q=vb+net+play+mp3

Edited by CoMPMStR

##### Share on other sites

Hey hazard.. how would you play a mp3 or wav file. I got something working(my.computer.audio.play) and it plays wav sounds. But only pcm wav ( which is like windows wav file) if i try to play other wav than a sound from windwos i get an error. Also i tried wmp.dll and that did not work... so you know any way to play a mp3 or wav file other than my.computer.audio.play

`Dim wav As New System.Media.SoundPlayerwav.SoundLocation = "filename.wav"wav.Play()`

Enjoy!

Thanks can you play mp3s?

*********EDIT THIS DOESNT WORK

IT gives me an error just like other one. IT can only play PCM wave files

ALso i think this is the same thing as doing my.computer.audio.play("FILE.wav")

I don't know what else to suggest except get an audio converter to convert the wav files to a valid format.

EDIT:

I suppose you could use the managed directx to play mp3 files.

You could also just use google to see what else there is to find.. http://www.google.com/search?hl=en&q=vb+net+play+mp3

Well i tried using wmp.dll as a reference in vb. But when i load the script it says wmplib.dll ( or something like that) could not be loaded or found. I coppied it from my bin folder when i built it. Ill try a mp3 with manageddx now.. I think i got it *****EDIT: Hmm maybe it was just my wav files that were messed up because most of them work now wiht my.com.audio.play

Edited by boomer678

##### Share on other sites

NEW VERSION:

GTAIV .Net Script Hook v0.85 BETA

Changes in Version 0.85 BETA:

- fixed serveral bugs in the new threading architecture

- fixed all reported AccessViolations

- fixed custom cameras. they work now as intended.

- added ScriptCommands to allow communication between scripts (see the included ScriptCommunication example)

- added easy settings (ini) file support (just access "Settings" in your scripts)

- added ability to catch dialed phone numbers in scripts (PhoneNumberDialed & BindPhoneNumber)

- added "ScriptHelp" console command, which displays general info and bound console commands of scripts.

- added more functions to the Graphics class.

- you can scroll in the console now using the PageUp/Down keys (hold Shift to get to start/end immediately)

- use Shift + NumpadPlus/Minus to grow/shrink the console

- more stuff, as usual

##### Share on other sites

NEW VERSION:

GTAIV .Net Script Hook v0.85 BETA

Changes in Version 0.85 BETA:

- fixed serveral bugs in the new threading architecture

- fixed all reported AccessViolations

- fixed custom cameras. they work now as intended.

- added ScriptCommands to allow communication between scripts (see the included ScriptCommunication example)

- added easy settings (ini) file support (just access "Settings" in your scripts)

- added ability to catch dialed phone numbers in scripts (PhoneNumberDialed & BindPhoneNumber)

- added "ScriptHelp" console command, which displays general info and bound console commands of scripts.

- added more functions to the Graphics class.

- you can scroll in the console now using the PageUp/Down keys (hold Shift to get to start/end immediately)

- use Shift + NumpadPlus/Minus to grow/shrink the console

- more stuff, as usual

##### Share on other sites
Hey hazard.. how would you play a mp3 or wav file. I got something working(my.computer.audio.play) and it plays wav sounds. But only pcm wav ( which is like windows wav file) if i try to play other wav than a sound from windwos i get an error. Also i tried wmp.dll and that did not work... so you know any way to play a mp3 or wav file other than my.computer.audio.play

`Dim wav As New System.Media.SoundPlayerwav.SoundLocation = "filename.wav"wav.Play()`

Enjoy!

Thanks can you play mp3s?

*********EDIT THIS DOESNT WORK

IT gives me an error just like other one. IT can only play PCM wave files

ALso i think this is the same thing as doing my.computer.audio.play("FILE.wav")

I always use BASS.DLL, to play wav or mp3 or tracker files. http://www.un4seen.com/

##### Share on other sites

I thought the phonenumber thing was impossible atm?

##### Share on other sites

Im getting this error when I press . to spawn something

2009-02-17 13:01:27 - STARTING SCRIPTS...

2009-02-17 13:01:27 - ...successfully started script 'SuperSpawnerScript.CoMPMStR0'!

2009-02-17 13:04:09 - Error during Tick in script 'SuperSpawnerScript.CoMPMStR0':

at SuperSpawnerScript.CoMPMStR0.1(Single A_0, Single A_1)

at SuperSpawnerScript.CoMPMStR0.6(Int32 A_0)

at SuperSpawnerScript.CoMPMStR0.0(Keys A_0)

at GTA.Script.ProcessEvents()

at GTA.Script.DoTick()

Can someone help?

Cheers

##### Share on other sites
Im getting this error when I press . to spawn something

2009-02-17 13:01:27 - STARTING SCRIPTS...

2009-02-17 13:01:27 - ...successfully started script 'SuperSpawnerScript.CoMPMStR0'!

2009-02-17 13:04:09 - Error during Tick in script 'SuperSpawnerScript.CoMPMStR0':

at SuperSpawnerScript.CoMPMStR0.1(Single A_0, Single A_1)

at SuperSpawnerScript.CoMPMStR0.6(Int32 A_0)

at SuperSpawnerScript.CoMPMStR0.0(Keys A_0)

at GTA.Script.ProcessEvents()

at GTA.Script.DoTick()

Can someone help?

Cheers

I think Model.Getname is removed, it didnt work before.

HazzardX told me this:

@Intosia: I never tried it. Just included it because the related native function sounded fitting. The problem is that models are given as hash-codes of the name. Turning the hashcode into the full name again is not possible unless the game provides such a function for known model names.

##### Share on other sites

hi, i'm trying to figure out the relationship of the two parameters of Vehicle.ApplyForce(Vector3,Vector3)

i assign only one positive number within the two Vector3 and gets the combination below.

`----------------------------------------------------------         |                RotationDirection ------------------------------------------------         |     x      |       y       |       z----------------------------------------------------------   x     | turn right | turn right    | roll right----------------------------------------------------------   y     | turn left  | go forward    | roll forward----------------------------------------------------------   z     | roll left  | roll backward | jump up straight----------------------------------------------------------`

i don't quite understand the results, could anyone help?

##### Share on other sites

i don't quite understand the results, could anyone help?

The directions are easy: positive X is right, positive Y it front, positive Z is Up

The rotation parameter just add an additional rotation to the movement. I'm not sure about the axes though. Might be rotation around X, Y and Z axes, or it might be Yaw, Pitch, Roll. Based on your results i guess it is the latter.

##### Share on other sites

- added ability to catch dialed phone numbers in scripts (PhoneNumberDialed & BindPhoneNumber)

Damn it...how?!

I've tried it with the 'GetGlobalValue' (AruHook), but it doesn't work...for me.

Would you like to share some info?

What else should I say...N1 and Rock on!

Auf Wiederhören.

##### Share on other sites
i don't quite understand the results, could anyone help?

The directions are easy: positive X is right, positive Y it front, positive Z is Up

The rotation parameter just add an additional rotation to the movement. I'm not sure about the axes though. Might be rotation around X, Y and Z axes, or it might be Yaw, Pitch, Roll. Based on your results i guess it is the latter.

the result of direction is obvious.

for the rotation, maybe is the latter, but i just can't figure out a rule or pattern to explain the results.. any way thanks for the reply.

yeah, i'm trying to make an RC control Mod which enable Niko to remote control a car. so i also want to know is there a way to steer, if can't, i'll try to make a driver inside and call DriveTo()..

ps: i got System.AccessViolationException when calling Game.CurrentCamera.LookAt(Vehicle/Vector3), haven't tried the Ped overload version.

##### Share on other sites

My teleport script is almost working again. LoadEnvironmentNow produces protected memory errors.

Also Object.Position sometimes causes crashes, at least for me.

`                      System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.                        at NativeInvoke.Invoke<unsigned int,int,float,float,float>(SByte* , Int32 , Single , Single , Single )                        at GTA.Object.set_Position(Vector3 value)`

I don't know why Model.Name was removed. It has always worked for me, the way I used it. Model.ToString returns the hash so that won't help. I guess I have to find another way to display the model names.

Another thing, what is the purpose for World.TriggerCollisionsAt? Does that method only load the world collisions at the specified coords? Is there a way we can check if any other entities are located at a position?

EDIT:

Is there any way to read the CurrentRoom to an integer or string?

Edited by CoMPMStR

##### Share on other sites

I just made a little minigame type thing which saves your highscore.

Basically its a speedbomb. You turn it on and once you go above 30 mph ( or something like that ) you cant go below 30 or you blow up :\. Also if you bail you blow up. The timer starts counting when the bomb is armed(once u hit the speed) and stops when you blow up. It saves your highscore to a txt file. Also when u set it. It plays GTAIV music, (got it from loading.rpf). I will release it with my other mod

##### Share on other sites
Model.ToString returns the hash so that won't help.

yeah, aru's project have a enum eModel stores the name and hash, parsing that should be easy.

##### Share on other sites
Model.ToString returns the hash so that won't help.

yeah, aru's project have a enum eModel stores the name and hash, parsing that should be easy.

sure, but it only contains a few hundred of the more than 10000 models. And an enum with more than 10000 entries wouldn't be a solution, too.

@boomer678: This sounds really great! The speedbomb minigames in the older GTA games were always a lot of fun. You got the music from loading.rpf? You are not allowed to redistribute original game files in your mods, just as little legal notice.

@CoMPMStR: LoadEnvironmentNow and Object.Position will be fixed in the next version.

I can also make that Model.ToString returns the name of the Model if you have created the model in your script by name, otherwise it will return the hexcode. I won't include a Model.Name until there is a reliable way to get the name for all models.

World.TriggerCollisionsAt just triggers collisions if there are objects that haven't checked for collisions yet... at least i think so.

Sorry for the breaking changes again. the next version 0.86 will (AGAIN) have lots of breaking changes because i changed all script events like KeyDown and Tick and so on to be actual events. I usually wait with new releases until i've got enough interesting changes in it, but i might release the version now already. This way you would have to update your mod only once.

##### Share on other sites

I say release it I indeed didnt switch the new version yet.

##### Share on other sites
And an enum with more than 10000 entries wouldn't be a solution, too.

i changed all script events like KeyDown and Tick and so on to be actual events.

maybe index & rehash it and store as static resource?

##### Share on other sites

Hey hazard and compmstr.. any way to play game music without having to get it from sparkiv( thats illegal if i put it in my mod and release it)?? i sent u a pm but anyway to

##### Share on other sites
Model.ToString returns the hash so that won't help.

yeah, aru's project have a enum eModel stores the name and hash, parsing that should be easy.

sure, but it only contains a few hundred of the more than 10000 models. And an enum with more than 10000 entries wouldn't be a solution, too.

@boomer678: This sounds really great! The speedbomb minigames in the older GTA games were always a lot of fun. You got the music from loading.rpf? You are not allowed to redistribute original game files in your mods, just as little legal notice.

@CoMPMStR: LoadEnvironmentNow and Object.Position will be fixed in the next version.

I can also make that Model.ToString returns the name of the Model if you have created the model in your script by name, otherwise it will return the hexcode. I won't include a Model.Name until there is a reliable way to get the name for all models.

World.TriggerCollisionsAt just triggers collisions if there are objects that haven't checked for collisions yet... at least i think so.

Sorry for the breaking changes again. the next version 0.86 will (AGAIN) have lots of breaking changes because i changed all script events like KeyDown and Tick and so on to be actual events. I usually wait with new releases until i've got enough interesting changes in it, but i might release the version now already. This way you would have to update your mod only once.

Yea its fun. It has easy, medium and hard. And sorry i didnt know it was illegal. But anyway to play music without having to get it from .rpf.. and is tada.wav ok? lol i found it somewhere on the internet

##### Share on other sites

Well, I was trying to see what World.TriggerCollisionsAt is used for and found out it causes some of those access violation script errors.

Shouldn't GetOffsetPosition be determined in world coords and not by heading, or is there another function for that?

For example, if you are standing at 100, 100, 100 with a heading of 180 and you call GetOffsetPosition(New Vector3(0, 1, 0)), shouldn't the result be 100, 101, 100 instead of 100, 99, 100? That's just the way I assumed it would be used, I came up with another way to get the offset position based on heading.

Also, do you think it's possible to add support for multiplying 2 vector3 variables, instead of multiplying each coord individually? For example, Dim vect As Vector3 = Player.Character.Velocity : vect *= New Vector3(5, 5, 5). I figured it should be available since you can add and subtract the same way, maybe even divide too.

##### Share on other sites

Also, do you think it's possible to add support for multiplying 2 vector3 variables, instead of multiplying each coord individually?

yeah, but both dot and cross multiply take two vectors, and only diff by return type, and it's not possible to overload a method only diff by return type.

maybe you can implement an extention method atm:

`namespace GTA{   public static class Vector3Extension   {       public static Vector3 CrossMultiply( this Vector3 v1, Vector3 v2 )       {           var x = v1.Y * v2.Z - v2.Y * v1.Z;           var y = v2.X * v1.Z - v1.X * v2.Z;           var z = v1.X * v2.Y - v2.X * v1.Y;           return new Vector3(x, y, z);       }   }}`

then you can use it like Vector3.CrossMultiply(Vector3)

Edited by diryboy

##### Share on other sites

NEW VERSION:

GTAIV .Net Script Hook v0.86 BETA

Changes in Version 0.86 BETA:

- removed Startup from scripts. You can now use all functions and also Wait() inside the constructor.

- Replaced all events that required a method override with actual events, conformant with the .Net standard. (ATTENTION: Most scripts have to be updated now!)

- Updated the examples accordingly. Look at them to see how to apply the changes to your scripts.

- The PhoneNumberDialed event is now also available in game version 1.0.1.0

- some other minor changes

@CoMPMStR: A multiplication of two vectors by it's components wouldn't make much sense in terms of vector mathematics. BUT in your example you are just scaling the vector by 5, this can already be done easily by multiplying the vector with a single value (vect *= 5.0F).

BTW: In the new version Model.ToString will return the model name in any case where Model.Name worked before, otherwise it will return the hexvalue. Room.ToString will now also return an ID (as String). Model and Room both have a FromString function now that can convert the String returned from ToString back into a Model/Room.

Edited by HazardX

##### Share on other sites
NEW VERSION:

GTAIV .Net Script Hook v0.86 BETA

Changes in Version 0.86 BETA:

- removed Startup from scripts. You can now use all functions and also Wait() inside the constructor.

- Replaced all events that required a method override with actual events, conformant with the .Net standard. (ATTENTION: Most scripts have to be updated now!)

- Updated the examples accordingly. Look at them to see how to apply the changes to your scripts.

- The PhoneNumberDialed event is now also available in game version 1.0.1.0

- some other minor changes

@CoMPMStR: A multiplication of two vectors by it's components wouldn't make much sense in terms of vector mathematics. BUT in your example you are just scaling the vector by 5, this can already be done easily by multiplying the vector with a single value (vect *= 5.0F).

BTW: In the new version Model.ToString will return the model name in any case where Model.Name worked before, otherwise it will return the hexvalue. Room.ToString will now also return an ID (as String). Model and Room both have a FromString function now that can convert the String returned from ToString back into a Model/Room.

Urh... changes always come

##### Share on other sites

NEW VERSION:

GTAIV .Net Script Hook v0.86 BETA

Changes in Version 0.86 BETA:

- removed Startup from scripts. You can now use all functions and also Wait() inside the constructor.

- Replaced all events that required a method override with actual events, conformant with the .Net standard. (ATTENTION: Most scripts have to be updated now!)

- Updated the examples accordingly. Look at them to see how to apply the changes to your scripts.

- The PhoneNumberDialed event is now also available in game version 1.0.1.0

- some other minor changes

the Tick event is a breaking change, i prefer the overriding technique, if we could do nothing with the sender and eventargs.

Edited by diryboy

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×