05.06.2015, 10:37
(
Последний раз редактировалось denNorske; 05.06.2015 в 11:33.
)
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):
OnPlayerDisconnect(playerid)
CMD:car
Tuned cars:
And so the method goes for all player spawned vehicles..
Race system:
(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.
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
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;
}
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;
}
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(car, X,Y,Z, Angle123, colour1, colour2, -1);
AccInfo[playerid][SpawnedCarID] = LVehicleID;
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;
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:x, Float:y, Float:z;
GetPlayerPos(i, x,y, z);
new car = CreateVehicle(Data[RaceCar], x, y, Data[StartZ]+1,Data[Angle], -1, -1, -1);
SetVehicleVirtualWorld(car, raceworld);
PutPlayerInVehicle(i, car, 0);
AccInfo[i][SpawnedCarID] = car;
return 1;
}
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 |
It didn't reuse the slot of the old car, instead just taking Vehicle ID 255. for no reason.
Help is hugely appreciated!
denNorske