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

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

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

      1. Events
    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA 6

    3. GTA V

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

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

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

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

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

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

    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. DYOM
      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. 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
    3. Gangs

    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
-Brennan

Vehicle Code Help

Recommended Posts

-Brennan

Looking for a few answers if anyone can help me with my vehicle portion of my menu. I am coding with C++.



Can someone tell me if it is possible to make an array or something with C++ instead of having a code like



if (PegassiZentorno)
{
REQUEST_MODEL(GET_HASH_KEY("ZENTORNO"));
while (!HAS_MODEL_LOADED(GET_HASH_KEY("ZENTORNO"))) WAIT(0);

Vector3 pos = GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER_PED_ID(), 0, 5.0, 0);
Vehicle veh = CREATE_VEHICLE(GET_HASH_KEY("ZENTORNO"), pos.x, pos.y, pos.z, GET_ENTITY_HEADING(PLAYER_PED_ID()), 0, 1);
SET_MODEL_AS_NO_LONGER_NEEDED(GET_HASH_KEY("ZENTORNO"));

PrintBottomLeftNote("Super Car ~g~Spawned!");
return;
}


for every single vehicle in the game. Also I am wondering if anyone has to code to loop spawning in created vehicles only would love to know that one, I have tried using the code below implemented in the spawning code itself but nothing works.



SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), VehicleName, -1);

Would love some help, thank you!


Share this post


Link to post
Share on other sites
Jitnaught

Instead of setting a boolean to spawn a certain vehicle, just set a string to the model of the vehicle you are wanting to spawn, then change the if statement to

if (spawnVehModel != ""){ //spawn veh spawnVehModel = "";}

and of course change the ""ZENTORNO"" strings to "spawnVehModel".

 

SET_PED_INTO_VEHICLE uses a vehicle variable, not the vehicle name.

Edited by LetsPlayOrDy

Share this post


Link to post
Share on other sites
-Brennan

I have tried setting it to



SET_PED_INTO_VEHICLE(PLAYER_PED_ID(), 0, -1);

And I have also tried setting it to



SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), 0, 1);

But neither of them seem to work.



My overall code would look like this:



if (PegassiZentorno)
{
REQUEST_MODEL(GET_HASH_KEY("ZENTORNO"));
while (!HAS_MODEL_LOADED(GET_HASH_KEY("ZENTORNO"))) WAIT(0);

Vector3 pos = GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER_PED_ID(), 0, 5.0, 0);
Vehicle veh = CREATE_VEHICLE(GET_HASH_KEY("ZENTORNO"), pos.x, pos.y, pos.z, GET_ENTITY_HEADING(PLAYER_PED_ID()), 0, 1);
SET_PED_INTO_VEHICLE(PLAYER_PED_ID(), 0, -1);
SET_MODEL_AS_NO_LONGER_NEEDED(GET_HASH_KEY("ZENTORNO"));

PrintBottomLeftNote("Super Car ~g~Spawned!");
return;
}

When I did some messing with the code and changed the native from Any to char * it just messed with my entire teleport into nearest vehicle code


Share this post


Link to post
Share on other sites
Jitnaught

