Help with OnPlayerText
#1

Hey all,

I need help with the conversion of a command to use under OnPlayerText. The point of this function is to replace the need for the use of /c to talk over a cellphone when a player is on a call. Below I've posted the original code, and the code I've formatted for use under OnPlayerText.

Original:
pawn Код:
else if((strcmp(cmd, "/cell", true) == 0) || (strcmp(cmd, "/c", true) == 0))
    {
        if(PlayerHasItem(playerid, ITEM_PHONE) == INVALID_ITEM_SLOT) {
            SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: You need to buy a phone first.");
            return 1;
        }

        if(gCalling[playerid][CELL_CALLTYPE] != 0) // player or system call
        {
            if(strcount(cmdtext, ' ') < 2)
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /cell [message]");
                return 1;
            }

            idx++; // remove the space
            strmid(string, cmdtext, idx, sizeof(string));

            new text[255];
            //new pn[24];
            //new pn = GetUserName(playerid);
            format(text, sizeof(text), "%s (cellphone): %s", GetUserName(playerid), string);
            SendLocalMessage(20.0, playerid, text, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);

            new targetid = gCalling[playerid][CELL_PLAYERID];
            if(gCalling[playerid][CELL_CALLTYPE] == 1) //player call
            {
                if(!IsPlayerConnected(targetid))
                {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "* Line goes dead.");
                    StopCall(playerid);
                    return 1;
                }

                format(text, sizeof(text), "%s (cellphone): %s", GetUserName(playerid), string);
                SendLocalMessage(20.0, playerid, text, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
            }
            else
            {
                //non player number
                SystemCall(playerid, targetid, string);
                format(text, sizeof(text), "%s (cellphone): %s", GetUserName(targetid), string);
                SendClientMessage(playerid, COLOR_WHITE, text);
                return 1;
            }
            format(text, sizeof(text), "%s (cellphone): %s", GetUserName(targetid), string);
            SendClientMessage(playerid, COLOR_WHITE, text);
            if (IsPlayerInAnyVehicle(playerid)) SendFBIVanMessage(playerid, COLOR_FBI1,COLOR_FBI2,COLOR_FBI3,COLOR_FBI4,COLOR_FBI5, string, 40.0);
            else SendFBIVanMessage(playerid, COLOR_FBI1,COLOR_FBI2,COLOR_FBI3,COLOR_FBI4,COLOR_FBI5, string, 60.0);
            if (PlayerInfo[playerid][pWired] == 1) format(text,sizeof(text),"[WIRE][Cell] %s says: %s",PlayerInfo[playerid][pName],string), SendFBIMessage(NICESKY, text);
        }
        else
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: You do not have a call.");
        }
        return 1;
    }
Modified:
pawn Код:
if(gCalling[playerid][CELL_CALLTYPE] != 0) // player or system call
        {
            idx++; // remove the space
            strmid(string, cmdtext, idx, sizeof(string));

            new text[255];
            //new pn[24];
            //new pn = GetUserName(playerid);
            format(text, sizeof(text), "%s (cellphone): %s", GetUserName(playerid), string);
            SendLocalMessage(20.0, playerid, text, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);

            new targetid = gCalling[playerid][CELL_PLAYERID];
            if(gCalling[playerid][CELL_CALLTYPE] == 1) //player call
            {
                if(!IsPlayerConnected(targetid))
                {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "* Line goes dead.");
                    StopCall(playerid);
                    return 1;
                }

                format(text, sizeof(text), "%s (cellphone): %s", GetUserName(playerid), string);
                SendLocalMessage(20.0, playerid, text, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
            }
            else
            {
                //non player number
                SystemCall(playerid, targetid, string);
                format(text, sizeof(text), "%s (cellphone): %s", GetUserName(targetid), string);
                SendClientMessage(playerid, COLOR_WHITE, text);
                return 1;
            }
            format(text, sizeof(text), "%s (cellphone): %s", GetUserName(targetid), string);
            SendClientMessage(playerid, COLOR_WHITE, text);
            if (IsPlayerInAnyVehicle(playerid)) SendFBIVanMessage(playerid, COLOR_FBI1,COLOR_FBI2,COLOR_FBI3,COLOR_FBI4,COLOR_FBI5, string, 40.0);
            else SendFBIVanMessage(playerid, COLOR_FBI1,COLOR_FBI2,COLOR_FBI3,COLOR_FBI4,COLOR_FBI5, string, 60.0);
            if (PlayerInfo[playerid][pWired] == 1) format(text,sizeof(text),"[WIRE][Cell] %s says: %s",PlayerInfo[playerid][pName],string), SendFBIMessage(NICESKY, text);
        }
    return 1;
}
I also get these few errors upon compiling.

Код:
C:\Documents and Settings\Admin\Desktop\SA-MP\GameMode\Aria v2 31-1-10 Final.pwn(3914) : warning 225: unreachable code
C:\Documents and Settings\Admin\Desktop\SA-MP\GameMode\Aria v2 31-1-10 Final.pwn(3916) : error 017: undefined symbol "idx"
C:\Documents and Settings\Admin\Desktop\SA-MP\GameMode\Aria v2 31-1-10 Final.pwn(3916) : warning 215: expression has no effect
C:\Documents and Settings\Admin\Desktop\SA-MP\GameMode\Aria v2 31-1-10 Final.pwn(3917) : error 017: undefined symbol "cmdtext"
C:\Documents and Settings\Admin\Desktop\SA-MP\GameMode\Aria v2 31-1-10 Final.pwn(3917) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Admin\Desktop\SA-MP\GameMode\Aria v2 31-1-10 Final.pwn(3919) : warning 219: local variable "text" shadows a variable at a preceding level
These errors are all corresponding to this part of the code. I've recognised the error regarding 'cmdtext' referring to the line:

pawn Код:
strmid(string, cmdtext, idx, sizeof(string));
.. and would anybody be able to suggest, looking at my code, what I can replace to make this work?

Cheers.
Reply
#2

It goes in OnPlayerCommandText, not OnPlayerText.
Reply
#3

The second one is that you need right?
Reply
#4

Quote:
Originally Posted by CJ101
It goes in OnPlayerCommandText, not OnPlayerText.
Quote:
Originally Posted by UberSocks
The point of this function is to replace the need for the use of /c to talk over a cellphone when a player is on a call. Below I've posted the original code, and the code I've formatted for use under OnPlayerText.
I've modified it to my capability, I just need someone to correct it and make sure it's fine so I can avoid the errors when compiling. I'm replacing a command with a function to be used under OnPlayerText.

Quote:
Originally Posted by Chuck_Taylor
The second one is that you need right?
Correct.
Reply
#5

Bump, someone please help.
Reply
#6

Bump. Is there anyone that can help?
Reply
#7

Bump, really need to fix this.

If anyone could help I'd really appreciate it.
Reply
#8

Don't know why its not working, but this still applies:

READ THIS BEFORE POSTING! (RULES TO FOLLOW)

Quote:

b) Do not bump
Some people apparently think they are important enough to bump their own topic after 10 minutes.
You can bump topics when the last reply is at least 12 hours old.

Reply
#9

If you post your entire onplayertext i will take a look, better yet put it in a pastbin.
With the code you have, its hard to see what you should and shouldn't have in there.
Reply
#10

pawn Код:
idx++; // remove the space
            strmid(string, cmdtext, idx, sizeof(string));

            new text[255];
            //new pn[24];
            //new pn = GetUserName(playerid);
            format(text, sizeof(text), "%s (cellphone): %s", GetUserName(playerid), string);
            SendLocalMessage(20.0, playerid, text, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
change this part to

pawn Код:
new msg[255];
            //new pn[24];
            //new pn = GetUserName(playerid);
            format(msg, sizeof(msg), "%s (cellphone): %s", GetUserName(playerid), text);
            SendLocalMessage(20.0, playerid, msg, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)