Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

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

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

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

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

C++ Script Hook


aru
 Share

Recommended Posts

hey

i´ve tried to spawn weapons but nothing happens when i use it dozingoff.gif

 

example:

 

 

 

Ped Niko1;GetPlayerId();if(Niko1.IsValid())GiveWeaponToChar(Niko1, WEAPON_MOLOTOV, 20, X); 

 

 

20 should be the ammo? but what dont know what the X is.

i tried 0, 1 true, false ^^

 

scripting.h is

 

 

static void GiveWeaponToChar(Ped c, eWeapon weapon, u32 ammo, u32 unknown0) { NativeInvoke::Invoke<scriptVoid>("GIVE_WEAPON_TO_CHAR", c, weapon, ammo, unknown0); }

 

 

smile.gif

Link to comment
Share on other sites

^ try:

 

 

Char c;u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId());GetPlayerChar(playerIndex, &c);GiveWeaponToChar(c,WEAPON_MOLOTOV,30000,0);	

 

 

The third parm is indeed ammo.

 

 

Link to comment
Share on other sites

thank u it works smile.gifsmile.gif

 

 

 

but now i have an other problem

 

i made some scripts and everything work

 

but if I send it to 2 friends.. the scripts dont work only at me

 

in the log´s is located ADDRESS 0x00000000

 

 

someone has an idea ?

 

sry for bad english ^^ confused.gif

Edited by WarBall
Link to comment
Share on other sites

I want people to be able to change the input keys in my mod. How would I do this? Do I need to create an INI file and make my mod read from that?

 

Thanks in advance.

 

EDIT:

I'm unable to use my mod while doing a mission. Is anyone else having this issue too?

Link to comment
Share on other sites

 

I want people to be able to change the input keys in my mod. How would I do this? Do I need to create an INI file and make my mod read from that?

 

Thanks in advance.

That's the approach I took smile.gif

 

ini file trainer.ini

 

it has several sections, one is

 

[KeyBindings]GodKeyOn1=163  //God mode On, Default RCTRLGodKeyOn2=112  //God mode On, Default F1

 

 

Which is the keycombination to enable god mode. You can basically include all your keys in this section (I have about 90 smile.gif )

 

Now I declare the GodKeyOn1 and 2 as int. also a bool to control the reading

 

 

int GodKeyOn1,GodKeyOn2;bool Get_Keys;

 

 

I did this in the header, but it's better to do it in the source apparently.

 

in the run tick I have:

 

if (Get_Keys == true) 	{ 	GetKeys(); 	}

 

 

Then in the GetKeys I read the keys as follows:

 

 

void CustomThread::GetKeys(){ DWORD  retval=0;TCHAR  buffer[bUFSIZE]=TEXT("");    TCHAR  buf[bUFSIZE]=TEXT("");    TCHAR* lpPart[bUFSIZE]={NULL};retval = GetFullPathName(TEXT("trainer.ini"),       BUFSIZE,                     buffer,       lpPart);GodKeyOn1 = GetPrivateProfileInt(TEXT("KeyBindings"),TEXT("GodKeyOn1"),VK_RCONTROL,buffer);GodKeyOn2 = GetPrivateProfileInt(TEXT("KeyBindings"),TEXT("GodKeyOn2"),VK_F1,buffer);Get_Keys=false;}

 

 

The first bit of code is to get the current directory and the file name, then each key is read, first parm is the section name in the ini file, the second is the actual keyname, the third is the default value, (in case the ini file cannot be found, it will use these values), the last parameter is the filename and path stored in the buffer.

 

Finally in runtick I have:

 

 

if ((GetAsyncKeyState(GodKeyOn1)&&(GetAsyncKeyState(GodKeyOn2) & 0x8000) != 0)) 	{ 	GodmodeOn(); 	}

 

 

Add a #define BUFSIZE 4096 in your source.

 

Easy smile.gif

Edited by sjaak327
Link to comment
Share on other sites

EDIT:

I'm unable to use my mod while doing a mission. Is anyone else having this issue too?

Maybe it would help if you would tell what exactly doesn't work.

 

I have no problems using options during missions.

 

 

Link to comment
Share on other sites

Hmm... i use hex (0xXX) instead of integers that you use. Does it matter?

 

Thanks for the code tho.

Link to comment
Share on other sites

Hmm... i use hex (0xXX) instead of integers that you use. Does it matter?

 

