Undetectable bug? (Vehicle system - Car ID's - Won't despawn correctly)
#1

Car bugs, freeroam


Hello!
Okay, now after checking my code at least 40-50 times, re-coding the entire vehicle system and replacing PVars with arrays, I still can't find the bug, which is causing vehicles to be messed up. By messed up, I mean that vehicle ID's, specifically car ID 255 (which is server-sided on restart), is causing players to steal vehicles from eachother, and causing additional vehicle features to bug, such as a Private vehicle system I've made. First, I thought CreateVehicle returned 255 in some cases, because instead of creating a new vehicle, it just stole a vehicle from someone else. -_-

I have also been in-touch with several people on the #sa-mp.scripting IRC channel, in order to get details about different functions and callbacks, and how they act in different situations.


What the system is supposed to do?
- Mainly, I want it to handle the cars in such a way, that it doesn't end up being vehicles spawned everywhere on the server. So I am currently allowing one spawned car per playerid. When a new car is spawned, I use a check to see if there is any past-spawned cars, and if so (and if valid) I destroy it before i create the new one.
The Race system I made also uses the "per-playerid" spawned cars Array, so the Race vehicle also can get destroyed when the player is either leaving or spawning a new car after the race.


What can I see that bugs up?
- Firstly, after I changed the code to check for "IsValidVehicle", I started experiencing alot more car-spam around the map than before.
Also, I've kept a close eye on Car ID 255 when Im online. And it has always something to do with players after a while. I did never actually see how it bugs up. All I know is that it is spawned on OnGamemodeInit() (look at the attachment)

Please be aware, that I did not create a global function to call each time, as I wasn't aware of that method back then when i started out with it.




The code I use
OnPlayerDeath(playerid):
PHP код:
if(AccInfo[playerid][SpawnedCarID] != INVALID_VEHICLE_ID)
    {
        
DestroyVehicle(AccInfo[playerid][SpawnedCarID]);
        
AccInfo[playerid][SpawnedCarID] = INVALID_VEHICLE_ID;
    } 
OnPlayerDisconnect(playerid)
PHP код:
if(AccInfo[playerid][SpawnedCarID] != INVALID_VEHICLE_ID)
    {
        
DestroyVehicle(AccInfo[playerid][SpawnedCarID]);
        
AccInfo[playerid][SpawnedCarID] = INVALID_VEHICLE_ID;
    }
    if(
PlayerInfo[playerid][CarID] != -1)
    {
        if(
IsValidVehicle(PlayerInfo[playerid][CarID]))
            
DestroyVehicle(PlayerInfo[playerid][CarID]);
        
DestroyDynamic3DTextLabel(PlayerInfo[playerid][textie]);
        
PlayerInfo[playerid][CarID] = -1;
    } 
CMD:car
PHP код:
if(AccInfo[playerid][SpawnedCarID] != INVALID_VEHICLE_ID)
    {
        
printf("CMD:CAR = Old spawned car ID = %d  BY Payerid = %d",AccInfo[playerid][SpawnedCarID],playerid);
        
DestroyVehicle(AccInfo[playerid][SpawnedCarID]);
        
AccInfo[playerid][SpawnedCarID] = INVALID_VEHICLE_ID;
    }
        
LVehicleID CreateVehicle(carX,Y,ZAngle123colour1colour2, -1);
    
AccInfo[playerid][SpawnedCarID] = LVehicleID
Tuned cars:
PHP код:
if(AccInfo[playerid][SpawnedCarID] != INVALID_VEHICLE_ID)
        {
            
DestroyVehicle(AccInfo[playerid][SpawnedCarID]);
            
AccInfo[playerid][SpawnedCarID] = INVALID_VEHICLE_ID;
        }
        
LVehicleIDt CreateVehicle(560,X,Y,Z,Angle123,1,-1,-1);
        
AccInfo[playerid][SpawnedCarID] = LVehicleIDt
And so the method goes for all player spawned vehicles..


Race system:
PHP код:
//Joining the race:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        
RemovePlayerFromVehicle(playerid);
    if(
AccInfo[playerid][SpawnedCarID] != INVALID_VEHICLE_ID)
    {
        
DestroyVehicle(AccInfo[playerid][SpawnedCarID]);
        
AccInfo[playerid][SpawnedCarID] = INVALID_VEHICLE_ID;
    }
//////////////
//then this function is called:
forward PutRacerInVehicle(i); //called from the function timer, so the maps can load.
public PutRacerInVehicle(i)
{
            new 
Float:xFloat:yFloat:z;
            
GetPlayerPos(ix,yz);
            new 
car CreateVehicle(Data[RaceCar], xyData[StartZ]+1,Data[Angle], -1, -1, -1);
            
SetVehicleVirtualWorld(carraceworld);
            
PutPlayerInVehicle(icar0);
            
AccInfo[i][SpawnedCarID] = car;
            return 
1;

(Im sorry about the identation, it gets kinda fked when i paste it into the forums )


At least you can see system
Am I doing anything wrong, and can i get some nice help on how to solve this?
Is a vehicle returned as "valid" when it just exploded? Or, what about the CreateVehicle(........, SPAWN_TIME); ?

Am I missing something?

I hate issues with the cars, as they are really important in that kind of gamemodes.


EDIT

Restarted server today again.
Quote:

[09:01:42] CMD:CAR = Old spawned car ID = 489 BY Payerid = 11
[09:01:42] CMD:CAR = LvehicleID = 255
[09:01:42] CMD:CAR = new spawned car ID (VAR) = 255 BY Payerid = 11

I was standing by Vehicle 255 and just watching, until i got this one ^
It didn't reuse the slot of the old car, instead just taking Vehicle ID 255. for no reason.


Help is hugely appreciated!
denNorske
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)