SA-MP Forums Archive
A weird bug?! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: A weird bug?! (/showthread.php?tid=548060)



A weird bug?! - streetpeace - 27.11.2014

Hello everybody,

I've got a bug since one/two months but I can't fix it because he's so weird. I've searched and asked for help a lot of times but no one cares or maybe no one knows the solution of this one.

The problem that when I write if and after that I write else if in some callbacks (onplayerdeath, onplayerstatechange, onplayerentervehicle and maybe other callbacks) It doesn't work... The if condition work but the others (else if) doesn't work. Can I have a possible solution of this please ? Thanks.


Re: A weird bug?! - Beckett - 27.11.2014

You're probably messing it up, show us how you're doing it perhaps.


Re : A weird bug?! - streetpeace - 27.11.2014

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:Pos[3];
    if(!ispassenger)
    {
         if(IsPoliceVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas membre de la police!");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
         }
         if(IsCamionneurVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas camionneur ou vous n'avez pas les compйtences nйcessaires ou vous n'кtes pas en service.");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
         }
         else if(IsAmbulancierVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas ambulancier.");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             printf("Ambulance");
         }
    }
    return 1;
}
The two else if doesn't work.


Re: A weird bug?! - CalvinC - 27.11.2014

Have you tried changing the "else if" to "if"?


Re: Re : A weird bug?! - Runn3R - 27.11.2014

Quote:
Originally Posted by streetpeace
Посмотреть сообщение
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:Pos[3];
    if(!ispassenger)
    {
         if(IsPoliceVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas membre de la police!");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
         }
         if(IsCamionneurVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas camionneur ou vous n'avez pas les compйtences nйcessaires ou vous n'кtes pas en service.");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
         }
         else if(IsAmbulancierVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas ambulancier.");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             printf("Ambulance");
         }
    }
    return 1;
}
The two else if doesn't work.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:Pos[3];
    if(!ispassenger)
    {
         if(IsPoliceVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas membre de la police!");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
         }
         else if(IsCamionneurVeh(vehicleid)) // This needs to be like this
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas camionneur ou vous n'avez pas les compйtences nйcessaires ou vous n'кtes pas en service.");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
         }
         else if(IsAmbulancierVeh(vehicleid))
         {
             SendClientMessage(playerid, -1, "Vous n'кtes pas ambulancier.");
             GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
             printf("Ambulance");
         }
    }
    return 1;
}
Also you maybe have a problem in your functions. Maybe they return 0 which makes the script ignore the statement.

Show us the functions. All 3 of them.


Re : A weird bug?! - streetpeace - 27.11.2014

pawn Код:
stock IsCamionneurVeh(vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(vehicleid == CamionneurVeh[i]) return true;
    }
    return true;
}
stock IsAmbulancierVeh(vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(vehicleid == Ambulances[i]) return true;
    }
    return true;
}
stock IsPoliceVeh(vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(vehicleid == LSPDVoiture[i]) return true;
    }
    return true;
}
Here is the code and your solution doesn't work (about else if)


Re: A weird bug?! - Abagail - 27.11.2014

You don't return false at all so the result will always be true. Therefore, the first one is always true, and the other one's aren't called because of it.


Re : A weird bug?! - streetpeace - 27.11.2014

I've already searched a lot of times for a possible solution for this bug but I can't find something that can fix this problem. I have the same problems with some others callbacks (onplayerdeath, onplayerstatechange..) please help me.


Re : A weird bug?! - streetpeace - 27.11.2014

no one can help ?


Re: Re : A weird bug?! - Runn3R - 27.11.2014

pawn Код:
stock IsCamionneurVeh(vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(vehicleid == CamionneurVeh[i]) return true;
    }
    return false;
}
stock IsAmbulancierVeh(vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(vehicleid == Ambulances[i]) return true;
    }
    return false;
}
stock IsPoliceVeh(vehicleid)
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(vehicleid == LSPDVoiture[i]) return true;
    }
    return false;
}