Roleplay Chat Module
#1

Features:
Roleplay chats such as /shout /me /do /low /whisper /b and more.
Global OOC through /ooc to talk in Global OOC and /toogleooc to toogle OOC
Megaphone available for all members (you can change it to faction-only)

PHP Code:
#include <a_samp>
#include "../include/gl_common.inc"
#include "../include/gl_messages.inc" // <- contains all the main text/messaging functions
//---------------------------------------------
stock ProcessChatText(playeridtext[])
{
    new 
useindex=1;
    
// Handle shouting prefix (!)
    
if(text[0] == '!' && strlen(text) > 1) {
        if(
text[1] == ' 'useindex++;
         
TalkMessage(SHOUT_DISTANCEplayerid"*shouts*"text[useindex]);
         return;
    }
    
// Handle quiet prefix (#)
    
if(text[0] == '#' && strlen(text) > 1) {
        if(
text[1] == ' 'useindex++;
         
TalkMessage(LOW_DISTANCEplayerid"*quietly*"text[useindex]);
         return;
    }
    
// Send to other players in range and fade
    
TalkMessage(TALK_DISTANCEplayerid""text);
}
//---------------------------------------------
stock ProcessActionText(playeridmessage[], actiontype)
{
    new 
ActionText[256+1];
    new 
ActionBubble[MAX_CHATBUBBLE_LENGTH+1];
    new 
PlayerName[MAX_PLAYER_NAME+1];
    
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
    if(
actiontype == ACTION_DO) {
        
format(ActionText256"* %s ((%s))"messagePlayerName);
        
format(ActionBubbleMAX_CHATBUBBLE_LENGTH"* (( %s ))"message);
    } else {
        
format(ActionText256"* %s %s"PlayerNamemessage);
        
format(ActionBubbleMAX_CHATBUBBLE_LENGTH"* %s"message);
    }
    
    
LocalMessage(ACTION_DISTANCEplayeridACTION_COLORActionText);
       
SetPlayerChatBubble(playeridActionBubbleACTION_COLORACTION_DISTANCECHAT_BUBBLE_TIME);
}
//---------------------------------------------
new gOOCDisabled false;
stock GlobalOOCMessage(playeridmessage[])
{
    new 
msg[256+1];
    new 
PlayerName[MAX_PLAYER_NAME+1];
    if(
gOOCDisabled) {
        
CmdErrorMessage(playerid"The OOC channel is not enabled right now");
        return;
    }
    
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
    
format(msg256"(( %s: %s ))"PlayerNamemessage);
    for(new 
0MAX_PLAYERSi++) { // for every player
        
if(IsPlayerConnected(i)) { // Todo: check if player accepts occ
            
PlayerMessage(iOOC_COLORmsg);
        }
    }
}
//---------------------------------------------
stock ToggleOOC(playerid)
{
    if(
IsPlayerAdmin(playerid)) {
        
// toggle it
        
if(gOOCDisabledgOOCDisabled false;
        else 
gOOCDisabled true;
        
        if(!
gOOCDisabled) {
            
GlobalMessage(GENERAL_COLOR"{D0D0D0}[ooc] channel is {80CC80}enabled");
        } else {
            
GlobalMessage(GENERAL_COLOR"{D0D0D0}[ooc] channel is {CC8080}disabled");
        }
    } else {
        
CmdErrorMessage(playerid"Your admin level isn't high enough to change this");
    }
}
//---------------------------------------------
stock ProcessLocalOOC(playeridmessage[])
{
    new 
new_message[256+1];
    new 
PlayerName[MAX_PLAYER_NAME+1];
    
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
    
format(new_message256"%s (( %s ))"PlayerNamemessage);
    
LocalMessage(TALK_DISTANCEplayeridLOCAL_TALK_COLORnew_message);
}
//---------------------------------------------
stock ProcessMegaphone(playeridmessage[])
{
    
// Todo: add permissions on megaphone usage
       
new new_message[256+1];
    new 
PlayerName[MAX_PLAYER_NAME+1];
    
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
    
format(new_message256"(megaphone) %s >> %s"PlayerNamemessage);
    
LocalMessage(MEGAPHONE_DISTANCEplayeridMEGAPHONE_COLORnew_message1);
}
//---------------------------------------------
stock ProcessWhisper(playeridtoplayeridmessage[])
{
    new 
PlayerName[MAX_PLAYER_NAME+1];
    new 
ToPlayerName[MAX_PLAYER_NAME+1];
    new 
PmMessage[256+1];
    
GetPlayerName(playerid,PlayerName,sizeof(PlayerName));
    
GetPlayerName(toplayerid,ToPlayerName,sizeof(ToPlayerName));
    
format(PmMessagesizeof(PmMessage), ">> %s(%d): %s"ToPlayerNametoplayeridmessage);
    
PlayerMessage(playeridWHISPER_COLORPmMessage);
    
format(PmMessagesizeof(PmMessage), "** %s(%d): %s"PlayerNameplayeridmessage);
    
PlayerMessage(toplayeridWHISPER_COLORPmMessage);
    
PlayerPlaySound(toplayerid10850.00.00.0);
}
//---------------------------------------------
stock ProcessChatCommands(playeridcmdtext[])
{
    new 
cmd[256+1];
    new 
message[256+1];
    new    
tmp[256+1];
    new    
idx;
    
cmd strtok(cmdtextidx);
    
// Action commands
    
if(!strcmp("/me"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"/me [action]");
            return 
1;
        }
        
ProcessActionText(playeridmessageACTION_ME);
        return 
1;
    }
    if(!
strcmp("/do"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"/do [action]");
            return 
1;
        }
        
ProcessActionText(playeridmessageACTION_DO);
        return 
1;
    }
    
// Talk commands
    // /low
    
if(!strcmp("/l"cmdtrue) || !strcmp("/low"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"(/l)ow [text]");
            return 
1;
        }
        
TalkMessage(LOW_DISTANCEplayerid"*quietly*"message);
        return 
1;
    }
    
// /shout
    
if(!strcmp("/s"cmdtrue) || !strcmp("/shout"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"(/s)hout [text]");
            return 
1;
        }
        
TalkMessage(SHOUT_DISTANCEplayerid"*shouts*"message);
        return 
1;
    }
    
