How to use custom functions inside custom functions.
#1

Hey, I am having a small problem, I made two functions, both of which would work perfectly, but I have a problem with it not working, and I suspect this to be due to the fact in one of the custom functions I was using a custom function.

Is there a way I could use a custom function inside a custom function?

Here is my functions:
pawn Code:
SendLocalClientMessage(playerid, Float:dist, color, str[])
{
    new Float:ppos[3];
    GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
    foreach(Player, i)
    {
        if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
        SendClientMessage(i, color, str);
    }
}
pawn Code:
SendClientMeMessage(playerid, astr[])
{
    new name[MAX_PLAYER_NAME], string[144];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "* %s %s", name, astr);
    SendLocalClientMessage(playerid, 30.0, COLOR_RP, string);
}
And an example of usage (uses ZCMD):
pawn Code:
CMD:test(playerid, params[])
{
    SendClientMeMessage(playerid, "is happy because is his /me command works.");
    return 1;
}
Please help me with this issue so I can get it fixed ASAP.
Reply
#2

what exactly doesn't work? does pawn give any errors/warnings or is it just failing to work in-game?
Reply
#3

Quote:
Originally Posted by Smileys
View Post
what exactly doesn't work? does pawn give any errors/warnings or is it just failing to work in-game?
Fails to actual work IG, I know the me function would work if I use SendClientMessage and I know the SendLocalClientMessage works without being used inside the function, so I have no idea WTF it is.
Reply
#4

hm, try this

pawn Code:
SendLocalClientMessage(playerid, Float:dist, color, str[])
{
    new Float:ppos[3];
    GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
    foreach(Player, i)
    {
        if(IsPlayerInRangeOfPoint(i, dist, ppos[0], ppos[1], ppos[2]))
        SendClientMessage(i, color, str);
    }
    SendClientMessage( playerid, color, str );
}
Reply
#5

They don't look like they have mistakes in them, but try these:
pawn Code:
SendLocalClientMessage(playerid, Float:range, color, str[])
{
    if (IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        foreach(Player, i)
        {
            if(IsPlayerInRangeOfPoint(i, range, ppos[0], ppos[1], ppos[2]))
            {
                SendClientMessage(i, color, str);
            }
        }
        return 1;
    }
    return 0;
}

SendClientMeMessage(playerid, astr[])
{
    if (IsPlayerConnected(playerid))
    {
        new name[MAX_PLAYER_NAME], string[144];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "* %s %s", name, astr);
        SendLocalClientMessage(playerid, 30.0, COLOR_RP, string);
        return 1;
    }
    return 0;
}
EDIT: The post above me only added a SendClientMessage, which would cause two messages for the playerid.
Reply
#6

Quote:
Originally Posted by Stinged
View Post
They don't look like they have mistakes in them, but try these:
pawn Code:
SendLocalClientMessage(playerid, Float:range, color, str[])
{
    if (IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        foreach(Player, i)
        {
            if(IsPlayerInRangeOfPoint(i, range, ppos[0], ppos[1], ppos[2]))
            {
                SendClientMessage(i, color, str);
            }
        }
        return 1;
    }
    return 0;
}

SendClientMeMessage(playerid, astr[])
{
    if (IsPlayerConnected(playerid))
    {
        new name[MAX_PLAYER_NAME], string[144];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "* %s %s", name, astr);
        SendLocalClientMessage(playerid, 30.0, COLOR_RP, string);
        return 1;
    }
    return 0;
}
EDIT: The post above me only added a SendClientMessage, which would cause two messages for the playerid.
Nah, this ain't working.
Reply
#7

Anyone else have any ideas?
Reply
#8

I would suggest you to only use SendLocalMessage because you are using SendMeMessage in only /me command, right? So you can simply write something like this:
pawn Code:
stock ReturnName(playerid)
{
    new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, sizeof(string));
    return string;
}

