stock SpawnPlayerVehicle(playerid, vehicleid, Float:x,Float:y,Float:z,Float:angle, color1313,color2323, respawn = -1,putinvehicle)
{
#pragma unused respawn
if(IsValidVehicle(AccInfo[playerid][SpawnedCarID])) // If the player who gets a new car, had an old one spawned. If so, despawn it and reset the array.
{
printf("SpawnPlayerVehicle: Old spawned car ID = %d BY Playerid = %d (Destroyed)",AccInfo[playerid][SpawnedCarID],playerid);
DestroyVehicle(AccInfo[playerid][SpawnedCarID]); //destroying it
AccInfo[playerid][SpawnedCarID] = -1; //resetting array
}
AccInfo[playerid][SpawnedCarID] = CreateVehicle(vehicleid, x,y,z, angle, color1313, color2323, 240); //creating a new vehicle and assigns it to the SpawnedCarID again, so it can be destroyed when a new one is spawned.
printf("SpawnPlayerVehicle: New spawned car ID = %d BY Playerid = %d (Created)",AccInfo[playerid][SpawnedCarID],playerid);
SetVehicleVirtualWorld(AccInfo[playerid][SpawnedCarID], GetPlayerVirtualWorld(playerid));
LinkVehicleToInterior(AccInfo[playerid][SpawnedCarID], GetPlayerInterior(playerid));
new error;
new string[180], string2[180];
AccInfo[playerid][onlinetime] = gettime() - AccInfo[playerid][logintime];
foreach(Player, i)
{
error++;
if(AccInfo[i][SpawnedCarID] == AccInfo[playerid][SpawnedCarID] && i != playerid) // if the carID isn't unique, (that someone else already had that car in their array) - Print it and tell it in the log.
{
format(string, sizeof(string), "DEBUG VEHICLES: Old player: %s (ID %d) || New player: %s (ID %d) || SpawnedCarID Match", PlayerName(i), i, PlayerName(playerid), playerid);
format(string2, sizeof(string2), "Player Info: Gamemode: %d || OnlineTime: %d || Loggedin: %d || VW: %d || Int: %d ", AccInfo[playerid][GameModeType],AccInfo[playerid][onlinetime],
AccInfo[playerid][USER_LOGGED_IN], GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
}
else if(PlayerInfo[i][CarID] == AccInfo[playerid][SpawnedCarID])
{
format(string, sizeof(string), "DEBUG VEHICLES: newly spawned car was a private car.|| Old owner: %s (ID %d) || New player: %s (ID %d)", PlayerName(i), i, PlayerName(playerid), playerid);
format(string2, sizeof(string2), "Player Info: Gamemode: %d || OnlineTime: %d || Loggedin: %d || VW: %d || Int: %d ", AccInfo[playerid][GameModeType],AccInfo[playerid][onlinetime],
AccInfo[playerid][USER_LOGGED_IN], GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
}
else if(trailer[i] == AccInfo[playerid][SpawnedCarID])
{
format(string, sizeof(string), "DEBUG VEHICLES: - new car was trailer. Old owner: %s (ID %d) || New player: %s (ID %d)", PlayerName(i), i, PlayerName(playerid), playerid);
format(string2, sizeof(string2), "Player Info: Gamemode: %d || OnlineTime: %d || Loggedin: %d || VW: %d || Int: %d ", AccInfo[playerid][GameModeType],AccInfo[playerid][onlinetime],
AccInfo[playerid][USER_LOGGED_IN], GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
}
if(ToggleDebug[i] == 1)
{
SendClientMessage(i, -1, string);
SendClientMessage(i, -1, string2);
}
}
if(error > 0)
{
printf(string);
printf(string2);
}
if(putinvehicle == 1)
{
PutPlayerInVehicle(playerid, AccInfo[playerid][SpawnedCarID], 0);
}
return 1;
}
[01:17:00] SpawnPlayerVehicle: Old spawned car ID = 458 BY Playerid = 5 (Destroyed) [01:17:00] ><>><><><<<<<>>< DestroyVehicle(458) >><<<<>><<><<<<<><>> [01:17:00] CreateVehicle(473,-304.647155,1526.395996,75.359375,0.000000,0,1,240) = 458 [01:17:00] SpawnPlayerVehicle: New spawned car ID = 458 BY Playerid = 5 (Created) [01:17:00] DEBUG VEHICLES: Old player: Veg5 (ID 1) || New player: XxXAgustin123XxX (ID 5) || SpawnedCarID Match [01:17:00] Player Info: Gamemode: 0 || OnlineTime: 1685 || Loggedin: 1 || VW: 0 || Int: 0 [01:17:08] SpawnPlayerVehicle: Old spawned car ID = 458 BY Playerid = 5 (Destroyed) [01:17:08] ><>><><><<<<<>>< DestroyVehicle(458) >><<<<>><<><<<<<><>> [01:17:08] CreateVehicle(450,-305.435272,1522.001220,75.359375,0.000000,0,1,240) = 458 [01:17:08] SpawnPlayerVehicle: New spawned car ID = 458 BY Playerid = 5 (Created) [01:17:08] DEBUG VEHICLES: Old player: Veg5 (ID 1) || New player: XxXAgustin123XxX (ID 5) || SpawnedCarID Match [01:17:08] Player Info: Gamemode: 0 || OnlineTime: 1693 || Loggedin: 1 || VW: 0 || Int: 0 [01:17:22] SpawnPlayerVehicle: Old spawned car ID = 458 BY Playerid = 5 (Destroyed) [01:17:22] ><>><><><<<<<>>< DestroyVehicle(458) >><<<<>><<><<<<<><>> [01:17:22] CreateVehicle(463,-307.332458,1521.475219,75.359375,0.000000,0,1,240) = 458 [01:17:22] SpawnPlayerVehicle: New spawned car ID = 458 BY Playerid = 5 (Created) [01:17:22] DEBUG VEHICLES: Old player: Veg5 (ID 1) || New player: XxXAgustin123XxX (ID 5) || SpawnedCarID Match [01:17:22] Player Info: Gamemode: 0 || OnlineTime: 1707 || Loggedin: 1 || VW: 0 || Int: 0 [01:18:32] (Veg5 used /race) [01:18:36] SpawnPlayerVehicle: Old spawned car ID = 458 BY Playerid = 1 (Destroyed) [01:18:36] ><>><><><<<<<>>< DestroyVehicle(458) >><<<<>><<><<<<<><>> [01:18:36] CreateVehicle(509,2253.867187,-1750.366455,14.100000,269.000000,-1,-1,240) = 458 [01:18:36] SpawnPlayerVehicle: New spawned car ID = 458 BY Playerid = 1 (Created) [01:18:36] DEBUG VEHICLES: Old player: XxXAgustin123XxX (ID 5) || New player: Veg5 (ID 1) || SpawnedCarID Match [01:18:36] Player Info: Gamemode: 0 || OnlineTime: 1756 || Loggedin: 1 || VW: 70 || Int: 0 |
How can I prevent CreateVehicle to create one that is already taken? I can't do much about that part.
Also, that is part of what I'm tryin to achieve in first place, by assigning them in creation. But it seems the id's mix up :/ Any examples? To prevent destroying old one if not unique? |
I don't think you have understood what "CreateVehicle" returns, there is no single way a vehicle created with "CreateVehicle" could have somehow the same id. If someone's vehicle is destroyed and their vehicle respawned, then just refresh the player's variable containing the id to the new vehicle's id. They will never be the same.
|
A dead vehicle is still using the slot of that vehicle id -
And I know that CreateVehicle isn't going to return a used ID, so I need to prevent destroying the old car, in case it is used by someone else. But why would a car, that someone spawned; suddenly have another owner? Just, w00t? That is my problem. Player 0 spawns a car, and have it saved in his "spawnedcarid". Player 1 Spawns his car, destroys id 0's car, and creates id 0's "spawnedcarid". (Aka; car is stolen) I can do it the way you say, but wasn't exactly what i was thinking in first place. |
Player 0 spawns a car, and have it saved in his "spawnedcarid".
We're all good for now. Player 1 Spawns his car, destroys id 0's car, and creates id 0's "spawnedcarid". (Aka; car is stolen) If player 1's vehicle is destroyed, then why don't you reset their variable since their car is gone? |