Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
MadthatModsareDisabled

Using C++ for modding

Recommended Posts

MadthatModsareDisabled

Hello everyone,

 

I apologize if this is in the wrong category.

 

 

I am sort of new to C++ game programming. I have a background in Java, JavaScript, C, Visual Basic 6.0 and some DirectX.

 

This message is actually mostly directed to either Aru or HazardX. I am looking for examples to create menus in GTA IV. I want to create a Trainer that takes advantage of many things such as Spawning, Teleporting, God Mode, Restoring Health, etc.

 

I have been reading through alot of the tutorials, but have not found one on displaying menus yet. I just learned how to display text recently through another users' post. An example is below.

 

I am currently using Microsoft C++ 2008 and have downloaded the program GTA IV ScriptHook for C++. I am editing the thread called CustomerFiberThread.cpp to learn from it. The example I currently have gives a player the option of a car spawner, model player skin, and teleportation.

 

ARU/HazardX: Do you know if you are ever going to support Multiplayer Mods in the future? I understand you are concerned about RockStar's policy. Yet somebody is already creating spawners, etc in Multiplayer.

 

What are some of the good books you have read Aru/HazardX? It would be appreciated also if you can refer me to any websites that provide good examples of mod programming - maybe even possibly ASI compiler programming.

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

       u32 testnumber = 42;PrintHelpWithNumber("NUMBER", testnumber);// Static function below is used in Scripting.hstatic void PrintHelpWithNumber(const ch *gxtName, i32 value) { NativeInvoke::Invoke<scriptVoid>("PRINT_HELP_WITH_NUMBER", gxtName, value); }

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Also can anybody recommend a good game for graphics programming for Microsoft C++ to use in GTA IV?

 

Thanks very much! smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

In the example I mentioned above I am also trying to incorporate a string inside the static function. I only have a short time this morning and started testing some more printing. I am attempting to create multiple vertical rows of text. A menu example is below.

 

1. Car Spawer

2. Object Spawner

3. Model Spawner

4. Teleportation

5. God Mode

 

You get the idea. The script example I have only produces numbers. Also how can you reposition the X, Y variables to move the text around so it can be positioned vertically as in my example above. The tested beta code I have for text number printing also doesn't show all 3 numbers. It only shows a "3" when I run the game and press F1. I would submit the code, but I am just modifying an example and I don't want people to think I am using someone else's code. Rather I am learning from it, as all open source coders do. Here's the modified program.

 

 

 	u32 testnumber1 = 1; 	u32 testnumber2 = 2; 	u32 testnumber3 = 3; 	PrintHelpWithNumber("NUMBER", testnumber1); 	PrintHelpWithNumber("NUMBER", testnumber2); 	PrintHelpWithNumber("NUMBER", testnumber3);

 

 

Perhaps I will have to modify the PrintHelpWithNumber static function. It would be better to have another static function that creates both strings and text. Does anyone have any examples for this?

 

Thanks again.

 

 

Aru / HazardX you guys rock! Keep the world as an open source environment as it was in the early days of programming. smile.gif

Share this post


Link to post
Share on other sites
zBobG

I would like an example of displaying a menu as well. Here are some native functions for displaying text at a [x, y] position. Sorry, I do not have good documentation for any of them.

 

 

static void DisplayTextWith2Numbers(f32 x, f32 y, const ch *gxtName, i32 number1, i32 number2) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_2_NUMBERS", x, y, gxtName, number1, number2); }static void DisplayTextWithFloat(f32 x, f32 y, const ch *gxtName, f32 value, u32 unknown) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_FLOAT", x, y, gxtName, value, unknown); }static void DisplayTextWithLiteralString(f32 x, f32 y, const ch *gxtName, const ch *literalStr) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_LITERAL_STRING", x, y, gxtName, literalStr); }static void DisplayTextWithNumber(f32 x, f32 y, const ch *gxtName, i32 value) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_NUMBER", x, y, gxtName, value); }static void DisplayTextWithString(f32 x, f32 y, const ch *gxtName, const ch *gxtStringName) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_STRING", x, y, gxtName, gxtStringName); }static void DisplayTextWithTwoLiteralStrings(f32 x, f32 y, const ch *gxtName, const ch *literalStr1, const ch *literalStr2) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_TWO_LITERAL_STRINGS", x, y, gxtName, literalStr1, literalStr2); }static void DisplayTextWithTwoStrings(f32 x, f32 y, const ch *gxtName, const ch *gxtStringName1, const ch *gxtStringName2) { NativeInvoke::Invoke<scriptVoid>("DISPLAY_TEXT_WITH_TWO_STRINGS", x, y, gxtName, gxtStringName1, gxtStringName2); }

 

 

