24.05.2016, 19:04
I think this will work way better for you (No strcmp/looping is needed)
I'm assuming you create the vehicle doing something like this (Triggered by the player). This is an example..
Now the callbacks..
Hope it helps.
PHP код:
enum carEnum{
id_x,
carowner[MAX_PLAYER_NAME], // Since you have this variable, only player-created vehicles will be used in this enum.
carmodelid,
Float:c_x,
Float:c_y,
Float:c_z,
Float:c_r,
c_color1,
c_color2,
c_respawntime,
cnitro,
paintjob,
plate,
c_autorespawn,
carteam,
db_id
};
new cInfo[MAX_PLAYERS][carEnum]; // Changed to MAX_PLAYERS. This enum is related to player-created vehicles, no vehicles created by the server. Right?
PHP код:
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
cInfo[playerid][id_x] = CreateVehicle(...) // We store the vehicle id on playerid -> id_x variable.
cInfo[playerid][carmodelid] = GetPlayerVehicleModelID(cInfo[playerid][id_x]); // Stuff..
cInfo[playerid][c_x] = X; // Stuff..
cInfo[playerid][c_y] = Y; // Stuff..
cInfo[playerid][c_z] = Z; // More Stuff..
cInfo[playerid][c_r] = A; // Etc..
PHP код:
public OnPlayerConnect(playerid)
{
// Set id_x to -1.. (You should reset the entire enum to their original values when a player connects)
cInfo[playerid][id_x] = -1; // We set it to -1, because what if the player creates a vehicles, when there is no other vehicle created yet?.
// for(;;) cInfo[playerid][Enum_Variable] = DEFAULT_VALUE ...
return 1;
}
// Player-created vehicle, no loop needed. Just a check if the vehicle has been created.
public OnPlayerDisconnect(playerid, reason)
{
// You check if carteam is 255 so..
if(cInfo[playerid][carteam] == 255 && cInfo[playerid][id_x] >= 0) DestroyVehicle(cInfo[playerid][id_x]);
// Then you must reset id_x.. (You should reset the entire enum to their original values, again)
cInfo[playerid][id_x] = -1;
// for(;;) cInfo[playerid][Enum_Variable] = DEFAULT_VALUE ...
return 1;
}