Thanks for the code tho.

No it doesn't, it's just easier for the users I guess, to use numeric values instead of hex.

 

 

Link to comment
Share on other sites

Thanks for the replies Sjaak smile.gif

 

I'll look into that method you posted, see if I can make it work smile.gif

 

And about the mission-issue... well, it isn't there. Atleast for me. But when I tried my mod at a friend's, it wouldn't work during missions. It could be because he wasn't using Alexander's asi-loader...

Link to comment
Share on other sites

Thanks for the replies Sjaak smile.gif

 

I'll look into that method you posted, see if I can make it work smile.gif

 

And about the mission-issue... well, it isn't there. Atleast for me. But when I tried my mod at a friend's, it wouldn't work during missions. It could be because he wasn't using Alexander's asi-loader...

Well the dll's based on this scripthook of course need an asi loader, all three (xliveless, asi loader and yaasil) will load the dll's.

 

I myself never use xliveless (because of the less), I used to use asi loader, but I have moved to yaasil, as this works correctly in Windows 7, the asi loader is giving me problems on Win 7.

 

 

Link to comment
Share on other sites

I just tried it in an empty scripthook custom source file, works fine for me.

 

 

#include "CustomThread.h"#include "Scripting.h"#include "../ScriptHook/Log.h"#include <windows.h>#define	BUFSIZE 4096// Pull in all our scripting functions/typesusing namespace Scripting;int GodKeyOn1,GodKeyOn2;bool Get_Keys;CustomThread::CustomThread(){SetName("CustomThread");m_State = StateDefault;}void CustomThread::RunTick(){// There should be no infinite loops in this function. If you need to wait for something // to become available, set a local static variable and return. Ideally you would implement// this is as a state machine as follows:if (Get_Keys == true)  {  GetKeys();  }switch(m_State){case StateDefault:	// Default state... check for key presses,      // and do anything that we don't have to wait for 	 	if ((GetAsyncKeyState(VK_F7) & 1) != 0) 	{   LogInfo("Requested a MODEL_BANSHEE spawn");   m_CarModel = MODEL_BANSHEE;   RequestModel(m_CarModel);   // Change our state so that we can spawn the car when available   m_State = StateSpawnCar; 	}	 	else if ((GetAsyncKeyState(GodKeyOn1)&&(GetAsyncKeyState(GodKeyOn2) & 0x8000) != 0)) { GodmodeOn(); } 	 break;case StateSpawnCar:	// Spawn the car model when its available { 	if (HasModelLoaded(m_CarModel)) 	{   LogInfo("Car model available... spawning it!");   Ped ped;   Vehicle vehicle;   f32 x,y,z;   Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   GetPlayerChar(playerIndex, &ped);   GetCharCoordinates(ped, &x, &y, &z);   CreateCar(m_CarModel, x, y, z, &vehicle, true);   MarkModelAsNoLongerNeeded(m_CarModel);   m_State = StateDefault; 	} } break;}}void CustomThread::GetKeys(){DWORD  retval=0;TCHAR  buffer[bUFSIZE]=TEXT("");   TCHAR  buf[bUFSIZE]=TEXT("");   TCHAR* lpPart[bUFSIZE]={NULL};retval = GetFullPathName(TEXT("trainer.ini"),      BUFSIZE,                    buffer,      lpPart);GodKeyOn1 = GetPrivateProfileInt(TEXT("KeyBindings"),TEXT("GodKeyOn1"),VK_RCONTROL,buffer);GodKeyOn2 = GetPrivateProfileInt(TEXT("KeyBindings"),TEXT("GodKeyOn2"),VK_F1,buffer);Get_Keys=false;}void CustomThread::GodmodeOn(){}

 

 

And add

 

void GetKeys();

void GodmodeOn();

 

in the header.

 

 

Link to comment
Share on other sites

I'm a lil bit confused about the ini stuff, because I use just one line and it works fine for me.

 

...#include <windows.h>int customKey = GetPrivateProfileInt("Config", "Key", 117, "./Whatever.ini");...

 

I've also change the character-set settings from unicode to multi-byte, because of the strings. (I'm sooo lazy)

Is there any problem with this way?

 

Peace!

Link to comment
Share on other sites

 

I'm a lil bit confused about the ini stuff, because I use just one line and it works fine for me.

 

