• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] string manipulation i/o and proper orientation order
#1
Question 
Subject

string manipulation i/o and proper orientation order



Hello community! today i want to share with you a chunk of code written by me, it's main purpose and usage is to mention player's in game globally to know to whom the player is speaking to, the issue i have and concerned about is i cannot proceed further, that is why i have posted here all in relation with pawn scripting section to ask for help from more experienced codders/scripters.



The thing/'s i am concerned about:



Code:
public OnPlayerText(playerid, text[])

{

? ? ? switch(text[1])

? ? ? {

? ? ? ? ? ?case '@': // case the player has inputted symbol '@'

? ? ? ? ? ?{

? ? ? ? ? ? ? ? // sending a client message to the playerid, mainly for its usage.

? ? ? ? ? ? ? ? // `sscanf` proccssed

? ? ? ? ? ? ? ? if(sscanf(text, "us[96]", targetid, message))

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ?SendClientMessage(playerid, -1, "mention player: \'@\' <id> message");

? ? ? ? ? ? ? ? ? ? ?return 0;

? ? ? ? ? ? ? ? }

? ? ? ? ? ?}

? ? ? }

? ? ? return 0;

}


  • 1. Retrieving both playerid and targetid name - Pending

  • 2. coloring - Ready

  • 3. checking each position on input (after the symbol '@' checking id from 0 to 100) - No idea how to check position

  • 4. formating and sending the message - have it




missing some vital functions and organizing/hooking them.



Best Regard's to everyone

?Hastlaking
  Reply
#2
Try this;

Code:
public OnPlayerText(playerid, text[])
{
    if(text[0] == '@')
    {
        new targetid, message[130], message2[130], targetname[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
        strdel(text, 0, 1);
        if(sscanf(text, "us[130]", targetid, message2))
            return SendClientMessage(playerid, -1, "mention player: \'@\' <id> message"), 0;
        if(!IsPlayerConnected(targetid))
            return SendClientMessage(playerid, -1, "This player not connected."), 0;
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        GetPlayerName(targetid, targetname, MAX_PLAYER_NAME);
        format(message, sizeof(message), "%s: @%s - %s", name, targetname, message2);
        SendClientMessageToAll(-1, message);
        return 0;
    }
    return 1;
}
  Reply
#3
Better yet, you can use something like this in sscanf to search for `@` and get the ID at the same time:



Code:
'@'u
  Reply


Forum Jump: