SA-MP Forums Archive
Help with OnPlayerText - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with OnPlayerText (/showthread.php?tid=124603)



Help with OnPlayerText - UberSocks - 31.01.2010

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.


Re: Help with OnPlayerText - CJ101 - 31.01.2010

It goes in OnPlayerCommandText, not OnPlayerText.


Re: Help with OnPlayerText - pierhs - 31.01.2010

The second one is that you need right?


Re: Help with OnPlayerText - UberSocks - 31.01.2010

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.


Re: Help with OnPlayerText - UberSocks - 31.01.2010

Bump, someone please help.


Re: Help with OnPlayerText - UberSocks - 31.01.2010

Bump. Is there anyone that can help?


Re: Help with OnPlayerText - UberSocks - 01.02.2010

Bump, really need to fix this.

If anyone could help I'd really appreciate it.


Re: Help with OnPlayerText - mansonh - 01.02.2010

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.




Re: Help with OnPlayerText - mansonh - 01.02.2010

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.


Re: Help with OnPlayerText - MadeMan - 01.02.2010

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);