Problem with /pm cmd
#1

Hi,i maked a fast /pm cmd for my GM.

I got this:

pawn Код:
new pMessage[128];
    new gMessage[128];
    new pName[MAX_PLAYER_NAME+1];
    new iName[MAX_PLAYER_NAME+1];

dcmd_pm(playerid, params[])
    {
        if(!strlen(params) || strlen(params) > 5) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        new id = strval(params);
        gMessage = strrest(cmdtext,idx);
        if(!strlen(gMessage)) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,COLOR_YELLOW,"/pm : Bad player ID");
            return 1;
        }
        if(playerid != id) {
            GetPlayerName(id,iName,sizeof(iName));
            GetPlayerName(playerid,pName,sizeof(pName));
            format(pMessage,sizeof(pMessage),"<Private Message to %s(%d): %s",iName,id,gMessage);
            SendClientMessage(playerid,COLOR_YELLOW,pMessage);
            format(pMessage,sizeof(pMessage),">Private Message from %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,COLOR_YELLOW,pMessage);
            new str[100];
            format(str,sizeof str," **PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            SendClientMessageToAdmins(COLOR_GREEN,str,1);
            new str1[100];
            format(str1,sizeof str1,"0,5PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            IRC_GroupSay(gGroupID, channel, str1);
            printf(pMessage);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
            printf("PM: %s",pMessage);
        }
        else {
            SendClientMessage(playerid,COLOR_YELLOW,"You cannot PM yourself");
        }
        return 1;
}
I got this errors:

Код:
C:\Documents and Settings\k\Desktop\SFWAR.pwn(802) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1063) : error 017: undefined symbol "strrest"
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1063) : error 033: array must be indexed (variable "gMessage")
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1081) : warning 202: number of arguments does not match definition
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1120) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1120) : warning 219: local variable "iName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1158) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1158) : warning 219: local variable "iName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1180) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1180) : warning 219: local variable "iName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1203) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1203) : warning 219: local variable "iName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1230) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1230) : warning 219: local variable "iName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1261) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Documents and Settings\k\Desktop\SFWAR.pwn(1261) : warning 219: local variable "iName" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
What's wrong?

If i remove the variable pName i get the "undefenied symbol",lol.
Reply
#2

Код:
new pMessage[128];
    new gMessage[128];
    new pName[MAX_PLAYER_NAME];
    new iName[MAX_PLAYER_NAME];