Instead of changing it to char* (I don't know where you got this information or idea of it using a char*), change it to a Ped type, like so:

SET_PED_INTO_VEHICLE(Ped ped, Vehicle vehicle, int seatIndex)

 

Then your code should look like...

	if (PegassiZentorno)	{		REQUEST_MODEL(GET_HASH_KEY("ZENTORNO"));		while (!HAS_MODEL_LOADED(GET_HASH_KEY("ZENTORNO"))) WAIT(0);		Vector3 pos = GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER_PED_ID(), 0, 5.0, 0);		Vehicle veh = CREATE_VEHICLE(GET_HASH_KEY("ZENTORNO"), pos.x, pos.y, pos.z, GET_ENTITY_HEADING(PLAYER_PED_ID()), 0, 1);		SET_PED_INTO_VEHICLE(PLAYER_PED_ID(), veh, -1); //changed 0 to veh		SET_MODEL_AS_NO_LONGER_NEEDED(GET_HASH_KEY("ZENTORNO"));		PrintBottomLeftNote("Super Car ~g~Spawned!");		return;	}

Share this post


Link to post
Share on other sites
-Brennan

Sick that seemed to fix that whole issue, now do you know of a way to make an array or long list like in NativeTrainer for spawning vehicles or is that not possible with C++?


Share this post


Link to post
Share on other sites
Jitnaught

You could look in the NativeTrainer source code to see how it makes arrays...

char* yourArray[] = { "string1", "string2", "string3" };

Share this post


Link to post
Share on other sites
-Brennan

I guess ill have to peek into a little bit when I get spare time to mess around with it, anyway you would be willing to help me out a little bit more I have tried adding you via skype


Share this post


Link to post
Share on other sites
Jitnaught

Why not here?

Share this post


Link to post
Share on other sites
-Brennan

There are 2 codes more that I more related to weapons that im having a hard time getting a grip with


Edited by -Brennan

Share this post


Link to post
Share on other sites
whorse

Why not here?

I second this notion. Just post your questions here. Why do people want to ask long and difficult questions about programming over PMs or skype? You only get one person to respond to you, and if any useful information is posted, only you and the other person will ever see it. Plus, speaking about code over Skype is not exactly the best way of discussing programming. Code is meant to be written down, not talked about over the phone or w/e

 

It just pisses me off when I see a thread where someone knows the answer to what I'm looking for, but the last comment is "Hey I'll PM you" and I never get to find out what it is

  • Like 1

Share this post


Link to post
Share on other sites
-Brennan

Below is a copy of the money gun code I have retrieved from a post here. Bummer is it crashes my game right when I shoot. Any answers as to why?



if (MoneyGun)//broken
{
if (IS_PED_SHOOTING(PLAYER_PED_ID()))
{
float tmp[3];
GET_PED_LAST_WEAPON_IMPACT_COORD(PLAYER_PED_ID(), tmp);
CREATE_AMBIENT_PICKUP(GET_HASH_KEY("PICKUP_MONEY_MED_BAG"), tmp[0], tmp[2], tmp[4], 0, 40000, 1, 0, 1);
}
return;
}

Below is the code for my teleport gun code. For some reason the code only seems to work for a distance of maybe 10 ft. When I try any farther I can see the bullets impact building etc but I don't teleport?



if (TeleportGun)//increase distance
{
if (IS_PED_SHOOTING(PLAYER_PED_ID()))
{
Entity e = PLAYER_PED_ID();
float tmp[6];
GET_PED_LAST_WEAPON_IMPACT_COORD(PLAYER_PED_ID(), tmp);

if (tmp[0] != 0 || tmp[2] != 0 || tmp[4] != 0)
{
SET_ENTITY_COORDS_NO_OFFSET(e, tmp[0], tmp[2], tmp[4] + 0.5f, 0, 0, 1);
}

}
return;
}

Share this post


Link to post
Share on other sites
Jitnaught

Fixed some of the things I saw wrong with them and commented on what I changed. I don't know if I fixed the teleport one, but the money gun should work now.

if (MoneyGun)//hopefully fixed	{		if (IS_PED_SHOOTING(PLAYER_PED_ID()))		{			Vector3 tmp; //use Vector3 instead			GET_PED_LAST_WEAPON_IMPACT_COORD(PLAYER_PED_ID(), &tmp); //get address of tmp using & symbol			CREATE_AMBIENT_PICKUP(GET_HASH_KEY("PICKUP_MONEY_MED_BAG"), tmp.x, tmp.y, tmp.z, 0, 40000, 1, 0, 1); //uses Vector3 now (.x, .y, .z)		}		return;	}
if (TeleportGun)//increase distance (don't know if fixed)	{		if (IS_PED_SHOOTING(PLAYER_PED_ID()))		{			Entity e = PLAYER_PED_ID();			Vector3 tmp; //changed to Vector3			bool foundCoords = GET_PED_LAST_WEAPON_IMPACT_COORD(PLAYER_PED_ID(), &tmp); //declare boolean which receives the return of GET_PED_LAST_WEAPON_IMPACT_COORD, and uses address of tmp			if (foundCoords) //checks if GET_PED_LAST_WEAPON_IMPACT_COORD found coords			{				SET_ENTITY_COORDS_NO_OFFSET(e, tmp.x, tmp.y, tmp.z + 0.5f, 0, 0, 1); //uses Vector3 now			}		}		return;	}

Sorry for not a more descriptive post... it would have taken a lot more time to write out everything than just change the code and comment on it.

Edited by LetsPlayOrDy

Share this post


Link to post
Share on other sites
-Brennan

For the money gun code for some reason the & in the &tmp part says "vector 3* is incompatible with float *" or something along that line and the found coords on the teleport gun is undefined


lol fixed the part sorry the foundcoord and foundcoords were different so I had to fix that but still the &temp it says the vector thing for it

Share this post


Link to post
Share on other sites
Jitnaught

You must have the native set up wrong, make sure it is like this:

static BOOL GET_PED_LAST_WEAPON_IMPACT_COORD(Ped ped, Vector3* coord) { return invoke<BOOL>(0x6C4D0409BA1A2BC2, ped, coord); } // 0x6C4D0409BA1A2BC2 0x9B266079

Share this post


Link to post
Share on other sites
-Brennan

Yeah I was just going to say that I had to change it from float to vector. Now my only issue is still with the teleport gun, still the same issue. Could it be something with my settings? I had a buddy telling me that could be the issue but for some reason when I use Force it still works?


Share this post


Link to post
Share on other sites
Jitnaught

Oh yeah I noticed I misspelled the foundCoords variable, sorry about that, I fixed it. Just rename "foundCoord" to "foundCoords" (if you haven't already).

 

What are you talking about "Force"?

Share this post


Link to post
Share on other sites
-Brennan

GTA Force Menu by Davidp and Racksmile. Im wondering if its because I play in windowed mode or something or depending on the weapon im using?


Share this post


Link to post
Share on other sites
Jitnaught

It could be because of your detail/draw/etc. distance, but I have no clue. Just try changing those distances and using different weapons (like the sniper rifle) to see if it changes the result.

Share this post


Link to post
Share on other sites
-Brennan

Is that within the code or somewhere else within the menu?


Share this post


Link to post
Share on other sites
Jitnaught

The game's settings.

Share this post


Link to post
Share on other sites
-Brennan

oh it would be my actual in game setting?


Share this post


Link to post
Share on other sites
-Brennan

I guess I could say the sniper goes a decent distance but the smgs and such do not.


Share this post


Link to post
Share on other sites
-Brennan

Thanks for all the help my friend!


Share this post


Link to post
Share on other sites
Jitnaught

So it was the weapon that was the problem?

No problem.

Share this post


Link to post
Share on other sites
-Brennan

I couldn't really figure out what to change honestly but the sniper goes a decent distance and that's fine

Share this post


Link to post
Share on other sites
alloc8or

Here's a better and 100% working money gun code.

if (money_gun){	DWORD model = GET_HASH_KEY("prop_money_bag_01");	DWORD PickupHash = GET_HASH_KEY("PICKUP_MONEY_CASE");	if (DOES_ENTITY_EXIST(PLAYER_PED_ID()))	{		if (IS_PED_SHOOTING(PLAYER_PED_ID()))		{			float tmp[6];			GET_PED_LAST_WEAPON_IMPACT_COORD(PLAYER_PED_ID(), (Vector3*)tmp);			if (tmp[0] != 0 || tmp[2] != 0 || tmp[4] != 0)			{				REQUEST_MODEL(model);				while (!HAS_MODEL_LOADED(model)) WAIT(0);				CREATE_AMBIENT_PICKUP(PickupHash, tmp[0], tmp[2], tmp[4], 0, 40000, model, false, true);				SET_MODEL_AS_NO_LONGER_NEEDED(model);			}		}	}}
  • Like 1

Share this post


Link to post
Share on other sites
whorse

 

Here's a better and 100% working money gun code.

if (money_gun){	DWORD model = GET_HASH_KEY("prop_money_bag_01");	DWORD PickupHash = GET_HASH_KEY("PICKUP_MONEY_CASE");	if (DOES_ENTITY_EXIST(PLAYER_PED_ID()))	{		if (IS_PED_SHOOTING(PLAYER_PED_ID()))		{			float tmp[6];			GET_PED_LAST_WEAPON_IMPACT_COORD(PLAYER_PED_ID(), (Vector3*)tmp);			if (tmp[0] != 0 || tmp[2] != 0 || tmp[4] != 0)			{				REQUEST_MODEL(model);				while (!HAS_MODEL_LOADED(model)) WAIT(0);				CREATE_AMBIENT_PICKUP(PickupHash, tmp[0], tmp[2], tmp[4], 0, 40000, model, false, true);				SET_MODEL_AS_NO_LONGER_NEEDED(model);			}		}	}}

that teleports money bags to the spot your bullet last hit, they dont get shot out. And I didn't know that Vector3's could be used like that, thanks. That means that you could declare them like:

Vector3 fwdVector = ENTITY::GET_ENTITY_FORWARD_VECTOR(player);Vector3 forceToApply = {50 * fwdVector.x, 0, 50 * fwdVector.y, 0, 50 * fwdVector.z, 0}; //zeroes to fill in the paddingENTITY::_APPLY_FORCE_TO_ENTITY_2(player, 1, forceToApply.x, forceToApply.y, forceToApply.z, 1, 0, 1, 1);  //push player forward

You could just do this "apply force to entity" with the objects spawned to make them "shoot" out of the player to the last bullet impact. Just change it so x is bulletImpact.x - playerPosition.x, and use the same for Y and Z. If you want it faster, multiply each subtracted coordinate value by 2, or by 0.5 if you want it slower (like "(bulletImpact.y - playerPosition.y) * 0.5"). You can even make them spawn at the gun barrel by using:

if (PLAYER::IS_PLAYER_FREE_AIMING(PLAYER::PLAYER_ID())){	Vector3 wepCoords = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(WEAPON::_GET_CURRENT_PED_WEAPON_ENTITY(PLAYER::PLAYER_PED_ID()), 0, -0.5f, -0.17f); //creds to GeorgeZhang for the offset	Object projectile = OBJECT::CREATE_AMBIENT_PICKUP(pickupHash, wepCoords.x, wepCoords.y, wepCoords.z, 0, 40000, model, false, true);

I got this to shoot the money bags but my character keeps picking most of them up before they can be shot, lol. And most of the ones that do get out disappear in mid air under a second after launch, even if I make them mission entities. Maybe around like 3% of them actually come out like they're supposed to. I havent tried it with anything else yet.

hope this helps

Edited by whorse

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Sign in to follow this  

  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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