SendLocalClientMessage(playerid, Float:range, color, str[])
{
    if (IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        foreach(Player, i)
        {
            if(IsPlayerInRangeOfPoint(i, range, ppos[0], ppos[1], ppos[2]))
            {
                SendClientMessage(i, color, str);
            }
        }
        return 1;
    }
    return 0;
}

CMD:me(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /me [action]");
    new string[128];
    format(string, sizeof(string), "* %s: %s", ReturnName(playerid), params);
    SendLocalClientMessage
    return 1;
}
SendLocalMessage is used in more than one command, so we are making function for it, while SendMeMessage is used only in /me so it's not that special to create it's own function.
Reply
#9

Quote:
Originally Posted by dominik523
View Post
I would suggest you to only use SendLocalMessage because you are using SendMeMessage in only /me command, right? So you can simply write something like this:
pawn Code:
stock ReturnName(playerid)
{
    new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, sizeof(string));
    return string;
}

SendLocalClientMessage(playerid, Float:range, color, str[])
{
    if (IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        foreach(Player, i)
        {
            if(IsPlayerInRangeOfPoint(i, range, ppos[0], ppos[1], ppos[2]))
            {
                SendClientMessage(i, color, str);
            }
        }
        return 1;
    }
    return 0;
}

CMD:me(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /me [action]");
    new string[128];
    format(string, sizeof(string), "* %s: %s", ReturnName(playerid), params);
    SendLocalClientMessage
    return 1;
}
SendLocalMessage is used in more than one command, so we are making function for it, while SendMeMessage is used only in /me so it's not that special to create it's own function.
Thanks for the help, but on the contract its not just for a /me command, its also for automatic /me messages, you know? Like when you do /lock it automatically sends the *Bob Jim has unlocked his vehicle*. So I figured it would be quicker to make a function for it since I have OCD I HAVE to make my code as neat as possible. I will use your method since it basically does the same thing.
Reply
#10

Quote:
Originally Posted by dominik523
View Post
I would suggest you to only use SendLocalMessage because you are using SendMeMessage in only /me command, right? So you can simply write something like this:
pawn Code:
stock ReturnName(playerid)
{
    new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, sizeof(string));
    return string;
}

SendLocalClientMessage(playerid, Float:range, color, str[])
{
    if (IsPlayerConnected(playerid))
    {
        new Float:ppos[3];
        GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
        foreach(Player, i)
        {
            if(IsPlayerInRangeOfPoint(i, range, ppos[0], ppos[1], ppos[2]))
            {
                SendClientMessage(i, color, str);
            }
        }
        return 1;
    }
    return 0;
}

CMD:me(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /me [action]");
    new string[128];
    format(string, sizeof(string), "* %s: %s", ReturnName(playerid), params);
    SendLocalClientMessage
    return 1;
}
SendLocalMessage is used in more than one command, so we are making function for it, while SendMeMessage is used only in /me so it's not that special to create it's own function.
Nope, still not working.

pawn Code:
CMD:seatbelt(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid, COLOR_GREY, "You are not inside a vehicle!");
    }
    else
    {
        new eqstr[1024], ueqstr[1024];
        //eqstr = CreatePlayerMeString(playerid, "reaches over to grab his seatbelt before clipping it in.");
        //ueqstr = CreatePlayerMeString(playerid, "reaches down to unclip his seatbelt before letting it slide back.");
        format(eqstr, sizeof(eqstr), "* %s reaches over to grab his seatbelt before clipping it in.", ReturnName(playerid));
        format(ueqstr, sizeof(ueqstr), "* %s reaches over to grab his seatbelt before clipping it in.", ReturnName(playerid));
        if(!IsPlayerSeatbelt(playerid))
        {
            SendLocalClientMessage(playerid, 30.0, COLOR_RP, eqstr);
            Seatbelt[playerid] = true;
        }
        else if(IsPlayerSeatbelt(playerid))
        {
            SendLocalClientMessage(playerid, 30.0, COLOR_RP, ueqstr);
            Seatbelt[playerid] = false;
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)