SA-MP Forums Archive
Creating Chat Bubble with command? - 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: Creating Chat Bubble with command? (/showthread.php?tid=256869)



Creating Chat Bubble with command? - Julian12345 - 22.05.2011

Hello guys, does anybody know how to create a chat bubble with a command?

pawn Код:
dcmd_headtext(playerid,params[]) {
    if(PlayerInfo[playerid][Level] >= 1) {
        if(strlen(params) > 128) return 0;
        new to_others[MAX_CHATBUBBLE_LENGTH+1];
        SendClientMessage(playerid, red, "You have set your head text message to %s",params);
        format(to_others,MAX_CHATBUBBLE_LENGTH, "%s",params);
        return SetPlayerChatBubble(playerid,to_others,red,35.0,10000);
    } else return SendClientMessage(playerid,red,"ERROR: Your level is not high enough");
}
I tried it, but the server crashed when using the code above. I know that I probably failed hardly with that.


Re: Creating Chat Bubble with command? - Seven_of_Nine - 22.05.2011

You can't use SendClientMessage to send formatted messages.
Add this to the top of your script:
pawn Код:
#define SendFormattedMessage(%0,%1,%2,%3) \
new text[128]; \
format(text,sizeof(text),%2,%3); \
SendClientMessage(%0,%1,text)
And use like:
pawn Код:
SendFormattedMessage(playerid,red,"You have set your head text message to %s",params);
Untested, if not works then:
pawn Код:
new text[128];
format(text,sizeof(text),"You have set your head text message to %s",params);
SendClientMessage(playerid,red,text);
Good luck with your code.


Re : Creating Chat Bubble with command? - Myk3l - 22.05.2011

pawn Код:
dcmd_headtext(playerid,params[]) {
    if(PlayerInfo[playerid][Level] >= 1) {
        if(strlen(params) > 128) SendClientMessage(playerid,red,"ERROR: Your message contain too many charcters."); return 1;
        new to_others[MAX_CHATBUBBLE_LENGTH+1];
        format(to_others, sizeof(to_other), "You have set your head text message to %s",params);
        SendClientMessage(playerid, red, to_others);
        format(to_others, MAX_CHATBUBBLE_LENGTH, "%s", params);
        SetPlayerChatBubble(playerid,to_others,red,35.0,10000);
        return 1;
    } else SendClientMessage(playerid,red,"ERROR: Your level is not high enough"); return 1;
}
Errors :
- You see if the message contain more than 128 characters, if it's true, you continue to execute the command.
So, i've changed for : "If the message contain more than 128 characters, send error message and stop command.
- SendClientMessage(playerid, color, msg[]); if you want insert "params" into the message, you must format this before.
- It's better if you SendClientMessage and after you return 1;

PS :
return 1; = stop script execution
return 0; = continue script execution

Myk3L.


AW: Creating Chat Bubble with command? - Julian12345 - 22.05.2011

Seven_of_Nine: The first code works perfectly, thank you very much!

Myk3l: I tested your code as well, but it does not work, although I dont get errors

It doesn't show this:

pawn Код:
You have set your head text message to %s
Well, no need to fix it for me since the code of Seven worked, thank you though Myk3l!


Re: Creating Chat Bubble with command? - Seven_of_Nine - 23.05.2011

This is the problem of Myk3l's code:
pawn Код:
//You missed a S there              V
format(to_others, sizeof(to_others), "You have set your head text message to %s",params);