...#include <windows.h>int customKey = GetPrivateProfileInt("Config", "Key", 117, "./Whatever.ini");...

 

I've also change the character-set settings from unicode to multi-byte, because of the strings. (I'm sooo lazy)

Is there any problem with this way?

 

Peace!

Well, I used the current path as the documentation told me to use the full path, otherwise it would search in c:\windows, which isn't what I would want, but I guess for the rest this would work as well.

 

Ah I see the ./ signifies the current path, boy I could have spared me that getcurrentpath function smile.gif

 

 

 

Edited by sjaak327
Link to comment
Share on other sites

good info all, ill use this in future projects. for those wondering about the multi byte setting its at

 

Project Properties -> Configuration

Properties -> General -> Character Set

Link to comment
Share on other sites

Edit:

how to spawn anything on your left or right?

it will be a greater effect

what is the param of SetCharAnimSpeed?

Edited by aceship
Link to comment
Share on other sites

Edit:

how to spawn anything on your left or right?

it will be a greater effect

what is the param of SetCharAnimSpeed?

 

case StateSpawnCar:	// Spawn the car model when its available { 	if (HasModelLoaded(m_CarModel)) 	{   LogInfo("Car model available... spawning it!");   Ped ped;   Vehicle vehicle;   f32 x,y,z;   Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   GetPlayerChar(playerIndex, &ped);   GetCharHeading(ped, &heading);   GetCharCoordinates(ped, &x, &y, &z);   float OffsetX;   float OffsetY;   float OffsetZ;   GetOffsetFromCharInWorldCoords(ped, 2.0, 0.0, 0.0, &OffsetX, &OffsetY, &OffsetZ);   //CreateCar(m_CarModel, x, y, z, &vehicle, true);   CreateCar(m_CarModel, OffsetX, OffsetY, OffsetZ, &vehicle, true);   SetCarHeading(vehicle, heading);      MarkModelAsNoLongerNeeded(m_CarModel);   m_State = StateDefault; 	} } break;

 

This is in my mod. Spawns the vehicles always to the right of the player, with the same heading as the player.

GetOffsetFromCharInWorldCoords looks for the world coordinates. (for this function, Y is infront/behind the player, X positive is right, negative is to the left of the player, Z is... above/below the player)

Link to comment
Share on other sites

Thanks it works, so Anyone?

Has make SetCharAnimSpeed working?

or make the speed of char faster?

Link to comment
Share on other sites

Thanks it works, so Anyone?

Has make SetCharAnimSpeed working?

or make the speed of char faster?

Well you could always use:

 

 

Char c; 	u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); 	GetPlayerChar(playerIndex, &c); 	f32 x,y,z; 	f32 x1,y1,z1; 	GetCharVelocity(c,&x,&y,&z); 	x1=x*1.5f; 	y1=y*1.5f; 	z1=z; 	SetCharVelocity(c,x1,y1,z1);

 

 

Link to comment
Share on other sites

Welll. ,I didnt mean the walking speed but the Anim speed

Then try it out for cyring out loud.

 

 

Link to comment
Share on other sites

cryani.gifcryani.gifcryani.gifcryani.gifPlease, This Will Make a Greater Effect To My Script cryani.gifcryani.gifcryani.gifcryani.gif

How to change spawned object direction?

Edited by aceship
Link to comment
Share on other sites

 

cryani.gif  cryani.gif  cryani.gif  cryani.gifPlease, This Will Make a Greater Effect To My Script cryani.gif  cryani.gif  cryani.gif  cryani.gif

How to change spawned object direction?

I help you if you please stop capitalizing every word!

 

Wrong:

Zomg This Is So Annoying!

 

Correct

Zomg this is so annoying!

 

Try it, its even easier!

Link to comment
Share on other sites

sorry,my after effect of scripting

soooooo, how to make a lock and unlock a script?

i make that but make all of my toogleable script running

Link to comment
Share on other sites

sorry,my after effect of scripting

soooooo, how to make a lock and unlock a script?

i make that but make all of my toogleable script running

Just put on big IF around the script...

 

 

Link to comment
Share on other sites

You want to mess my script?

please be serious this time

I am making a new script now

 

How to set Object Heading?

 

Link to comment
Share on other sites

You want to mess my script?

please be serious this time

I am making a new script now

 

How to set Object Heading?

Well im sorry, if you would explain better i can give a better answer confused.gif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

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

×
×
  • Create New...

Important Information

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