SA-MP Forums Archive
weird bug / crash by native SendClientMessage - 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: weird bug / crash by native SendClientMessage (/showthread.php?tid=367816)



weird bug / crash by native SendClientMessage - dudaefj - 11.08.2012

weird? Look backtrace...


Quote:

[10/08/12 16:48:30] [debug] Server crashed while executing BSL2.amx

[10/08/12 16:48:30] [debug] Backtrace:

[10/08/12 16:48:30] [debug] #0 native SendClientMessage () from bsl

[10/08/12 16:48:30] [debug] #1 000ff214 in public ProxDetector (Float:radi=30.00000, playerid=9, string[]=@0x0008b018 "Easy_Job trocou a r", col1=-1029514497, col2=-1029514497, col3=-1029514497, col4=-1029514497, col5=-1029514497) at C:\BSL\BSL 2.1\gamemodes\BSL2.pwn:8473

[10/08/12 16:48:30] [debug] #2 00094098 in public QdoResponderDialogNikoRadio (playerid=9, dialogid=88, response=1, listitem=95, inputtext[]=@0x0095af50 "") at Radio_System.pwn:84

[10/08/12 16:48:30] [debug] #3 00329794 in public S@@_OnDialogResponse (playerid=9, dialogid=88, response=1, listitem=95, inputtext[]=@0x0095af50 "", ... <1 variable argument>) at C:\BSL\BSL 2.1\gamemodes\BSL2.pwn:42901

[10/08/12 16:48:30] [debug] #4 native CallLocalFunction () from bsl

[10/08/12 16:48:30] [debug] #5 0001b730 in public OnDialogResponse (playerid=9, dialogid=88, response=1, listitem=95, inputtext[]=@0x0095aea0 "") at C:\sampserver\pawno\include\YSI\internal\y_dohooks .inc:3349

my ProxDetector:
PHP Code:
public ProxDetector(Float:radiplayeridstring[],col1,col2,col3,col4,col5)
{
    if(
IsPlayerConnected(playerid) && GetPlayerState(playerid) != PLAYER_STATE_SPECTATING)
    {
        new 
Float:posxFloat:posyFloat:posz;
        new 
Float:oldposxFloat:oldposyFloat:oldposz;
        new 
Float:tempposxFloat:tempposyFloat:tempposz;
        
GetPlayerPos(playeridoldposxoldposyoldposz);
        
//radi = 2.0; //Trigger Radius
        
foreach(Playeri)
            if(
GetPlayerInterior(playerid) == GetPlayerInterior(i))
                if(!
BigEar[i])
                {
                    
GetPlayerPos(iposxposyposz);
                    
tempposx = (oldposx -posx);
                    
tempposy = (oldposy -posy);
                    
tempposz = (oldposz -posz);
                    if(((
tempposx floatdiv(radi,16)) && (tempposx > -floatdiv(radi,16))) && ((tempposy floatdiv(radi,16)) && (tempposy > -floatdiv(radi,16))) && ((tempposz floatdiv(radi,16)) && (tempposz > -floatdiv(radi,16))))
                    {
                        
SendClientMessage(icol1string); // <- this line makes the crash
                    
}
                    else if(((
tempposx floatdiv(radi,8)) && (tempposx > -floatdiv(radi,8))) && ((tempposy floatdiv(radi,8)) && (tempposy > -floatdiv(radi,8))) && ((tempposz floatdiv(radi,8)) && (tempposz > -floatdiv(radi,8))))
                    {
                        
SendClientMessage(icol2string);
                    }
                    else if(((
tempposx floatdiv(radi,4)) && (tempposx > -floatdiv(radi,4))) && ((tempposy floatdiv(radi,4)) && (tempposy > -floatdiv(radi,4))) && ((tempposz floatdiv(radi,4)) && (tempposz > -floatdiv(radi,4))))
                    {
                        
SendClientMessage(icol3string);
                    }
                    else if(((
tempposx floatdiv(radi,2)) && (tempposx > -floatdiv(radi,2))) && ((tempposy floatdiv(radi,2)) && (tempposy > -floatdiv(radi,2))) && ((tempposz floatdiv(radi,2)) && (tempposz > -floatdiv(radi,2))))
                    {
                        
SendClientMessage(icol4string);
                    }
                    else if(((
tempposx radi) && (tempposx > -radi)) && ((tempposy radi) && (tempposy > -radi)) && ((tempposz radi) && (tempposz > -radi)))
                    {
                        
SendClientMessage(icol5string);
                    }
                }
                else
                {
                    
SendClientMessage(icol1string);
                }
    }
    return 
1;

when and how it has been called:
PHP Code:
        format(thestringsizeof(thestring), "%s trocou a rбdio do veнculo para a %s"Player[playerid][pName], DOF2_GetString(arquivo,endereco));
        
ProxDetector(30.0playeridthestringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE); 
anyone has any idea how to fix?
Is it really a bug from sa:mp ?
I'm using centOS, 64bits, dedicated server, samp 0.3e R2
thank you


Re: weird bug / crash by native SendClientMessage - phillip875 - 11.08.2012

You are missing 2 brackets - one after foreach and the closing one after else towards the bottom.

if this doesn't help - use this:

pawn Code:
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        //radi = 2.0; //Trigger Radius
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
            {
                GetPlayerPos(i, posx, posy, posz);
                tempposx = (oldposx -posx);
                tempposy = (oldposy -posy);
                tempposz = (oldposz -posz);
                //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
                if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
                {
                    SendClientMessage(i, col1, string);
                }
                else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
                {
                    SendClientMessage(i, col2, string);
                }
                else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
                {
                    SendClientMessage(i, col3, string);
                }
                else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
                {
                    SendClientMessage(i, col4, string);
                }
                else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
                {
                    SendClientMessage(i, col5, string);
                }
            }
        }
    }//not connected
    return 1;
}



