|
 |
|
|
|
|
|
GTA Modification Forums
Identify Current/Last Vehicle Entered
 |
|
 |
| |
Billsy93  |
Posted: Tuesday, May 21 2013, 15:26
|
Player Hater

Group: Members
Joined: May 7, 2013

|
Hello, Basically I am trying to create a script (in C++) whereby the player can easily identify the last car they were in upon exiting the vehicle (running off to do something else). The last vehicle entered will have an arrow above it and will appear as a blip on your map and minimap and will be called "Your Car". If you then go on to enter another vehicle, the previous vehicle will be forgotten and the new vehicle will be classed as your new, current vehicle that you are making use of. I have made quite a start and I'm nearly there, however I'm stuck and seek some help, the main problems are that my compiler (Visual Studio) doesn't like the GetDriverOfCar function and its' parameters as well as the fact I'm unsure as to how to get the vehicle ID of my current car in order to add a blip to it so it can be identified once i've exited the vehicle regarding the AddBlipToCar function. Below is the code I have thus far, any help would be appreciated to get this up and running: | CODE | #include "CustomFiberThread.h" #include "Scripting.h" #include "../ScriptHook/Log.h" #include <windows.h>
using namespace Scripting;
CustomFiberThread::CustomFiberThread() { SetName("CarOwnership"); }
void CustomFiberThread::RunScript() { while(IsThreadAlive()) { Blip SavedVehicleBlip; int playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); Ped ped; GetPlayerChar(playerIndex, &ped); Blip SavedVehicleBlip; Vehicle LastVehicle; Vehicle SavedVehicle; Vehicle CurrentVehicle; if ((IsCharInAnyCar(GetPlayerPed()) == true) && (GetDriverOfCar(CurrentVehicle, &GetPlayerPed()) == ped)) { if (SavedVehicle != false) { SetCarAsMissionCar(SavedVehicle, false); SavedVehicleBlip == false; } GetCarCharIsUsing(ped, &CurrentVehicle); StoreCarCharIsInNoSave(playerIndex, &CurrentVehicle); SetCarAsMissionCar(CurrentVehicle, true); AddBlipForCar(GetVehicleModel(), &SavedVehicleBlip); ChangeBlipSprite(SavedVehicleBlip, BLIP_GARAGE); ChangeBlipScale(SavedVehicleBlip, 0.5f); ChangeBlipColour(SavedVehicleBlip, 5); //Magenta SetBlipAsShortRange(SavedVehicleBlip, 1); ChangeBlipNameFromAscii(SavedVehicleBlip, "Your Car"); } if (SavedVehicle != false) { SetCarAsMissionCar(CurrentVehicle, false);; RemoveBlip(SavedVehicleBlip); } if ((IsCharInAnyCar(GetPlayerPed()) == true)) { LastVehicle = CurrentVehicle; } } } |
Cheers, Billsy
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Lord_of_Light  |
Posted: Tuesday, May 21 2013, 21:00
|
Player Hater

Group: BUSTED!
Joined: May 21, 2013

|
yes i wanted u to post this code: | CODE | | static void GetDriverOfCar(Vehicle vehicle, Ped *pPed) { NativeInvoke::Invoke<NATIVE_GET_DRIVER_OF_CAR, ScriptVoid>(vehicle, pPed); } |
i recommend u write this in c#, c++ scripts dont have any performance benefits really and coding it is more a hassle for someone new... c# | CODE | | Ped driver = vehicle.GetPedOnSeat(VehicleSeat.Driver);//will crash if vehicle does not exist |
c++ | CODE | Vehicle vehicle;//set your vehicle however u do... GetClosestCar, etc Ped driver; GetDriverOfCar(vehicle, &driver); |
edit: my bad scripthook has vehicle, ped and blip class like shdn. i thought they were handled differently... i dont use the c++ scripthook This post has been edited by Lord_of_Light on Tuesday, May 21 2013, 21:02
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Billsy93  |
Posted: Tuesday, May 21 2013, 21:07
|
Player Hater

Group: Members
Joined: May 7, 2013

|
| QUOTE (Lord_of_Light @ Tuesday, May 21 2013, 21:00) | yes i wanted u to post this code:
| CODE | | static void GetDriverOfCar(Vehicle vehicle, Ped *pPed) { NativeInvoke::Invoke<NATIVE_GET_DRIVER_OF_CAR, ScriptVoid>(vehicle, pPed); } |
i recommend u write this in c#, c++ scripts dont have any performance benefits really and coding it is more a hassle for someone new...
c#
| CODE | | Ped driver = vehicle.GetPedOnSeat(VehicleSeat.Driver);//will crash if vehicle does not exist |
c++
| CODE | Vehicle vehicle;//set your vehicle however u do... GetClosestCar, etc Ped driver; GetDriverOfCar(vehicle, &driver); |
edit: my bad scripthook has vehicle, ped and blip class like shdn. i thought they were handled differently... i dont use the c++ scripthook  |
Hey, I changed | CODE | | if ((IsCharInAnyCar(GetPlayerPed()) == true) && (GetDriverOfCar(CurrentVehicle, &GetPlayerPed()) == ped)) |
to this | CODE | | if ((IsCharInAnyCar(GetPlayerPed()) == true) && (GetDriverOfCar(CurrentVehicle, &ped))) |
as it didn't like the "== true". However, now it still doesn't like the GetDriverOfCar part of the if condition as Visual Studio is saying it needs to be a boolean, how do I code the condition (if statement) correctly in this scenario? Thanks
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Billsy93  |
Posted: Wednesday, May 22 2013, 13:02
|
Player Hater

Group: Members
Joined: May 7, 2013

|
| QUOTE (Lord_of_Light @ Wednesday, May 22 2013, 06:50) | | CODE | namespace SaveMyCar { using System; using GTA;
public class Main : Script { Blip blip; Vehicle playerVeh;
public Main() { Tick += Main_Tick; }
void Main_Tick(object sender, EventArgs e) { if (Game.LocalPlayer.Character.isInVehicle()) { if (Game.Exists(playerVeh)) { if (playerVeh.isRequiredForMission) playerVeh.isRequiredForMission = false; if (playerVeh != Game.LocalPlayer.Character.CurrentVehicle) playerVeh = Game.LocalPlayer.Character.CurrentVehicle; } else { playerVeh = Game.LocalPlayer.Character.CurrentVehicle; }
if (Game.Exists(blip)) blip.Delete(); } else { if (Game.Exists(playerVeh) && playerVeh.isDriveable && !playerVeh.isRequiredForMission) { playerVeh.isRequiredForMission = true; if (!Game.Exists(blip)) { blip = playerVeh.AttachBlip(); blip.Name = "Your Car"; blip.Scale = 0.5f; blip.Color = (BlipColor)5; } } } } } } |
.net is much easier to work with, u can see how simple it is to read the script and intellisense is so much better | Hey, Thanks for this Lord, however, it doesn't quite do what I want it to do. When I tried your script, the first car I get in, gets a blip (which is good, as intended). However, if I get in another car, the blip for the first car still exists and doesn't get deleted. I want that to be deleted as the current car gets updated with the new car you are now in and for that to get a blip and so on, updating for every new car you enter. If that makes sense? What part of the code would you change in order for that to come into effect? Cheers.
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Lord_of_Light  |
Posted: Wednesday, May 22 2013, 16:33
|
Player Hater

Group: BUSTED!
Joined: May 21, 2013

|
| QUOTE (Billsy93 @ Wednesday, May 22 2013, 13:02) | Hey,
Thanks for this Lord, however, it doesn't quite do what I want it to do. When I tried your script, the first car I get in, gets a blip (which is good, as intended). However, if I get in another car, the blip for the first car still exists and doesn't get deleted. I want that to be deleted as the current car gets updated with the new car you are now in and for that to get a blip and so on, updating for every new car you enter. If that makes sense? What part of the code would you change in order for that to come into effect?
Cheers. |
When I tested entering multiple cars it worked, u donthave 2 scripts installed changing if vehicle is a mission vehicle?? Test my script alone to double check Worked for me but I'll double check later this may help u understand where the bug is coming from... | CODE | namespace SaveMyCar { using System; using GTA;
public class Main : Script { Blip blip; Vehicle playerVeh;
public Main() { Tick += Main_Tick; }
//this script manages two different states the player could be in... in a car or on foot
void Main_Tick(object sender, EventArgs e) { if (Game.LocalPlayer.Character.isInVehicle())//Player is in vehicle { if (Game.Exists(playerVeh))//player car has been saved previously { if (playerVeh.isRequiredForMission) playerVeh.isRequiredForMission = false;//removes save flag from previously saved car which may or may not be the current car the player is in, this script uses the ReqForMission vehicle property as a flag and only set true when exiting the car if (playerVeh != Game.LocalPlayer.Character.CurrentVehicle) playerVeh = Game.LocalPlayer.Character.CurrentVehicle;//ensures player's current car is the new car to be saved } else//player car not previously saved { playerVeh = Game.LocalPlayer.Character.CurrentVehicle;//this sets the first car player gets into }
if (Game.Exists(blip)) blip.Delete();//deletes blip this script created so for u to get in another car and this blip not get deleted does not make sense, if in fact your blip isnt being deleted i believe u have a script installed with bad code and f*cking up gta memory, u usually will run into access violation errors that u can see in the console when this happens } else//Player is on foot { //removed... && playerVeh.isDriveable as i don't think it is necessary on 2nd thought and may confuse things
if (Game.Exists(playerVeh) && !playerVeh.isRequiredForMission)//ensures a player car was saved to vehicle variable and it hasn't already been made a mission car, which is the flag this script relies on { playerVeh.isRequiredForMission = true; if (!Game.Exists(blip)) { blip = playerVeh.AttachBlip(); blip.Name = "Your Car"; blip.Scale = 0.5f; blip.Color = (BlipColor)5; } } } } //so this script just constantly checks for a situation and when it finds it, runs a few lines of code and the following ticks, no code should run //just walk through my comments and see if u can determine where my logic breaks because i tested and works fine;) } } |
i kinda don't believe you since i tested last night and after reviewing code i see if u r in a vehicle... a blip will not be created by my script, it will only delete the blip it created before, then when ur on foot it can only create the blip once since the blip once and it even has to get through 2 checks to make another blip so this script can't lose track of the blip it creates... so im thinking u have another issue going on... and it did work perfect for me... read my comments in the script and let me know if it makes sense every single if statement in this script is designed to only be true once for each time a player gets in and out of a vehicle so 99% of the time this script runs it just checks bools that route the script to just constantly return from the tick method This post has been edited by Lord_of_Light on Wednesday, May 22 2013, 17:29
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Billsy93  |
Posted: Thursday, May 23 2013, 11:58
|
Player Hater

Group: Members
Joined: May 7, 2013

|
| QUOTE (Lord_of_Light @ Wednesday, May 22 2013, 16:33) | | QUOTE (Billsy93 @ Wednesday, May 22 2013, 13:02) | Hey,
Thanks for this Lord, however, it doesn't quite do what I want it to do. When I tried your script, the first car I get in, gets a blip (which is good, as intended). However, if I get in another car, the blip for the first car still exists and doesn't get deleted. I want that to be deleted as the current car gets updated with the new car you are now in and for that to get a blip and so on, updating for every new car you enter. If that makes sense? What part of the code would you change in order for that to come into effect?
Cheers. |
When I tested entering multiple cars it worked, u donthave 2 scripts installed changing if vehicle is a mission vehicle?? Test my script alone to double check
Worked for me but I'll double check later
this may help u understand where the bug is coming from...
| CODE | namespace SaveMyCar { using System; using GTA;
public class Main : Script { Blip blip; Vehicle playerVeh;
public Main() { Tick += Main_Tick; }
//this script manages two different states the player could be in... in a car or on foot
void Main_Tick(object sender, EventArgs e) { if (Game.LocalPlayer.Character.isInVehicle())//Player is in vehicle { if (Game.Exists(playerVeh))//player car has been saved previously { if (playerVeh.isRequiredForMission) playerVeh.isRequiredForMission = false;//removes save flag from previously saved car which may or may not be the current car the player is in, this script uses the ReqForMission vehicle property as a flag and only set true when exiting the car if (playerVeh != Game.LocalPlayer.Character.CurrentVehicle) playerVeh = Game.LocalPlayer.Character.CurrentVehicle;//ensures player's current car is the new car to be saved } else//player car not previously saved { playerVeh = Game.LocalPlayer.Character.CurrentVehicle;//this sets the first car player gets into }
if (Game.Exists(blip)) blip.Delete();//deletes blip this script created so for u to get in another car and this blip not get deleted does not make sense, if in fact your blip isnt being deleted i believe u have a script installed with bad code and f*cking up gta memory, u usually will run into access violation errors that u can see in the console when this happens } else//Player is on foot { //removed... && playerVeh.isDriveable as i don't think it is necessary on 2nd thought and may confuse things
if (Game.Exists(playerVeh) && !playerVeh.isRequiredForMission)//ensures a player car was saved to vehicle variable and it hasn't already been made a mission car, which is the flag this script relies on { playerVeh.isRequiredForMission = true; if (!Game.Exists(blip)) { blip = playerVeh.AttachBlip(); blip.Name = "Your Car"; blip.Scale = 0.5f; blip.Color = (BlipColor)5; } } } } //so this script just constantly checks for a situation and when it finds it, runs a few lines of code and the following ticks, no code should run //just walk through my comments and see if u can determine where my logic breaks because i tested and works fine;) } } |
i kinda don't believe you since i tested last night and after reviewing code i see if u r in a vehicle... a blip will not be created by my script, it will only delete the blip it created before, then when ur on foot it can only create the blip once since the blip once and it even has to get through 2 checks to make another blip so this script can't lose track of the blip it creates... so im thinking u have another issue going on... and it did work perfect for me... read my comments in the script and let me know if it makes sense
every single if statement in this script is designed to only be true once for each time a player gets in and out of a vehicle so 99% of the time this script runs it just checks bools that route the script to just constantly return from the tick method |
This is very strange indeed. I've tried again and uninstalling some others mods, but to no avail. I still get an error message when I get into a second vehicle upon loading the game. The script works fine for the first car, as when a exit the blip is there etc, but when I get into another car, I get an error and the blip from the first doesn't get deleted and updated to the new car when I exit. Here's what the error message is saying. Error during Tick in script 'SaveMyCar.Main': GTA.NonExistingObjectException: Invalid call to an object that doesn't exist anymore! at GTA.Blip.Delete() at SaveMyCar.Main.Main_Tick(Object sender, EventArgs e) at GTA.Script.TryTick() at GTA.Script.DoTick() at GTA.ScriptThread.OnTick()
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Billsy93  |
Posted: Thursday, May 23 2013, 19:07
|
Player Hater

Group: Members
Joined: May 7, 2013

|
| QUOTE (girish_is_gay @ Thursday, May 23 2013, 17:22) | i believe u have some type of conflict going on being it from another script or maybe u r using 1.0.4 and something in the 0.4.0 scripthook isnt compatable
this is the line of code that caused the crash btw
| CODE | | if (Game.Exists(blip)) blip.Delete(); |
The exists part ensures the object exists in memory so it has something to delete. So for it to say yes it exists and then when it deletes a nanosecond (not actual time) later it doesn't exist means u have a memory issue. I believe your using an old scripthook for an older version gta or ur using a script that is using code wrong and putting wrong value types into memory and making gta confused to what is what. So even though it thinks a blip exists, it might be looking at something completely different... this is my guess just based on what ur saying | Cheers Girish, I solved the issue now, you're right in identifying that it was to do with the blip deletion, the cause of the problem was where the code to delete the blip had been placed within the script. All is well, thanks for the help all.
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
girish_is_gay  |
Posted: Thursday, May 23 2013, 19:09
|
Player Hater

Group: BUSTED!
Joined: May 23, 2013

|
| QUOTE (Billsy93 @ Thursday, May 23 2013, 19:07) | | QUOTE (girish_is_gay @ Thursday, May 23 2013, 17:22) | i believe u have some type of conflict going on being it from another script or maybe u r using 1.0.4 and something in the 0.4.0 scripthook isnt compatable
this is the line of code that caused the crash btw
| CODE | | if (Game.Exists(blip)) blip.Delete(); |
The exists part ensures the object exists in memory so it has something to delete. So for it to say yes it exists and then when it deletes a nanosecond (not actual time) later it doesn't exist means u have a memory issue. I believe your using an old scripthook for an older version gta or ur using a script that is using code wrong and putting wrong value types into memory and making gta confused to what is what. So even though it thinks a blip exists, it might be looking at something completely different... this is my guess just based on what ur saying |
Cheers Girish,
I solved the issue now, you're right in identifying that it was to do with the blip deletion, the cause of the problem was where the code to delete the blip had been placed within the script. All is well, thanks for the help all. |
so why dont u share what fixed it? and u have been talking to one person... faggot mods on here ban me over and over, so u can thank jitsuin, not all This post has been edited by girish_is_gay on Thursday, May 23 2013, 19:11
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Pages:
(2) [1] 2
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
| |
 |
|
 |
|
|
|
|