Disconnect destroy vehicle
#1

hello.
When i leave the server, i want it to destroy my vehicle.
But, nothing happends
This is my code for OnPlayerDisconnect:
PHP код:
    for(new i=0i<sizeof(cInfo); i++)
    {
      if(
cInfo[i][carteam]==255)
 {
      if(
cInfo[i][id_x]==0)continue;
      if(
cInfo[i][carowner] != PlayerInfo[playerid][pusername])continue;
      
DestroyVehicle(cInfo[i][id_x]);
      
cInfo[i][id_x]=0;
 } 
Reply
#2

https://sampwiki.blast.hk/wiki/Strcmp
Reply
#3

Quote:
Originally Posted by ilijap
Посмотреть сообщение
Yes, use strcmp for
PHP код:
 if(cInfo[i][carowner] != PlayerInfo[playerid][pusername]) 
->
PHP код:
 if(!strcmp(cInfo[i][carowner],PlayerInfo[playerid][pusername])) 
Show us your cInfo.
Also why do you set
PHP код:
 for(new i=0i<sizeof(cInfo); i++) 
instead of
PHP код:
for(new GetVehiclePoolSize(); 0i--) 
Reply
#4

Quote:
Originally Posted by ilijap
Посмотреть сообщение
thanks

.


Quote:
Originally Posted by Dayrion
Посмотреть сообщение
This is not helping at all..
--
Show us your cInfo.
Also why do you set
PHP код:
 for(new i=0i<sizeof(cInfo); i++) 
instead of
PHP код:
for(new GetVehiclePoolSize(); 0i--) 
welp i forgot to put the info into [carteam] xd

Quote:
Originally Posted by Dayrion
Also why do you set
PHP код:
 for(new i=0i<sizeof(cInfo); i++) 
instead of
PHP код:
for(new GetVehiclePoolSize(); 0i--) 
no idea.

still doesn't work btw.

PHP код:
enum carEnum{
id_x,
carowner[MAX_PLAYER_NAME],
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[1000][carEnum]; 
Reply
#5

someone an idea?
Reply
#6

I think this will work way better for you (No strcmp/looping is needed)

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? 
I'm assuming you create the vehicle doing something like this (Triggered by the player). This is an example..

PHP код:
new Float:XFloat:YFloat:ZFloat:A;
GetPlayerPos(playeridXYZ);
GetPlayerFacingAngle(playeridA);
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.. 
Now the callbacks..

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(playeridreason)
{
    
// You check if carteam is 255 so..
    
if(cInfo[playerid][carteam] == 255 && cInfo[playerid][id_x] >= 0DestroyVehicle(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;

Hope it helps.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)