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

Intosia
you need to delete the object using object id, not model hash !

 

When you do creatobject (blahblahblah, you pass a reference to the object &object). This object should also be used to delete the object, build an array for all objects you spawn, and then you can delete them all, no need to store x,y,z postions, store the object id's to an array.

A vector is easier!

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

I kind of understand what you mean by building an array for all objects I spawn, but I don't know how to add this array to an object. dontgetit.gif

 

My routine for the object spawner works this way (until I can further understand object arrays).

 

The main loop:

 

 

void CustomFiberThread::RunScript(){int ObjectX = 0;int PedObjectX = 0; char str1[300];char str2[300];char str3[300];char str4[300];char str5[300];char mes1[300];char mod[][38] = { "CJ_FENCE_1_2","CJ_IND_PIPE_4","CJ_AB_RIT_S_PILLAR","CJ_AB_RIT_S_PILLAR2","CJ_AB_SOPWIN1","CJ_AB_SOPWIN2" ,"CJ_AB_SOPWIN3","CJ_ARROW","CJ_COM_COUCH_1" ,"CJ_AB_RITZ_PILLER1","CJ_AB_RITZ_PILLER2","CJ_BAG_TABLE","CJ_AIRCON10","CJ_BEDROOM1_W","CJ_BEER_TABLE_1","CJ_BENCH" ,"CJ_AB_RITZ_PILLER1","CJ_BFAST_J_2","CJ_BARRIER_5","CJ_BILLBRD_1A","CJ_BM_PHONE1","CJ_CHAIR_7","CJ_COMP2_GATE_L" ,"CJ_BILLBRD_1A","CJ_BEDROOM1_W","CJ_BOAT_SURROUND","CJ_CAGE_3","CJ_CARPET_DIRT","CJ_CHINA_GLASS1","CJ_DUMPSTER_1" ,"CJ_FRIDGE_3","CJ_IND_WASHER_5","CJ_IND_WOODPILE_1","CJ_INT_DOOR_12_H","CJ_JOJO_BOX1","CJ_KITCH_1_SINK","CJ_OLD_BOAT_1" ,"CJ_PROC_BRICK3","CJ_SCAFFOLD_03","SCAFFOLD_6","CJ_SHOWER","CJ_CYLINDER","CJ_DM_ARCWAY"};char pedes[][38] = {"CJ_OIL_DRUM","CJ_OIL_DRUM_2","CJ_OIL_DRUM_3","CJ_OIL_DRUM_4" ,"CJ_GAME_CUBE_1","CJ_GAME_CUBE_2","CJ_GAME_CUBE_3","CJ_GAME_CUBE_4","CJ_GAME_CUBE_5","CJ_GAME_CUBE_6" ,"CJ_OIL_TIN_1","CJ_OIL_TIN_2","CJ_PLANE_1","CJ_PLANE_1"}; //***********************************************************************************while(IsThreadAlive()){       if ((GetAsyncKeyState(VK_F5) & 1) != 0)       {           LogInfo("Teleporting player to way point"); 	PrintStringWithLiteralStringNow("STRING", "Press the space bar to spawn object", 7500, 1);   sprintf_s(mes1,300,"Spawning the %s", mod[ObjectX]);   PrintStringWithLiteralStringNow("STRING", mes1, 6000, 1);   ObjectX +=1;   if (ObjectX > 43)   {   	ObjectX = 1;   }   sprintf_s(str1,300,"Spawning the %s", mod[ObjectX]);   PrintStringWithLiteralStringNow("STRING", str1, 6000, 1);   sprintf_s(str2,300,mod[ObjectX]);   SpawnObject(GetModelHash(str2));          }

 

 

When the user presses the F5 key a message is printed about "spawing" then I increment an ObjectX variable. This keeps track of the current object the user has spawned.

 

Next this routine below:

 

 

sprintf_s(str2,300,mod[ObjectX]);

 

 

Creates a string (thanks to help on this forum) that stores the current MODEL in my char list. However I have yet to understand how to point at an enumeration and add it inside my routine.

 

Finally this code:

 

SpawnObject(GetModelHash(str2));

 

 

Calls the SpawnObject function to position the object on the screen. The (GetModelHas(str2)) appears to be locating the correct object.

 

There is another issue I've noticed. Sometimes people online cannot see the object(s) I have spawned. Maybe its the GetModelHash call? The GetModelHash was an example inside Aru's code. That's where I got it from.

 

Am I just making this more complicated than it is? Please go easy as I am still reading up on this stuff. I'm up to Chapter 4 now (Arrays), but I don't see any example for object arrays yet.

 

Can you please provide code examples? That makes it easier for me to comprehend.

 

Thanks! smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
Intosia

MP modding is disabled in the latest C++ hook.....

Share this post


Link to post
Share on other sites
ceedj
True because I am trying to balance the scales between how C++ does something and how the game does another. I will look into Native names later. Lol. I'm having too much fun playing the game already.

 

Also does anybody know how to delete objects? I'm getting alot of complaints about this. I want to show an object and delete it later.

 

If possible could you provide a code sample.

 

Again as always it is appreciated. This is open source and also to anyone who wants to see my code vice versa. smile.gif

As I mentioned, the scripting in IV is largely the same as the previous games. Grab Sanny Builder and load up the main.scm for VC or SA (providing you own them) and read the Coding Bible in the Mission Coding section of this site. It covers things like loading and unloading models, deleting created objects/peds/cars/etc, and all other things about proper GTA coding that you should know.

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Thanks. I am also trying to use the Ragdoll function, but having trouble loading the ScriptingDirty.h header file. I got this error message:

 

2>CustomThread.cpp

3>c:\gta4_script_hookc\103\samplecustomfiber\customfiberthread.cpp(14) : fatal error C1083: Cannot open include file: 'ScriptingDirty.h': No such file or directory

3>Main.cpp

 

My include routines are:

 

 

#include "CustomFiberThread.h"#include "Scripting.h"#include "ScriptingDirty.h"#include "../ScriptHook/ScriptHookManager.h"#include "../ScriptHook/Log.h"#include <cstring>#include <windows.h>

 

 

I need the ScriptingDirty to access this function below:

 

 

void CustomFiberThread::RagdollPlayer(eModel model){RequestModel(model);while(!HasModelLoaded(model)){ Wait(0);}Ped ped = GetPlayerPed();Object obj;f32 x, y, z;GetCharCoordinates(ped, &x, &y, &z - 8);// pass a reference to the objectCreateObject(model, x, y - 5, z - 8, &obj, true); // z - 40, y-80 testing values MarkModelAsNoLongerNeeded(model);SwitchPedToRagdoll(ped, 10000, 20000, 2, 1, 1, 0);  }

 

 

The function as listed in ScriptingDirty.h is below:

 

 

static ScriptAny SwitchPedToRagdoll(ScriptAny p0, ScriptAny p1, ScriptAny p2, ScriptAny p3, ScriptAny p4, ScriptAny p5, ScriptAny p6) { return NativeInvoke::Invoke<scriptAny>("SWITCH_PED_TO_RAGDOLL", p0, p1, p2, p3, p4, p5, p6); }

 

 

The last thing I need to accomplish (for now) is to implement the speed routine. I found this function in the forums.

 

 

void CustomFiberThread::SpeedofPlayer(eModel emodel){//	RequestModel(model);//	while(!HasModelLoaded(model))//	{//  Wait(0);//	}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);}

 

 

PS: The section under Coding Bible is not compatible with Visual C++. Do you know of any tutorials on here to teach GTA IV programming in C++? I already know about the regular (basic) programming section.

 

Thanks for everything guys! smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Can anyone help or provide a suggestion? dontgetit.gifsmile.gif

Share this post


Link to post
Share on other sites
Intosia

Never include Dirty! Find the function you like in Dirty.h and copy it over to Scripting.h in the Fiber folder (here you have EXTRA functions that are not in the hook already). But before you van use them you need to know the parameters! (Thats why they are in Dirty, because 'no-one' knows the parameters...)

Share this post


Link to post
Share on other sites
zBobG
you need to delete the object using object id, not model hash !

 

When you do creatobject (blahblahblah, you pass a reference to the object &object). This object should also be used to delete the object, build an array for all objects you spawn, and then you can delete them all, no need to store x,y,z postions, store the object id's to an array.

A vector is easier!

A C++ vector is the best solution.

 

A vector is a list of 'things', it is a container, the 'things' can be other C++ objects or just ordinary values. The list grows and shrinks without your having to manage it.

 

You could create your GTA4 objects by constructing a C++ object that has the constructor and destructor for a GTA4 object and returns the GTA4 object_ID which you then store into the C++ vector object (stored into the list). To delete the GTA4 object just retrieve the list entry then use the GTA4 object destructor method and delete the list entry (by the list index).

 

Or, using a more sophisticated mechanism, you could have one C++ object which combines both the GTA4 object methods (constructor, destructor etc.) and the list management. Then you could manipulate the GTA4 objects as if they were a simple array of objects using the list's methods.

 

For example:

object_list.object_create(object_name) --> GTA4 object constructor looks up hash --> calls object_list.add --> spawns an object and adds the object ID to the list, returns an index

object_list.object_delete(index) --> calls object_list.destroy(index) -- deletes an object (using that object's destructor) and removes it from the list

(Of course this all depends on how you write the code for the C++ objects.)

 

Destroying the list itself calls the delete method for all objects in the list, you don't need to know anything about the list contents.

You could also code an 'empty_the_list' method that just deletes all the contained objects without destroying the list object itself. A 'clear list' method is (usually) already built into C++ vectors.

Edited by zBobG

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Hey guys,

 

Thanks for all the help. I got a fully functional object and now a ped spawner. I've been adding a lot of new objects and I'm having a new problem.

 

At gtamodding.com there are model hashes. I want to add these objects into my program to spawn them. However it appears they have no physical properties. As an example if I spawn a highway, I cannot drive on it and the helicopter goes through it.

 

Here's my example code. Warning its a little long. I also finally learned how pointers work and found they reduce a lot of the memory consumed by a C++ program.

 

Here's how I access the objects (in a pointer array).

 

 

char* mod[] = { "CJ_AB_PANRACK","CJ_AB_RIT_S_PILLAR","CJ_AB_RIT_S_PILLAR2","CJ_AB_RITZ_PILLER1","CJ_AB_RITZ_PILLER2" ,"CJ_AB_SOPWIN1","CJ_AB_SOPWIN2","CJ_AB_SOPWIN3","CJ_AIRCON10","CJ_AIRCON11","CJ_AIRCON7","CJ_AIRCON8","CJ_AIRCON9" ,"Watertower_LOD1_mh4","TG_Freeway","TG_f_substation","TG_watertower3_LOD01","apartment","CJ_APPLE_SMALL","CJ_ARROW","CJ_ARROW_ICON" ,"CJ_ARROW_ICON_2","CJ_B_CAN1","CJ_B_CAN3","CJ_BAG_TABLE","CJ_BAGUETTE_1","CJ_BAN_1","CJ_BAN_2","CJ_BAN_3","CJ_BAN_4"    ,"CJ_BAN_5","CJ_BAN_6","CJ_BAN_7","CJ_BAN_8","CJ_BANK_DOOR_L","CJ_BANK_DOOR_R","CJ_BANK_MON","CJ_BARRIER_1","CJ_BARRIER_10"   ,"CJ_BARRIER_10B","CJ_BARRIER_11","CJ_BARRIER_11B","CJ_BARRIER_1B","CJ_BARRIER_1C","CJ_BARRIER_2","CJ_BARRIER_3","CJ_BARRIER_4B"

 

 

The section below is when the user presses F1 to spawn an object.

 

 

 

 }// F1 - Spawning an object else if ((GetAsyncKeyState(VK_F1) & 1) != 0) { 	sprintf_s(str1,300,"Spawning the %s", mod[ObjectX]); 	PrintStringWithLiteralStringNow("STRING", str1, 6000, 1); 	sprintf_s(str2,300,mod[ObjectX]); 	SpawnObject(GetModelHash(str2)); }

 

 

Is my problem because I am still using the GetModelHash? There are a lot of objects however that do have physical properties that you can interact with when using GetModelHash. Somebody also mentioned I may want to make this static. I am calling them from an enumeration list that does not appear to be static. Does any of this make sense? dontgetit.gif

 

Below is the example taken from Script Hook project file ScriptingEnums.h

 

 

 MODEL_CJ_AB_PANRACK = 0x328BCBE4, MODEL_CJ_AB_RIT_S_PILLAR = 0x386DD27D, MODEL_CJ_AB_RIT_S_PILLAR2 = 0x76982EC9, MODEL_CJ_AB_RITZ_PILLER1 = 0x3F1FFF92, MODEL_CJ_AB_RITZ_PILLER2 = 0x2862D218, MODEL_CJ_AB_SOPWIN1 = 0x05894A78, MODEL_CJ_AB_SOPWIN2 = 0xDD3D78F5, MODEL_CJ_AB_SOPWIN3 = 0xEED41C22, MODEL_CJ_AIRCON10 = 0xC585300D, MODEL_CJ_AIRCON11 = 0xE5466F8F, MODEL_CJ_AIRCON7 = 0xD2323ECE, MODEL_CJ_AIRCON8 = 0x1C80D36A, MODEL_CJ_AIRCON9 = 0x275CE922, MODEL_Watertower_LOD1_mh4 = 0x2671776F, MODEL_TG_Freeway = 0x58CC40D9, MODEL_TG_f_substation  = 0xE7066D07, MODEL_TG_watertower3_LOD01 = 0xC1722B93, MODEL_TG_watertower3_LOD02  = 0xD35ACF64, MODEL_TG_watertower3_LOD03  = 0xDCFCE2A8,

 

 

As always I appreciate all responses. Also a special thanks to those who have encouraged me to learn more about C++. That has helped save a lot of errors. I'm understanding classes better now to and how a void works with a subroutine call. smile.gif

Share this post


Link to post
Share on other sites
sjaak327

First of all, request collission for objects you spawn. This will get rid of many cases, however not all.

 

 

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Well I'm getting a headache trying to figure out how to check for object collisions. If anyone finds out anything I'd appreciate code examples (makes my life easier). biggrin.gif

 

The next thing I am trying to do is learn to control an object by moving the coordinates around. I want this similar to how it is done like with Construct Mod, however mine won't use a mouse. This is some example code of what I'm trying to accomplish. However as usual it doesn't seem to work right (crashes the game). It compiles with no errors.

 

 

void CustomFiberThread::MoveObjectLeft(eModel model){RequestModel(model);while(!HasModelLoaded(model)) // model = MODEL_ (from enumeration list){ Wait(0);}Ped ped = GetPlayerPed();Object obj; f32 x, y, z;GetCharCoordinates(ped, &x, &y, &z - 8);CreateObject(model, x, y - 5, z - 8, &obj, true); // z - 40, y-80 testing valuesx -=1;MarkModelAsNoLongerNeeded(model); // model = MODEL_}

 

 

The key function:

 

 

// Multiply key - else if ((GetAsyncKeyState(VK_NUMPAD6) & 1) != 0) { 	LogInfo("Pressed a page key"); 	PrintStringWithLiteralStringNow("STRING", "Moving object right",7500,1); 	MoveObjectLeft(GetModelHash(str2)); }

 

 

Another thing I am trying to learn about is the function:

 

 

GetObjectRotationVelocity(Object obj, f32 *pX, f32 *pY, f32 *pZ)

 

 

Any ideas on how this works? Maybe I could learn to rotate it by degrees just like in Construct Mod. I want to use the numpad keys to accomplish this.

 

 

It appears that the x value cannot be used to decrement or increment values within the object. This is still a little confusing. I understand how variables work, but I'm not sure how people are doing this.

 

Any help is welcomed and highly appreciated guys. smile.gif

Edited by MadthatModsareDisabled

Share this post


Link to post
Share on other sites
Zach

 

GetCharCoordinates(ped, &x, &y, &z - 8);

 

 

With the above, you realize you are passing in the address of z minus 8, e.g., if z is at 1000, you are telling the engine to store the value at address 992. Was that you intent? (Sorry..haven't really been following this thread.)

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

I'm okay with using z - 8 or whatever. What I am trying to do is to figure out how to move the object from place to place.

 

As an example:

 

If I press the number 4 key the object should move to the left

If I press the number 6 key the object should move to the right

 

The same will apply for up and down also, which I believe is what the z value is for.

 

My program can spawn object successfully, I just want to be able to have the ability to move them around before spawning them. smile.gif

 

Again any code examples would be most beneficial.

Share this post


Link to post
Share on other sites
Zach
I'm okay with using z - 8 or whatever.

No offense, but if you are "okay with [that]," then you have no business programming in C++ because you have no clue what you are doing. mercie_blink.gifbiggrin.gif

Share this post


Link to post
Share on other sites
MadthatModsareDisabled

Why are you saying that? If you are so good with programming in C++ then provide an example. I don't want to sound mean, but that last comment was offensive to me.

 

I have been programming since I've been 17. I am now 40 and have majored in computer programming. So I know programming like the back of my hand. However I am new to Script Hook and Visual C++. I just want to understand how things work.

 

The z - 8 routine works fine and I can spawn objects so I can see them. I've just having trouble manipulating their coordinates in a loop or whatever. Now I got that example on a gtaforum. If it is incorrect then it was not my design. Rather I learn by reading other people's source code and can get misled this way also.

 

Please don't post here if you are going to put people down. I would never do nor encourage that. That is immature behavior and should not be accepted on these forums.

 

Rather (idea) providing solutions by showing code examples will help anyone in need. After all were you always a great C++ programmer? The answer to that is obvious. I was just ticked by your last reply.

 

I have a working mod too,so please don't tell me I don't know what I'm doing. Provide examples instead and you will make more friends that way.

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.