/(w)hisper crashes the server lol wtf
#1

this command compiles perfectly...but when someone uses it ingame it crashes the server

pawn Код:
COMMAND:w(playerid, params[])
{
    return cmd_whisper(playerid, params);
}
COMMAND:whisper(playerid, params[])
{
    if (PlayerInfo[playerid][pSpawn] == 1){

        new COLOR = GetPlayerColor(playerid);

        new idx,string[512],length = strlen(params);
        while ((idx < length) && (params[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[512];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = params[idx];
            idx++;
        }
        result[idx - offset] = EOS;

        if (PlayerInfo[playerid][pMute] == 1)
        {
            SCM(playerid,COLOR_ERROR,"#Error: You Muted.");
            return 1;
        }

        if (!strlen(result))
        {
            SendClientMessage(playerid, COLOR_ERROR, "USAGE: /whisper (message).");
            return 1;
        }

        format(string, sizeof(string), "(WHISPER) %s (%d): %s",PlayerInfo[playerid][pName],playerid,result);
        SendClientMessage(playerid,COLOR, string);
        for (new i = 0; i < GetMaxPlayers(); i++)
        {

            i = GetClosestPlayer(playerid);
            if (IsPlayerConnected(i))
            {
                if (i != playerid)
                {
                    if (GetDistanceBetweenPlayers(playerid, i) < 10)
                    {
                        SendClientMessage(i,COLOR, string);
                    }
                }
            }
        }

    }else{
        SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
    }

    return 1;
}
Reply
#2

Try this:
PHP код:
COMMAND:w(playeridparams[])
{
    return 
cmd_whisper(playeridparams);
}
COMMAND:whisper(playeridparams[])
{
    if (
PlayerInfo[playerid][pSpawn] == 1){

        new 
idx,string[144],length strlen(params);
        while ((
idx length) && (params[idx] <= ' '))
        {
            
idx++;
        }
        new 
offset idx;
        new 
result[144];
        while ((
idx length) && ((idx offset) < (sizeof(result) - 1)))
        {
            
result[idx offset] = params[idx];
            
idx++;
        }
        
result[idx offset] = EOS;

        if (
PlayerInfo[playerid][pMute] == 1)
        {
            
SCM(playerid,COLOR_ERROR,"#Error: You Muted.");
            return 
1;
        }

        if (!
strlen(result))
        {
            
SendClientMessage(playeridCOLOR_ERROR"USAGE: /whisper (message).");
            return 
1;
        }

        
format(stringsizeof(string), "(WHISPER) %s (%d): %s",PlayerInfo[playerid][pName],playerid,result);
        
SendClientMessage(playerid,GetPlayerColor(playerid), string);
        for (new 
0GetMaxPlayers(); i++)
        {

            
GetClosestPlayer(playerid);
            if (
IsPlayerConnected(i))
            {
                if (
!= playerid)
                {
                    if (
GetDistanceBetweenPlayers(playeridi) < 10)
                    {
                        
SendClientMessage(i,GetPlayerColor(playerid), string);
                    }
                }
            }
        }

    }else{
        
SendClientMessage(playeridCOLOR_ERROR"You Cannot Use This Command When You're Dead.");
    }

    return 
1;

Post the log of crashdetect.dll
Reply
#3

COMMAND:w(playerid, params[]) return cmd_whisper(playerid, params);
Try this
Reply
#4

Quote:
Originally Posted by StuartIndia
Посмотреть сообщение
COMMAND:w(playerid, params[]) return cmd_whisper(playerid, params);
Try this
If you looked at his code, it's the same... It's not that.
Reply
#5

What exactly are you trying to do with these lines
Код:
new idx,string[512],length = strlen(params);
		while ((idx < length) && (params[idx] <= ' '))
		{
			idx++;
		}
		new offset = idx;
		new result[512];
		while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
		{
			result[idx - offset] = params[idx];
			idx++;
		}
		result[idx - offset] = EOS;
And also this loop will send the nearest player many messages..
Код:
 for (new i = 0; i < GetMaxPlayers(); i++)
        {

            i = GetClosestPlayer(playerid);
            if (IsPlayerConnected(i))
            {
                if (i != playerid)
                {
                    if (GetDistanceBetweenPlayers(playerid, i) < 10)
                    {
                        SendClientMessage(i,GetPlayerColor(playerid), string);
                    }
                }
            }
        }
If u are trying to send message to all players within range of 10 to playerid then use this
Код:
 for (new i = 0; i < GetMaxPlayers(); i++)
        {
            if (IsPlayerConnected(i))
            {
                if (i != playerid)
                {
                    if (GetDistanceBetweenPlayers(playerid, i) < 10)
                    {
                        SendClientMessage(i,GetPlayerColor(playerid), string);
                    }
                }
            }
        }
Reply
#6

^^ This fella is on to something...
Reply
#7

Let me make your life easier:

Download this (check out the features as well and if you like it): https://sampforum.blast.hk/showthread.php?tid=520734

And then you could do this:
pawn Код:
CMD:whisper(playerid, params[])
{
    new string[256], message[128];
    if(sscanf(params, "s[128]", message)) return SendMessage(playerid, 0xFFFF00FF, "Usage: /whisper (message).");
    format(string, sizeof(string), "[WHISPER]: (%d) %s: %s.", playerid, PlayerName(playerid), message);
    SendWhisperMessage(10.0, playerid, 0x00FFFFFF, string);
    return 1;
}

CMD:w(playerid, params[]) return cmd_whisper(playerid, params);

stock PlayerName(playerid)
{
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    return pname;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)