Use "STRING" (with the quotes) for gxtName, use (pass) a string for literalStr.

[x, y] is a float in the range 0 to 1 which means it is a position at a decimal percent of the display.

 

Here is a simple example:

 

function DisplayText(txt, x, y) DISPLAY_TEXT_WITH_LITERAL_STRING(x, y, "STRING", txt)end

 

Displays the (string) txt at position (float) [x, y].

 

I think these functions only display for ONE frame, I don't know how to make it display continuously - [EDIT] display it every frame. I guess. I've used this to 'blink' text.

 

Some useful utility functions:

 

static void SetTextBackground(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_BACKGROUND", p0); }static void SetTextCentre(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_CENTRE", p0); }static void SetTextColour(ScriptAny p0, ScriptAny p1, ScriptAny p2, ScriptAny p3) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_COLOUR", p0, p1, p2, p3); }static void SetTextDrawBeforeFade(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_DRAW_BEFORE_FADE", p0); }static void SetTextDropshadow(ScriptAny p0, ScriptAny p1, ScriptAny p2, ScriptAny p3, ScriptAny p4) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_DROPSHADOW", p0, p1, p2, p3, p4); }static void SetTextEdge(ScriptAny p0, ScriptAny p1, ScriptAny p2, ScriptAny p3, ScriptAny p4) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_EDGE", p0, p1, p2, p3, p4); }static void SetTextFont(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_FONT", p0); }static void SetTextJustify(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_JUSTIFY", p0); }static void SetTextLineDisplay(ScriptAny p0, ScriptAny p1) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_LINE_DISPLAY", p0, p1); }static void SetTextLineHeightMult(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_LINE_HEIGHT_MULT", p0); }static void SetTextProportional(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_PROPORTIONAL", p0); }static void SetTextRenderId(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_RENDER_ID", p0); }static void SetTextRightJustify(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_RIGHT_JUSTIFY", p0); }static void SetTextScale(ScriptAny p0, ScriptAny p1) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_SCALE", p0, p1); }static void SetTextToUseTextFileColours(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_TO_USE_TEXT_FILE_COLOURS", p0); }static void SetTextUseUnderscore(ScriptAny p0) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_USE_UNDERSCORE", p0); }static void SetTextWrap(ScriptAny p0, ScriptAny p1) { NativeInvoke::Invoke<scriptVoid>("SET_TEXT_WRAP", p0, p1); }

 

Particularly Color, Font and Scale. Sorry, I don't have good documentation for these either.

 

These are from scripting.h and scriptingDirty.h as documented for the C++ scripthook. I would think you already had these available to you.

 

I don't know if any of this will help. I would also like to know how to draw a menu, I'm sure it's not that complicated but I'm not all that interested anymore in doing my own Mod stuff.

Edited by zBobG

Share this post


Link to post
Share on other sites
Intosia

Setting font/color/size and stuff is possible with the .NET Hook. Dont know if you want to use that? Or ask Hazzard how he done it.

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Thanks for the examples. However how do I invoke one of these static functions inside a loop? Here's the example script I'm using it from.

 

Keep in mind I need a C++ example please.

 

 

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: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_F5) & 1) != 0) 	{   LogInfo("Spawning a random car");   Ped ped;   Vehicle vehicle;   u32 modelHash;   ScriptAny unknown;   Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   GetPlayerChar(playerIndex, &ped);   f32 x,y,z;   GetCharCoordinates(ped, &x, &y, &z);   GetRandomCarModelInMemory(1, &modelHash, &unknown);   CreateCar(modelHash, x, y, z, &vehicle, true); 	}

 

 

The function call should be situated somewhere between the LogInfo call or at the end of the loop. I don't know how to call a function within the loop as you gave me in your example.

 

Maybe you could create a loop to show me since I'm new at this?

 

Thanks. smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
Intosia
Thanks for the examples. However how do I invoke one of these static functions inside a loop? Here's the example script I'm using it from.

 

Keep in mind I need a C++ example please.

 

 

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: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_F5) & 1) != 0) 	{   LogInfo("Spawning a random car");   Ped ped;   Vehicle vehicle;   u32 modelHash;   ScriptAny unknown;   Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   GetPlayerChar(playerIndex, &ped);   f32 x,y,z;   GetCharCoordinates(ped, &x, &y, &z);   GetRandomCarModelInMemory(1, &modelHash, &unknown);   CreateCar(modelHash, x, y, z, &vehicle, true); 	}

 

 

The function call should be situated somewhere between the LogInfo call or at the end of the loop. I don't know how to call a function within the loop as you gave me in your example.

 

Maybe you could create a loop to show me since I'm new at this?

 

Thanks. smile.gif