dcmd_pm(playerid, params[])
    {
        if(!strlen(params) || strlen(params) > 5) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        new id = strval(params);
        gMessage = strrest(cmdtext,idx);
        if(!strlen(gMessage)) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,COLOR_YELLOW,"/pm : Bad player ID");
            return 1;
        }
        if(playerid != id) {
            GetPlayerName(id,iName,sizeof(iName));
            GetPlayerName(playerid,pName,sizeof(pName));
            format(pMessage,sizeof(pMessage),"<Private Message to %s(%d): %s",iName,id,gMessage);
            SendClientMessage(playerid,COLOR_YELLOW,pMessage);
            format(pMessage,sizeof(pMessage),">Private Message from %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,COLOR_YELLOW,pMessage);
            new str[100];
            format(str,sizeof str," **PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            SendClientMessageToAdmins(COLOR_GREEN,str,1);
            new str1[100];
            format(str1,sizeof str1,"0,5PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            IRC_GroupSay(gGroupID, channel, str1);
            printf(pMessage);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
            printf("PM: %s",pMessage);
        }
        else {
            SendClientMessage(playerid,COLOR_YELLOW,"You cannot PM yourself");
        }
        return 1;
}
Reply
#3

What has changed?I see the normal errors..
Reply
#4

BUMP!
Reply
#5

pawn Код:
dcmd_pm(playerid, params[])
    {
    new pMessage[128];
    new gMessage[128];
    new pName[MAX_PLAYER_NAME+1];
    new iName[MAX_PLAYER_NAME+1];
        if(!strlen(params) || strlen(params) > 5) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        new id = strval(params);
        gMessage = strrest(cmdtext,idx);
        if(!strlen(gMessage)) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,COLOR_YELLOW,"/pm : Bad player ID");
            return 1;
        }
        if(playerid != id) {
            GetPlayerName(id,iName,sizeof(iName));
            GetPlayerName(playerid,pName,sizeof(pName));
            format(pMessage,sizeof(pMessage),"<Private Message to %s(%d): %s",iName,id,gMessage);
            SendClientMessage(playerid,COLOR_YELLOW,pMessage);
            format(pMessage,sizeof(pMessage),">Private Message from %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,COLOR_YELLOW,pMessage);
            new str[100];
            format(str,sizeof str," **PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            SendClientMessageToAdmins(COLOR_GREEN,str,1);
            new str1[100];
            format(str1,sizeof str1,"0,5PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            IRC_GroupSay(gGroupID, channel, str1);
            printf(pMessage);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
            printf("PM: %s",pMessage);
        }
        else {
            SendClientMessage(playerid,COLOR_YELLOW,"You cannot PM yourself");
        }
        return 1;
}
Reply
#6

Change the name of the pName variable because one already exists with that name. strrest is an undefined sybol so you dont have that function in your code.
Reply
#7

... Dont get worry. Try this:
pawn Код:
new pMessage[128];
    new gMessage;
    new pName[MAX_PLAYER_NAME+1];
    new iName[MAX_PLAYER_NAME+1];

dcmd_pm(playerid, params[])
    {
        new gMessage,id,tmp[256],tmp2[256],Index;
        tmp = strtok(params,Index);
        tmp2 = strtok(params,Index);
        id = strval(tmp);
        gMessage = strval(tmp2);
        if(!strval(tmp) && !strval(tmp2) || strlen(tmp) > 5)
        {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        if(!strval(tmp2))
        {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        if(!IsPlayerConnected(id))
        {
            SendClientMessage(playerid,COLOR_YELLOW,"/pm : Bad player ID");
            return 1;
        }
        if(playerid != id)
        {
            GetPlayerName(id,iName,sizeof(iName));
            GetPlayerName(playerid,pName,sizeof(pName));
            format(pMessage,sizeof(pMessage),"<Private Message to %s(%d): %s",iName,id,gMessage);
            SendClientMessage(playerid,COLOR_YELLOW,pMessage);
            format(pMessage,sizeof(pMessage),">Private Message from %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,COLOR_YELLOW,pMessage);
            new str[100];
            format(str,sizeof str," **PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            SendClientMessageToAdmins(COLOR_GREEN,str,1);
            new str1[100];
            format(str1,sizeof str1,"0,5PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            IRC_GroupSay(gGroupID, channel, str1);
            printf(pMessage);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
            printf("PM: %s",pMessage);
        }
        else
        {
            SendClientMessage(playerid,COLOR_YELLOW,"You cannot PM yourself");
        }
        return 1;
}
Reply
#8

@blackwave,your code returns lots of "pName shadows a variable at precedeing level".


Xeploit,i edited in this way:

Код:
dcmd_pm(playerid, params[])
    {
    new pMessage[128];
    new gMessage[128];
    new pName[MAX_PLAYER_NAME+1];
    new iName[MAX_PLAYER_NAME+1];
        if(!strlen(params) || strlen(params) > 5) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        new id = strval(params);
        if(!strlen(gMessage)) {
            SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (id) (message)");
            return 1;
        }
        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,COLOR_YELLOW,"/pm : Bad player ID");
            return 1;
        }
        if(playerid != id) {
            GetPlayerName(id,iName,sizeof(iName));
            GetPlayerName(playerid,pName,sizeof(pName));
            format(pMessage,sizeof(pMessage),"<Private Message to %s(%d): %s",iName,id,gMessage);
            SendClientMessage(playerid,COLOR_YELLOW,pMessage);
            format(pMessage,sizeof(pMessage),">Private Message from %s(%d): %s",pName,playerid,gMessage);
            SendClientMessage(id,COLOR_YELLOW,pMessage);
            new str[100];
            format(str,sizeof str," **PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            SendMessageToAdmins(COLOR_GREEN,str);
            new str1[100];
            format(str1,sizeof str1,"0,5PM from %s (%d) to %s (%d): %s",pName,playerid,iName,id,gMessage);
            IRC_GroupSay(gGroupID, IRC_CHANNEL, str1);
            printf(pMessage);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
            printf("PM: %s",pMessage);
        }
        else {
            SendClientMessage(playerid,COLOR_YELLOW,"You cannot PM yourself");
        }
        return 1;
}
But if i do /pm 1 test

it show me the normal message: /pm id message

And doesnt work.
Reply
#9

You will always get the "pName shadows a variable at precedeing level" warning until you rename that variable... no matter what, you need to change the name of that variable.
Reply
#10

use sscanf...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)