Help regarding a function I made.
#1

So I was trying to make a local client message function, similar to the ones RP servers to use to create a local chat however its not working and will not display any messages, I have no idea why.

Here is the function:
pawn Код:
SendLocalClientMessage(playerid, Float:dist, color, str[])
{
    if(IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        SendClientMessage(playerid, color, str);
        foreach(Player, i)
        {
            if(IsPlayerConnected(i) && i != playerid)
            {
                if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
                {
                    SendClientMessage(i, color, str);
                }
            }
        }
    }
    return 1;
}
And here is an example usage (uses ZCMD):
pawn Код:
CMD:test(playerid, params[])
{
    SendLocalClientMessage(playerid, 30.0, COLOR_GREY, "If you see this message, \"SendClientLocalMessage\" works");
    return 1;
}
If someone could point out where I went wrong and fix it so I don't make the same mistake again, it will be much appreciated.
Reply
#2

you don't want to use "IsPlayerConnected" In Foreach.

try this code:

pawn Код:
SendLocalClientMessage(playerid, Float:dist, color, str[])
{
    if(IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        SendClientMessage(playerid, color, str);
        foreach(Player, i)
        {
            if(i != playerid)
            {
                if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
                {
                    return SendClientMessage(i, color, str);
                }
            }
        }
    }
}
Reply
#3

Try this:
Код:
stock SendLocalClientMessage(playerid, Float:dist, color, str[])
{
     if(IsPlayerConnected(playerid))
     {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        SendClientMessage(playerid, color, str);
        foreach(Player, i)

        if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
        {
             return SendClientMessage(i, color, str);
        }
    }
    return 1;
}
And this:

Код:
CMD:test(playerid, params[])
{
        SendLocalClientMessage(playerid, COLOR_WHITE, "TEST 123");
        return 1;
}
Reply
#4

Hello Josh23761
Instead of the codes above, you could use the next code to avoid several 'ifs' that aren't really necessary and don't have the 'bug' of double messages
Both of above are wrong because if you use return in the message the function will end only with a message
pawn Код:
stock SendLocalClientMessage(playerid, Float:dist, color, str[])
{
    new Float:ppos[3];
    GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
    foreach(Player, i)//I'm not sure what foreach are you using because the foreach of ****** that I use is a little different, and it doesn't need use the 'if(IsPlayerConnected(i))'
    {
                if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
                SendClientMessage(i, color, str);
    }
}
Reply
#5

Thanks, but now I have another custom function that does not work:

pawn Код:
CreatePlayerMeString(playerid, astr[])
{
    new name[MAX_PLAYER_NAME], string[1024];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "* %s %s", name, astr);
    return string;
}
I know what is probably wrong, is that return string thing, but I dunno how else I could get it to work. Its suppose to take a string the user imputed, and format it to make a /me style string.

Example:
pawn Код:
new mestring = CreatePlayerMeString(playerid, "wishes that his custom function could work");
Reply
#6

First of all, string[1024] is a really big mistake that you are making. SendClientMessage can only send 144 characters, so you are creating way too big string.
CreatePlayerMeString would work like this.
Код:
CMD:me(playerid, params[])
{
	new string[128];
	format(string, sizeof(string), "%s", CreatePlayerMeString(playerid, params);
	SendClientMessage(playerid, -1, string);
	return 1:
}
You need to use it with format because it will return a string. You tried to store that string into an integer, which won't work.
Reply
#7

Quote:
Originally Posted by dominik523
Посмотреть сообщение
First of all, string[1024] is a really big mistake that you are making. SendClientMessage can only send 144 characters, so you are creating way too big string.
CreatePlayerMeString would work like this.
Код:
CMD:me(playerid, params[])
{
	new string[128];
	format(string, sizeof(string), "%s", CreatePlayerMeString(playerid, params);
	SendClientMessage(playerid, -1, string);
	return 1:
}
You need to use it with format because it will return a string. You tried to store that string into an integer, which won't work.
Ohh, right. So basically it was not the function, but the way I was actually trying to use it. Thanks man.
Reply
#8

Quote:
Originally Posted by dominik523
Посмотреть сообщение
First of all, string[1024] is a really big mistake that you are making. SendClientMessage can only send 144 characters, so you are creating way too big string.
CreatePlayerMeString would work like this.
Код:
CMD:me(playerid, params[])
{
	new string[128];
	format(string, sizeof(string), "%s", CreatePlayerMeString(playerid, params);
	SendClientMessage(playerid, -1, string);
	return 1:
}
You need to use it with format because it will return a string. You tried to store that string into an integer, which won't work.
Still not working.
Reply
#9

Still need help, and I need it fairly fast please.
Reply
#10

try this:
pawn Код:
SendLocalClientMessage(playerid, Float:dist, color, str[])
{
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        SendClientMessage(playerid, color, str);
        for(new i = 0; i < MAX_PLAYERS; i ++ )
        {
            if(IsPlayerConnected(i) && i != playerid)
            {
                if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
                {
                    SendClientMessage(i, color, str);
                }
            }
        }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)