Respuesta: Re: weird bug / crash by native SendClientMessage - dudaefj - 11.08.2012

Quote:
Originally Posted by phillip875
View Post
You are missing 2 brackets - one after foreach and the closing one after else towards the bottom.

if this doesn't help - use this:

pawn Code:
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        //radi = 2.0; //Trigger Radius
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
            {
                GetPlayerPos(i, posx, posy, posz);
                tempposx = (oldposx -posx);
                tempposy = (oldposy -posy);
                tempposz = (oldposz -posz);
                //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
                if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
                {
                    SendClientMessage(i, col1, string);
                }
                else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
                {
                    SendClientMessage(i, col2, string);
                }
                else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
                {
                    SendClientMessage(i, col3, string);
                }
                else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
                {
                    SendClientMessage(i, col4, string);
                }
                else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
                {
                    SendClientMessage(i, col5, string);
                }
            }
        }
    }//not connected
    return 1;
}
those brackets are not necessary, if you have just one "thing" after foreach, while, for, if, else, it can be done without brackets

PHP Code:
new 1;
3;
if(
3)
   
printf("a = %d"a); 
is the same as
PHP Code:
new 1;
3;
if(
3)
{
   
printf("a = %d"a);

you can have too:

PHP Code:
for(new 0MAX_PLAYERSi++)
   if(
== 7)
     print(
"player id 7 has been found");
  else
     
printf("player id %d is not player id 7"i); 
you can try it if you want, but the brackets are not necessary in this case.


Re: weird bug / crash by native SendClientMessage - leonardo1434 - 11.08.2012

use this one, i've made it now. it should works in the same way.

pawn Code:
stock newprox(playerid,Float:range,text[],co1,co2,co3,co4,co5)
{
    new Float:l_2[3];
    GetPlayerPos(playerid,l_2[0],l_2[1],l_2[2]);
    for(new i = 0; i != MAX_PLAYERS;++i) {
        if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))) {
            if(IsPlayerInRangeOfPoint(i,range/16,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co1, text);
            else if(IsPlayerInRangeOfPoint(i,range/8,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co2, text);
            else if(IsPlayerInRangeOfPoint(i,range/4,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co3, text);
            else if(IsPlayerInRangeOfPoint(i,range/2,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co4, text);
            else if(IsPlayerInRangeOfPoint(i,range,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co5, text);
        }
    }
    return 1;
}

//usage
newprox(playerid,30.0,#cool,-1,-1,-1,-1,-1);



Respuesta: Re: weird bug / crash by native SendClientMessage - dudaefj - 11.08.2012

Quote:
Originally Posted by leonardo1434
View Post
use this one, i've made it now. it should works in the same way.

pawn Code:
stock newprox(playerid,Float:range,text[],co1,co2,co3,co4,co5)
{
    new Float:l_2[3];
    GetPlayerPos(playerid,l_2[0],l_2[1],l_2[2]);
    for(new i = 0; i != MAX_PLAYERS;++i) {
        if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))) {
            if(IsPlayerInRangeOfPoint(i,range/16,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co1, text);
            else if(IsPlayerInRangeOfPoint(i,range/8,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co2, text);
            else if(IsPlayerInRangeOfPoint(i,range/4,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co3, text);
            else if(IsPlayerInRangeOfPoint(i,range/2,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co4, text);
            else if(IsPlayerInRangeOfPoint(i,range,l_2[0],l_2[1],l_2[2])) SendClientMessage(i, co5, text);
        }
    }
    return 1;
}

//usage
newprox(playerid,30.0,#cool,-1,-1,-1,-1,-1);
and why should it help me to fix the crash by "SendClientMessage" ?


Re: weird bug / crash by native SendClientMessage - leonardo1434 - 11.08.2012

Most probably, the way of this prox is wrong.


Re: weird bug / crash by native SendClientMessage - Devilxz97 - 11.08.2012

pawn Code:
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
            {
                GetPlayerPos(i, posx, posy, posz);
                tempposx = (oldposx -posx);
                tempposy = (oldposy -posy);
                tempposz = (oldposz -posz);
                if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16))) // If the player is within 16 meters
                {
                    SendClientMessage(i, col1, string);
                }
                else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8))) // within 8 meters
                {
                    SendClientMessage(i, col2, string);
                }
                else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4))) //4 meters
                {
                    SendClientMessage(i, col3, string);
                }
                else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2))) //2 meters
                {
                    SendClientMessage(i, col4, string);
                }
                else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) //1 meter
                {
                    SendClientMessage(i, col5, string);
                }
            }
            else
            {
                SendClientMessage(i, col1, string);
            }
        }
    }
    return 1;
}
try this.


Re: weird bug / crash by native SendClientMessage - leonardo1434 - 11.08.2012

Lol... what crappy you have made, you gonna send a message to a disconnect player. kinda dumb.


Re: weird bug / crash by native SendClientMessage - Devilxz97 - 11.08.2012

oh yea ?
im using this and it not send a message to a disconnect player.


Respuesta: Re: weird bug / crash by native SendClientMessage - dudaefj - 11.08.2012

Quote:
Originally Posted by Devilxz97
View Post
oh yea ?
im using this and it not send a message to a disconnect player.
yeah, it isn't, really, but how would that help ?