Warnings and script don't work
#1

Hello, before the thread sorry for my bad english but i try my best

So I made my first system to command /me, i saw some in the Internet but i decide to do my own, but I can't put it working, when I try /me the server says " Unknown Command" btw the /me is local, if someone could help me with the warnings and put this working I would apreciate

So here it goes the code:

Код:
public OnPlayerCommandText(playerid, cmdtext[])

if(IsPlayerConnected(playerid))
{
		new Float: radi, Float: str;
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        for(new i = 0; i < MAX_PLAYERS; i++)

	    if(IsPlayerConnected(i))
{
                GetPlayerPos(i, posx, posy, posz);
                tempposx = (oldposx -posx);
                tempposy = (oldposy -posy);
                tempposz = (oldposz -posz);



   if (!strcmp(cmdtext, "/me", true, 3))
    {
        if(!cmdtext[3])return SendClientMessage(playerid, vermelho, "Usa: /me [Aзгo]"); // Usa: /me Aзгo = [EN] Use: /me Action
        new str[128];
        GetPlayerName(playerid, str, sizeof(str));
        format(str, sizeof(str), "* %s %s", str, cmdtext[4]);
        if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
        SendClientMessage(i, roxo, "str");
	}
	 
	 {
        
        return 0;
}
    return 0;
}
}
The Warnings are:

Quote:

C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(41) : warning 217: loose indentation
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(44) : warning 219: local variable "str" shadows a variable at a preceding level
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(51) : warning 217: loose indentation
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(55) : warning 225: unreachable code
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(55) : warning 217: loose indentation
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(26) : warning 203: symbol is never used: "str"
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(26 -- 61) : warning 209: function "OnPlayerCommandText" should return a value
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


7 Warnings.

Sorry if the system is too bad, but I'm a newbie in pawno, and I'm trying hard
Reply
#2

I just fixed the indentation (..I think?), it was really messed up (tons of missing brackets and incorrect placement of return statements) and you're better off using something like ZCMD or sscanf, not strcmp.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(IsPlayerConnected(playerid))
    {
        new Float: radi, Float: str;
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;

        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                GetPlayerPos(i, posx, posy, posz);
                tempposx = (oldposx -posx);
                tempposy = (oldposy -posy);
                tempposz = (oldposz -posz);

                if (!strcmp(cmdtext, "/me", true, 3))
                {
                    if(!cmdtext[3]) return SendClientMessage(playerid, vermelho, "Usa: /me [Aзгo]");
                    new str[128];
                    GetPlayerName(playerid, str, sizeof(str));
                    format(str, sizeof(str), "* %s %s", str, cmdtext[4]);

                    if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
                    {
                        SendClientMessage(i, roxo, "str");
                    }
                }

                return 0; // no clue why you're doing this here but you're better off using "break;"
            }
        }
    }

    return 0;
}
Reply
#3

Thank you Mionee, you helped a lot fixing the warnings, about using ZCMD or sscanf, I don't know what that is but I will do my research and try to understand, the system still don't work, idk why, when i do
* MacacoDoArtico
the server says: " Usa: /me Aзгo " = [EN] Use: /me Action
but when i do /me [text] the server says " Unknown Command "
Thanks for the help Mionee it was really handy
Reply
#4

Try removing return 0; in the loop and replace it with break;

And why are you making it really complicated?
You're making /me send a local message right?
If so, just use GetPlayerPos and IsPlayerInRangeOfPoint in a loop.

And just like Mionee said, you should start using zcmd.
https://sampforum.blast.hk/showthread.php?tid=91354

If you started using it, use this instead:
pawn Код:
CMD:me(playerid, params[])
{
    if (isnull(params)) // Checking if params is null (params = text after the command)
        return SendClientMessage(playerid, -1, "USAGE: /me [text]");
       
    new Float:x, Float:y, Float:z, name[24], string[128];
    GetPlayerPos(playerid, x, y, z);
    GetPlayerName(playerid, name, sizeof (name));
    format(string, sizeof (string), "* %s %s", name, params); // Just like I said before, params = text after the command
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            if (IsPlayerInRangeOfPoint(i, 16, x, y, z))
            {
                SendClientMessage(playerid, -1, string);
            }
        }
        break;
    }
    return 1;
}
Reply
#5

Here's an example using the methods Stinged and myself recommended (said functions and sscanf, zcmd and foreach):

pawn Код:
// Outside of any callback:
CMD:me(playerid, params[])
{
    // Defining new variables; string = 144 (perfect size), text = 120 & name = 24 (MAX_PLAYER_NAME)
    // Also defining the floats for GetPlayerPos which we'll use after
    static string[144], text[120], name[MAX_PLAYER_NAME], Float: pX, Float: pY, Float: pZ;
    GetPlayerName(playerid, name, sizeof(name));   

    // Defining the specifiers and params to be used, if none are used, return an error message
    if(sscanf(params, "s[120]", text)) return SendClientMessage(playerid, -1, "/me [action]");

    // Format the string, it'll show as "name text"
    format(string, sizeof(string), "%s %s", name, text);
    GetPlayerPos(playerid, pX, pY, Pz); // Getting the player's position

    // Starting a loop using foreach and "i" as variable
    foreach(new i: Player)
    {
        // If "i" is in range (6.0) of playerid's position
        if(IsPlayerInRangeOfPoint(i, 6.0, pX, pY, pZ))
        {
            // Send the formatted message with color -1 (white)
            SendClientMessage(i, -1, string);
            // We don't break the loop because that would only send the message to only one player
        }
    }

    // Return a positive value
    return 1;
}
Without the comments, that would make a much more compact, efficient and simpler version of your code:

pawn Код:
CMD:me(playerid, params[])
{
    static string[144], text[120], name[MAX_PLAYER_NAME], Float: pX, Float: pY, Float: pZ;
    GetPlayerName(playerid, name, sizeof(name));   

    if(sscanf(params, "s[120]", text)) return SendClientMessage(playerid, -1, "/me [action]");

    format(string, sizeof(string), "%s %s", name, text);
    GetPlayerPos(playerid, pX, pY, Pz);

    foreach(new i: Player)
    {
        if(IsPlayerInRangeOfPoint(i, 6.0, pX, pY, pZ))
        {
            SendClientMessage(i, -1, string);
        }
    }

    return 1;
}
Reply
#6

Thanks a lot to both of you, helped a lot, I will see if it works
Reply
#7

Got this errors:

Quote:

C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(32) : error 017: undefined symbol "Pz"
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(34) : error 017: undefined symbol "foreach"
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(34) : error 029: invalid expression, assumed zero
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(34) : error 017: undefined symbol "Player"
C:\Users\Joka\Desktop\New folder (2)\gamemodes\GamemodeRP.pwn(34) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.

Reply
#8

Sorry for the double posts but i tried stinged's code and compiles, but when I enter in the server says " Stay in the world boundries "
Reply
#9

You're better off using foreach, you can download it here: https://sampforum.blast.hk/showthread.php?tid=92679

Also, for your error, I mistyped Pz on the GetPlayerPos line.

Change

pawn Код:
GetPlayerPos(playerid, pX, pY, Pz);
to

pawn Код:
GetPlayerPos(playerid, pX, pY, pZ);
Reply
#10

Got this error because of foreach
Quote:

C:\Users\Joka\Desktop\New folder (2)\pawno\include\foreach.inc(22 : fatal error 100: cannot read from file: "YSI\internal\y_natives"

What i do?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)