Please, if you dont know C++ or know how the C++ Hook works, why dont u use the .NET Hook? Saves you ALOT of trouble...?

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

I want to learn C++ as I already know Visual Basic. That is my goal here and why I am reading Aru's posts.

 

I'm also aware of how powerful C++ is.

 

Besides I can't get the .Net Script Hook version to work.

 

Thanks again.

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
zBobG
Besides I can't get the .Net Script Hook version to work.

Me neither. Also, I think the .NET scripthook is not available for v1.0.3.0 yet.

 

Sorry, my previous example was an Alice example because it was easy to find and understand (for me).

 

Make sure the following definition is in a whatever.h file, usually this would be in the scripting.h file (it already is but check it anyway). Use the full definition that defines the native function (I've just included the short version).

 

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

 

In the code just fill in the function:

 

if ((GetAsyncKeyState(VK_F5) & 1) != 0) {  LogInfo("Spawning a random car");  DisplayTextWithLiteralString(0.1, 0.1, "STRING", "Spawning a random car")  Ped ped;  Vehicle vehicle;  u32 modelHash;  ScriptAny unknown;  Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());  GetPlayerChar(playerIndex, &ped);...

 

You can of course define x and y and the text as variables then set them to something before using the function then pass the variable instead of a literal value.

 

[EDIT] I'm still not absolutely sure that this will work as intended. If the function only draws once per frame (not sure about that) then something else has to be done to get the text to stay on the screen. You would do this by creating a 'DisplayText' function outside of this loop, which you would call from this loop. That function would execute every tick and draw the text in every frame until you dismissed it (by a timer for example). There is a native function for 'Clearing' text but I don't know how it works or what to use it for. There is also a text 'Fade' function but again I don't know how it works either.

Edited by zBobG

Share this post


Link to post
Share on other sites
sjaak327

To display the text each frame, you need to run the relevant commands in the run tick event and control it with a bool, that's how I build my menus as well.

 

 

If (blahblahblah==true){SetTextScale(0.30f,0.22f);DisplayTextWithLiteralString(0.50f,0.01f,"STRING","Y=");}

 

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Thanks guys for pointing me in the right direction. I finally found a text message display that works. The script is below.

 

 

PrintStringWithLiteralStringNow("CP_MAX_2", "Spawn a magic comet",7500,1);

 

 

I'm on my journey to program some cool mods and eventually a trainer!

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

My next goal after I create the menus would be to learn how to spawn pedestrians and world objects (skate ramp, etc). Keep in mind everyone I am looking for example scripts in C++ only?

 

Thanks guys. smile.gif

Share this post


Link to post
Share on other sites
Intosia

Browse through the C++ HOOK topic, there are alot of code examples...

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

I just purchased two books today on C++ (although neither one is good for gaming). confused.gif

 

The first one is called Sams Teach Yourself C++ in one hour a day.

 

The second one is titled Ivor Horton's Beginning Visual C++ 2008.

 

Not sure how good they are.

 

I was also talking to the Sales Rep at Fry's Electronics and he is going to try to put a book on backorder for me. He saw one that was discounted and is a game instructional guide in C++. That one should be interesting.

 

Anybody else know any good sites for C++ gaming, especially understanding how to make these mods work effectively for GTA IV?

 

I'm working on trying to create an object spawner now. I found an example in on this site, but I couldn't get the program to work. My code is listed below: (excuse any misunderstandings with the language as I am new at this). The program is not mine, I am just modifying it. I will definitely give credit to its owner.

 

Also another issue I'm having is I want to spawn the Annihilator(helicopter). The message prints, but the helicopter never spawns.

 

Obviously some bugs I need to work on.

 

My handle name on GTA IV is StevorNtheHouse. (for those who know me) colgate.gif

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Here's NativeThread.h

 

 

#pragma once#include "Types.h"#include "GameTypes.h"#include "NativeThread.h" //class NativeThread : protected GameTypes::GtaThread{private:GameTypes::GtaThread *m_pOriginalThread;i32 m_nThreadIndex;protected:ch m_szThreadName[24];GameTypes::eThreadState Reset(u32 scriptHash, ptr pArgs, u32 argCount);GameTypes::eThreadState Run(u32 opsToExecute);GameTypes::eThreadState Tick(u32 opsToExecute);virtual void RunScript() = 0;	// To be overriddenvirtual void RunTick() = 0;  //void Wait(u32 timeMS);  	// Override the Wait native //void TerminateThisScript();  // Override the TerminateThisScript native //b8 IsThreadAlive();  

 

 

 

Below is CustomThread.h

 

 

#pragma once#include "../ScriptHook/NativeThread.h"#include "../ScriptHook/ScriptingEnums.h"#include "../ScriptHook/ScriptingTypes.h"class CustomThread : public NativeThread{private:Scripting::Player GetPlayer();Scripting::eModel m_CarModel;Scripting::eModel m_SkinModel;/////////////////Scripting::Ped GetPlayerPed();void SpawnCar(Scripting::eModel model);void SpawnObject(Scripting::eModel model);void ChangePlayerSkin(Scripting::eModel model);/////////////////enum eStateMachine{ StateDefault, StateSpawnCar, StateChangeSkin,};eStateMachine m_State;protected:void RunTick();/////////void RunScript();public:CustomThread();

 

 

Finally here is the main project file CustomThread.cpp

 

 

#include "CustomThread.h"#include "Scripting.h"#include "../ScriptHook/Log.h"#include "../ScriptHook/ScriptHookManager.h"#include <windows.h>// Pull in all our scripting functions/typesusing namespace Scripting;extern CustomThread _customThread;CustomThread::CustomThread(){SetName("CustomThread");m_State = StateDefault;}Player CustomThread::GetPlayer(){Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());return playerIndex;}Scripting::Ped CustomThread::GetPlayerPed(){Ped ped;GetPlayerChar(GetPlayer(), &ped);return ped;}void CustomThread::SpawnObject(eModel model){RequestModel(model);while(!HasModelLoaded(model)){ Wait(0);}LogInfo("request model");Ped ped = GetPlayerPed();Object object;f32 x,y,z;GetCharCoordinates(ped, &x,&y,&z);CreateObject(model, x, y, z, &object, true);MarkModelAsNoLongerNeeded(model);}void CustomThread::RunScript(){while (IsThreadAlive()){ if ((GetAsyncKeyState(VK_NUMPAD7) & 1) != 0) { 	SpawnObject(MODEL_CJ_BOAT_RAMP); }Wait(100);}}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: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_F5) & 1) != 0) 	{   LogInfo("Spawning a random car");   //DisplayTextWithString(35, 20, "DISPLAY_TEXT_WITH_STRING", "Position over here");   PrintStringWithLiteralStringNow("CP_MAX_2", "Spawning a random car",7500,1);   Ped ped;   Vehicle vehicle;   u32 modelHash;   ScriptAny unknown;   Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   GetPlayerChar(playerIndex, &ped);   f32 x,y,z;   GetCharCoordinates(ped, &x, &y, &z);   GetRandomCarModelInMemory(1, &modelHash, &unknown);   CreateCar(modelHash, x, y, z, &vehicle, true); 	} 	else if ((GetAsyncKeyState(VK_F6) & 1) != 0) 	{   LogInfo("Granting player $5000");   PrintStringWithLiteralStringNow("CP_MAX_2", "Spawning Steve Morrow's Annihilator",7500,1);   m_CarModel = MODEL_ANNIHILATOR;	   RequestModel(m_CarModel);	   //Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   //AddScore(playerIndex, 5000); 	} 	else if ((GetAsyncKeyState(VK_F1) & 1) != 0) 	{   LogInfo("Requested a MODEL_ANNIHILATOR spawn");   PrintStringWithLiteralStringNow("CP_MAX_1", "Spawning the tuga",7500,1);   m_CarModel = MODEL_TUGA;   RequestModel(m_CarModel);   // Change our state so that we can spawn the car when available   m_State = StateSpawnCar; 	}	 	else if ((GetAsyncKeyState(VK_F8) & 1) != 0) 	{   LogInfo("Changing the player skin");   PrintStringWithLiteralStringNow("CP_MAX_2", "Steve's model spawner",7500,1);   //m_SkinModel = MODEL_F_Y_CDRESS_01;   m_SkinModel = MODEL_IG_ROMAN;   RequestModel(m_SkinModel);   // Change our state so that we can change skin when available   m_State = StateChangeSkin; 	} 	else if ((GetAsyncKeyState(VK_F9) & 1) != 0) 	{   LogInfo("Converting the player skin back to Niko's");   //m_SkinModel = MODEL_PLAYER;   m_SkinModel = MODEL_M_M_HELIPILOT_01;   RequestModel(m_SkinModel);   // Change our state so that we can change skin when available   m_State = StateChangeSkin; 	} } 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;case StateChangeSkin:	// Change the player skin when its available { 	if (HasModelLoaded(m_SkinModel)) 	{   LogInfo("Skin model available... spawning it!");   Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());   eInteriorRoomKey roomKey;   Ped ped;   GetPlayerChar(playerIndex, &ped);   GetKeyForCharInRoom(ped, &roomKey);   ChangePlayerModel(playerIndex, m_SkinModel);   GetPlayerChar(playerIndex, &ped);   SetRoomForCharByKey(ped, roomKey);   MarkModelAsNoLongerNeeded(m_SkinModel);   m_State = StateDefault; 	} } break;}}

 

 

I'm currently getting an error message: (compiled output is below):

 

 

1>------ Build started: Project: ScriptHook, Configuration: Debug Win32 ------1>Compiling...1>ScriptHookManager.cpp1>Generating Code...1>Compiling...1>NativeFiberThread.cpp1>NativeThread.cpp1>Generating Code...1>Creating library...1>Build log was saved at "file://c:\GTAIV_Aru_ScriptHook\103\ScriptHook\Debug\BuildLog.htm"1>ScriptHook - 0 error(s), 0 warning(s)2>------ Build started: Project: SampleCustom, Configuration: Debug Win32 ------3>------ Build started: Project: SampleCustomFiber, Configuration: Debug Win32 ------3>Compiling...2>Compiling...3>Main.cpp2>Main.cpp3>Generating Code...2>Generating Code...3>Compiling...3>CustomFiberThread.cpp2>Compiling...2>CustomThread.cpp3>Generating Code...2>Generating Code...3>Linking...2>Linking...2>CustomThread.obj : error LNK2019: unresolved external symbol "protected: void __thiscall NativeThread::Wait(unsigned int)" ([email protected]@@[email protected]) referenced in function "private: void __thiscall CustomThread::SpawnObject(enum Scripting::eModel)" ([email protected]@@[email protected]@@@Z)2>CustomThread.obj : error LNK2019: unresolved external symbol "protected: bool __thiscall NativeThread::IsThreadAlive(void)" ([email protected]@@IAE_NXZ) referenced in function "protected: virtual void __thiscall CustomThread::RunScript(void)" ([email protected]@@MAEXXZ)2>C:\GTAIV_Aru_ScriptHook\103\Debug\SampleCustom.dll : fatal error LNK1120: 2 unresolved externals2>Build log was saved at "file://c:\GTAIV_Aru_ScriptHook\103\SampleCustom\Debug\BuildLog.htm"2>SampleCustom - 3 error(s), 0 warning(s)3>Embedding manifest...3>Build log was saved at "file://c:\GTAIV_Aru_ScriptHook\103\SampleCustomFiber\Debug\BuildLog.htm"3>SampleCustomFiber - 0 error(s), 0 warning(s)========== Build: 2 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

 

Any suggestions on what I'm not understanding?

 

Thanks for your feedback smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
sjaak327

You are trying to use wait, and get unresolved externals message, use customfiberthread if you want to use wait.

 

Or better, use the change state functionality in the customthread, there is no need for wait, you change the state, then use hasmodelloaded.

 

Also in case of the chopper, you don't request the state change, you just request the model, but of course it needs to create, add

 

 

m_state=StateSpawnCar

after the requestmodel and the annihilator will spawn.

 

 

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Thanks for the help. Can you provide me some code examples? Remember I am new at this. I was able to figure out where to place:

 

m_state=StateSpawnCar

 

since you stated it clearly.

 

I do not understand how to use CustomerFiberThread.h Do I need to also include this in CustomThread.cpp?I tried that before and the error message went away.

 

However I still couldn't get my object spawner to work.

 

Do you have a good example for an easier object spawner?

 

I appreciate anything you can provide. Feel free to critique my code too.

 

Thanks again. smile.gif

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

C++ programming, you gotta love it. lol

 

Okay I made the changes and added the option to spawn the annihilator.

 

I also added this line to CustomThread.cpp: #include "CustomFiberThread.h"

 

However now I'm getting even greater error messages (time to pick up my book again).

 

 

1>------ Build started: Project: ScriptHook, Configuration: Debug Win32 ------1>Compiling...1>ScriptHookManager.cpp1>c:\gtaiv_aru_scripthook\103\scripthook\scripthookmanager.cpp(52) : error C2039: 'Start' : is not a member of 'NativeThread'1>        c:\gtaiv_aru_scripthook\103\scripthook\nativethread.h(41) : see declaration of 'NativeThread'1>Generating Code...1>Compiling...1>NativeThread.cpp1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(44) : error C2600: 'NativeThread::NativeThread' : cannot define a compiler-generated special member function (must be declared in the class first)1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(45) : error C3861: 'SetName': identifier not found1>        This diagnostic occurred in the compiler generated function 'NativeThread::NativeThread(void)'1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(55) : error C2600: 'NativeThread::~NativeThread' : cannot define a compiler-generated special member function (must be declared in the class first)1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(65) : error C2039: 'SetName' : is not a member of 'NativeThread'1>        c:\gtaiv_aru_scripthook\103\scripthook\nativethread.h(41) : see declaration of 'NativeThread'1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(67) : error C2065: 'm_szThreadName' : undeclared identifier1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(115) : error C2039: 'Start' : is not a member of 'NativeThread'1>        c:\gtaiv_aru_scripthook\103\scripthook\nativethread.h(41) : see declaration of 'NativeThread'1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(117) : error C2065: 'm_szThreadName' : undeclared identifier1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(135) : error C2065: 'm_pOriginalThread' : undeclared identifier1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(136) : error C2065: 'm_nThreadIndex' : undeclared identifier1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(139) : error C2673: 'Start' : global functions do not have 'this' pointers1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(141) : error C2065: 'm_szThreadName' : undeclared identifier1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(142) : error C3861: 'Reset': identifier not found1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(147) : error C2065: 'm_Context' : undeclared identifier1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(147) : error C2228: left of '.ThreadId' must have class/struct/union1>        type is ''unknown-type''1>c:\gtaiv_aru_scripthook\103\scripthook\nativethread.cpp(152) : error C2509: 'Kill' : member function not declared in 'NativeThread'1>        c:\gtaiv_aru_scripthook\103\scripthook\nativethread.h(41) : see declaration of 'NativeThread'1>Generating Code...1>Compiling...1>NativeFiberThread.cpp1>Generating Code...1>Build log was saved at "file://c:\GTAIV_Aru_ScriptHook\103\ScriptHook\Debug\BuildLog.htm"1>ScriptHook - 16 error(s), 0 warning(s)2>------ Build started: Project: SampleCustom, Configuration: Debug Win32 ------3>------ Build started: Project: SampleCustomFiber, Configuration: Debug Win32 ------3>Compiling...2>Compiling...3>Main.cpp2>CustomThread.cpp2>c:\gtaiv_aru_scripthook\103\samplecustom\customthread.cpp(21) : error C2259: 'CustomThread' : cannot instantiate abstract class2>        due to following members:2>        'void GameTypes::scrThread::Kill(void)' : is abstract2>        c:\gtaiv_aru_scripthook\103\scripthook\gametypes.h(111) : see declaration of 'GameTypes::scrThread::Kill'2>c:\gtaiv_aru_scripthook\103\samplecustom\customthread.cpp(25) : error C3861: 'SetName': identifier not found2>c:\gtaiv_aru_scripthook\103\samplecustom\customthread.cpp(129) : error C2065: 'm_state' : undeclared identifier2>c:\gtaiv_aru_scripthook\103\samplecustom\customthread.cpp(133) : error C2143: syntax error : missing ';' before '}'2>Generating Code...2>Compiling...2>Main.cpp3>Generating Code...3>Compiling...3>CustomFiberThread.cpp2>c:\gtaiv_aru_scripthook\103\samplecustom\main.cpp(20) : error C2259: 'CustomThread' : cannot instantiate abstract class2>        due to following members:2>        'void GameTypes::scrThread::Kill(void)' : is abstract2>        c:\gtaiv_aru_scripthook\103\scripthook\gametypes.h(111) : see declaration of 'GameTypes::scrThread::Kill'2>Generating Code...2>Build log was saved at "file://c:\GTAIV_Aru_ScriptHook\103\SampleCustom\Debug\BuildLog.htm"2>SampleCustom - 5 error(s), 0 warning(s)3>c:\gtaiv_aru_scripthook\103\samplecustomfiber\customfiberthread.cpp(26) : error C3861: 'SetName': identifier not found3>Generating Code...3>Build log was saved at "file://c:\GTAIV_Aru_ScriptHook\103\SampleCustomFiber\Debug\BuildLog.htm"3>SampleCustomFiber - 1 error(s), 0 warning(s)========== Build: 0 succeeded, 3 failed, 0 up-to-date, 0 skipped ==========

 

 

Any ideas how bad I screwed this up? cry.gif

 

Thanks as always. smile.gif

Share this post


Link to post
Share on other sites
Intosia

Amean this can take AGES! You got 2 books, start learning! First make simple Windows programs. Learn how .h files and .cpp files work, how they connect. Learn about Public and Private. Learn about Overriding and Inheritance. Ow and OOP (Object Oriented Programming) (Classes), and Pointers (gotta love pointers)... THEN start using the C++ Hook, its useless trying fix errors if you dont know that you're doing... Im not trying to piss you off, but C++ is a difficult language with ALOT of wierd things, you cant just dive in half way, start at the beginning!

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Thanks. The second book I have seems to focus more on creating Windows 32 applications. Is that good for gaming or at least on the right track? Its a 1318 pages. I'm assuming that's extensive enough to get me where I want to in C++ and eventually making a killer trainer for GTA IV.

 

No you didn't tick me off since I don't bother easily. Rather I keep an open mind.

 

Thanks again. smile.gif

Share this post


Link to post
Share on other sites
Intosia

I suggest starting with a shorter book, like the 'in one hour' book. Its good for the basics. Then you can take the other book for more in-depth info.

 

Yeah, just go ahead and make some windows or console programs. Learn to make functions and pass pointers and references. Learn the syntax, thats important!

 

 

Share this post


Link to post
Share on other sites
Andrew

Books won't really guide you through to creating a trainer in C++, there might be some websites out there for that. The books will get you started in programming in C++, be it basic windows applications then maybe some networking stuff.

 

Gaming and C++ usally means you want to create a game, as such any books on that will talk about DirectX and creating a game using DirectX and C++.

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

The other book Sams Teach Yourself in ONe Hour a Day is not compatible with Visual C++.

 

 

Keep in mind I'm not brand new to programming. I started with the obvious Basic (years ago). Then I got into Assembly Language programming. Later at the university I took a class on Java, Javascript, HTML, QuickBasic, Visual Basic 6.0. and a short session on C++.

 

In the early 90's I also wrote programs using Cobol 1 and Pascal.

 

I even got my shot at learning DarkBasic for a short time.

 

I've been writing programs since the mid 80's and I've written thousands of them.

 

A little background about my computer education and interests. I started programming back in 1986 on the Atari 65xe (both Basic and Assembly). Then I purchased a Commodore 64 and also learned the same concepts (Basic/ Assembly). I was into big time gaming then and wrote a serious Assembly game on the Atari (took me a year to design). Then I coded one in Assembly on the C64.

 

I'm certain I can pick this up pretty quickly since I have that knowledge and I understand how classes work. When I was enrolled in school me and a friend wrote an ATM simulator in Java. That was complicated and we were the only ones in the class that had it compile successfully. That was awhile ago, but I'm sure I can brush up on the basics again.

 

I learn quickly enough and so far I'm enjoying the book Ivor Horton's Beginning Visual C++ 2008. He's very precise and shows a person how to use the application, etc. Gives very good examples.

 

Thanks for everything you can continue to suggest in my conquest to master C++. colgate.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Gangsta how did you get started in C++ programming?

 

What tips can you provide for a newbie like myself.

 

So far this book is awesome. It reminds me of how we need to go back to the "Hello World" example when learning a new language. Can't wait to see what lies ahead.

 

Thanks! smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Hi Guys, biggrin.gif

 

I've been reading up on arrays in my book and I want to implement an array call into a function, but I"m having a heck of a time. My code is as follows

 

 

void CustomFiberThread::RunScript(){char modobject[][38] = { "MODEL_CJ_BARRIER_10B", "MODEL_CJ_BARRIER_11" };int cnt = 1;// This is a fiber thread, so we use an loop to run the contents of this script.// The thread will terminate when we return from this function.while(IsThreadAlive()){       if ((GetAsyncKeyState(VK_F5) & 1) != 0)       {           LogInfo("Teleporting player to way point"); 	PrintStringWithLiteralStringNow("CP_MAX_1", "Spawning the " << modobject[0] << " object",7500,1);           //TeleportToWaypoint( GetPlayerPed() ); 	//SpawnObject(MODEL_CJ_BOAT_RAMP); 	//SpawnObject(MODEL_CJ_TREE_TRUNKS); 	SpawnObject(MODEL_CJ_BARRIER_10B);//etc

 

 

 

Okay I only want to focus on this line:

 

PrintStringWithLiteralStringNow("CP_MAX_1", "Spawning the " << modobject[0] << " object",7500,1);

 

 

My goal is to print out "Spawing the MODEL_CJ_BARRIER_10B", "MODEL object

by using the PrintStringWithLiteralStringNow function.

 

However I am getting this error:

 

3>c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(173) : error C2296: '<<' : illegal, left operand has type 'const char [14]'

3>c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(173) : error C2297: '<<' : illegal, right operand has type 'char [38]'

 

 

My goal is to eventually spawn any object (in an array list) using

 

 

SpawnObject(MODEL_CJ_BARRIER_10B);

 

 

To do this I will need to create a spawn function for the array mod such as:

 

 

SpawnObject(modobject);

 

 

Can this be done? What am I doing wrong? Please help as I've been at this for 2 hours already! suicidal.gif

 

I appreciate it. smile.gif

Share this post


Link to post
Share on other sites
Intosia

First, you cant join text with '<<' that only works with streams. (If you want to join to chararray you need to use the old StrCat function... Second Char arrays are a wierd thing, and old (from C). I suggest using the String class. Then you can just "test"+var+ "test". But a String is not the some a Char array, but what you can do is convert the string to a chararray but calling its .c_str() function. (Chararray is also called C String)

 

For eg.

 

#include <string>string Test;string Test2;Test2 = Test + " loool";// call a function that needs a char arrayThisisATestFunction(Test2.c_str()  );

 

 

Anyway String are nicer to work with, but need to be converted a Chararray when passing to a function...

 

There are ALOT more things you run into, i got bored of all those things so i started using the .NET hook... .NET takes care of all those things for you.

Edited by Intosia

Share this post


Link to post
Share on other sites
sjaak327

You can also use sprintf_s to convert.

 

net hook is for lazy programmers smile.gif

 

Jut joking..

 

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

That's a great example, but I still can't get it to work with my mod. How to I add this into the line below?

 

I need an example using Visual C++. Thanks. smile.gif

 

 

#include <cstring>char str1[20] = "MODEL_CJ_BARRIER_10B"; PrintStringWithLiteralStringNow("CP_MAX_1", "Spawning the " + str1[1], 7500, 1);

 

 

I'm still getting these error messages. Help! confused.gif

 

2>CustomThread.cpp

3>c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(157) : error C2117: 'str1' : array bounds overflow

3> c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(157) : see declaration of 'str1'

3>c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(157) : error C2117: 'str1' : array bounds overflow

3> c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(157) : see declaration of 'str1'

Share this post


Link to post
Share on other sites
sjaak327

You cannot concatenate text inside the printstring.. function (at least not that I know off),

 

so you need to do any concatenation before you pass the parm to that function.

 

Also use

 

PrintStringWithLiteralString("STRING",text,7500,1)

 

now all you need to do is construct the text parm in the way you want.

 

 

Share this post


Link to post
Share on other sites
Hergonan

 

#include <cstring>char str1[20] = "MODEL_CJ_BARRIER_10B";PrintStringWithLiteralStringNow("CP_MAX_1", "Spawning the " + str1[1], 7500, 1);

 

This will not work for two reasons.

"MODEL_CJ_BARRIER_10B" is at least 21 characters.

when you use str1[1] you will get an O, even if you specify a bigger sized array.

also, 7500 is too big. you have to use something between 0 and 1.

0.5 to make it the middle of the screen, for example. also, since you're using floats, add a "f".

use this:

char str1[300] (300, to be sure).

sprintf_s(str1,300,"Spawning the %s","MODEL_CJ_BARRIER_10B");

//I'm not really sure of the arguments for sprintf_s, but when you start typing it in visual c++ you will get the hint.

then

PrintStringWithLiteralStringNow("STRING", str1, 0.1f, 0.1f); // this will make it appear in the top left part of the screen

Share this post


Link to post
Share on other sites
sjaak327

Hmm, no there are no position parms in that function:

 

the 7500 is the number of milliseconds the message is displayed, and it's always displayed at the bottom of the screen.

 

 

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

This example is great Hergonan, but how do I set this inside a do loop? As an example I want to the player to press F5 repeatedly and get different objects.

 

Here's what I have changed so far:

 

 

void CustomFiberThread::RunScript(){// This is a fiber thread, so we use an loop to run the contents of this script.// The thread will terminate when we return from this function.// Will create a option to cycle through objects later by repeating an F5 presswhile(IsThreadAlive()){       if ((GetAsyncKeyState(VK_F5) & 1) != 0)       {     	sprintf_s(str1,300,"Spawning the %s","MODEL_CJ_WRECK_1"); 	PrintStringWithLiteralStringNow("STRING", str1, 0.1f, 0.1f); // this will make it appear in the top left part of the screen 	SpawnObject(MODEL_CJ_WRECK_1); 	// CJ_TREE_TRUNKS - long logs 	// CJ_AB_RIT_S_PILLAR - construction pillar 	// CJ_AB_RITZ_PILLER1 - small historical(greek) pillar 	// CJ_AB_RIT_S_PILLAR2 - small grey pillar 	// CJ_AB_RITZ_PILLER2 - long tall post (size of a small telephone pole) 	// CJ_AB_SOPWIN1 - small window 	// CJ_APPLE_1 - eaten apple core 	// CJ_ARROW - black/grey arrow pointing down (non physical) 	// CJ_B_CAN1 - small can 	// CJ_COM_COUCH_1 - black/grey couch (leather) 	// CJ_BAG_TABLE - table with purses on it 	// CJ_BAGUETTE - long sandwich 	// CJ_BAN - banana peel 	       } else if ((GetAsyncKeyState(VK_F6) & 1) != 0)

 

 

Do you see what I'm trying to accomplish? Thanks for any help. smile.gif

 

Here's a short example:

 

First time F5 is pressed:

 

The MODEL_CJ_WRECK_1 appears

 

Second time it is pressed:

 

The CJ_TREE_TRUNKS appears

 

and so on... smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
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
Sign in to follow this  

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

×

Important Information

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