// /b (local ooc)
    
if(!strcmp("/b"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"/b [text]");
            return 
1;
        }
        
ProcessLocalOOC(playeridmessage);
        return 
1;
    }
    
// /megaphone
    
if(!strcmp("/m"cmdtrue) || !strcmp("/megaphone"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"(/m)egaphone [text]");
            return 
1;
        }
        
ProcessMegaphone(playeridmessage);
        return 
1;
    }
    
// Global OOC /o and /ooc
    
if(!strcmp("/o"cmdtrue) || !strcmp("/ooc"cmdtrue))
    {
          
message strrest(cmdtext,idx);
          if(!
strlen(message)) {
            
CmdUsageMessage(playerid"(/o)oc [text]");
            return 
1;
        }
        
GlobalOOCMessage(playeridmessage);
        return 
1;
    }
    
// Toggle the OOC channel /togooc
    
if(!strcmp("/togooc"cmdtrue))
    {
             
ToggleOOC(playerid);
        return 
1;
    }
     
// /whisper /pm
    
if(!strcmp("/w"cmdtrue) || !strcmp("/whisper"cmdtrue) || !strcmp("/pm"cmdtrue))
    {
        
tmp strtok(cmdtext,idx);
        if(!
strlen(tmp)) {
            
CmdUsageMessage(playerid"(/w)hisper [playerid/PartOfName] [whisper text]");
            return 
1;
        }
        
        new 
toplayerid ReturnUser(tmp);
        if(
toplayerid == RETURN_USER_MULTIPLE) {
            
CmdErrorMessage(playerid"Multiple matches found for [name]. Please narrow the search.");
            return 
1;
        }
        if(
toplayerid == RETURN_USER_FAILURE || !IsPlayerConnected(toplayerid)) {
            
CmdErrorMessage(playerid"That player isn't connected right now.");
            return 
1;
        }
        
        
message strrest(cmdtext,idx);
                 
        if(!
strlen(message)) {
            
CmdUsageMessage(playerid"(/w)isper [playerid/PartOfName] [whisper text]");
            return 
1;
        }
        if(
IsPlayerConnected(toplayerid)) {
             
ProcessWhisper(playeridtoplayeridmessage);
        }
        
        return 
1;
    }
    return 
0;
}
//---------------------------------------------
public OnPlayerText(playeridtext[])
{
    
ProcessChatText(playeridtext);
    return 
0;
}
//------------------------------------------------
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
ProcessChatCommands(playerid,cmdtext)) {
        return 
1;
    }
    return 
0;
}
//--------------------------------------------- 
Lazy? Don't want to copy all the stuff?
RPChats.rar
Reply
#2

Worng Section Post Here http://forum.sa-mp.com/forumdisplay.php?f=17
Reply
#3

They are more of a snipped, https://sampforum.blast.hk/showthread.php?tid=281.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)