Creating Chat Bubble with command?
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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!
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)