16.06.2015, 23:28
Hello!
I have one global function to spawn 1 car per player online, and it looks like this:
But shortly after a server restart; this starts to happen:
Which indicates that the vehicle-ID that the new player spawned, was a vehicle-id that someone else had assigned as "theirs".
This causes the players to steal cars from eachother, and it's a very annoying problem.
What have i done wrong?
Is there anything else I have to do to prevent this?
~thanks
I have one global function to spawn 1 car per player online, and it looks like this:
PHP код:
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;
}
Quote:
[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 |
This causes the players to steal cars from eachother, and it's a very annoying problem.
What have i done wrong?
Is there anything else I have to do to prevent this?
~thanks