Advertisement
Guest User

SA-MP Chatbox

a guest
Jun 14th, 2013
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.93 KB | None | 0 0
  1. /*
  2.     SA-MP Chatbox
  3.     von pwnfl4sh
  4.     v3
  5. */
  6. #include <a_samp>
  7.  
  8. #undef MAX_PLAYERS
  9. #define MAX_PLAYERS 25
  10.  
  11. #define SHOW_INFO
  12. #define ALLOW_COLORS
  13. #define CHAT_WIDTH 170.0
  14.  
  15. #define DIALOG_FARBE 1337
  16.  
  17. new Text:ChatBox;
  18. new Text:ChatLine[10];
  19. new Text:ChatInfo;
  20. new ChatStr[10][128];
  21.  
  22. public OnFilterScriptInit()
  23. {
  24.     ChatBox = TextDrawCreate(30.000000, 190.000000, "__");
  25.     TextDrawBackgroundColor(ChatBox, 255);
  26.     TextDrawFont(ChatBox, 1);
  27.     TextDrawLetterSize(ChatBox, 0.000000, 14.000000);
  28.     TextDrawColor(ChatBox, -1);
  29.     TextDrawSetOutline(ChatBox, 0);
  30.     TextDrawSetProportional(ChatBox, 1);
  31.     TextDrawSetShadow(ChatBox, 1);
  32.     TextDrawUseBox(ChatBox, 1);
  33.     TextDrawBoxColor(ChatBox, 370546326);
  34.     TextDrawTextSize(ChatBox, 30.000000+CHAT_WIDTH, -10.000000);
  35.     TextDrawSetSelectable(ChatBox, 0);
  36.    
  37.     for(new i=0;i<10;i++)
  38.     {
  39.         ChatLine[i] = TextDrawCreate(31.000000, 191.000000+(i*10), "_");
  40.         TextDrawBackgroundColor(ChatLine[i], 255);
  41.         TextDrawFont(ChatLine[i], 1);
  42.         TextDrawLetterSize(ChatLine[i], 0.219999, 0.899999);
  43.         TextDrawColor(ChatLine[i], -1);
  44.         TextDrawSetOutline(ChatLine[i], 0);
  45.         TextDrawSetProportional(ChatLine[i], 1);
  46.         TextDrawSetShadow(ChatLine[i], 1);
  47.         TextDrawSetSelectable(ChatLine[i], 0);
  48.        
  49.         format(ChatStr[i],128,"_");
  50.     }
  51.    
  52.     ChatInfo = TextDrawCreate(32.000000, 302.000000, "~r~T~w~ zum Chatten...");
  53.     TextDrawBackgroundColor(ChatInfo, 255);
  54.     TextDrawFont(ChatInfo, 1);
  55.     TextDrawLetterSize(ChatInfo, 0.500000, 1.000000);
  56.     TextDrawColor(ChatInfo, -1);
  57.     TextDrawSetOutline(ChatInfo, 0);
  58.     TextDrawSetProportional(ChatInfo, 1);
  59.     TextDrawSetShadow(ChatInfo, 1);
  60.     TextDrawSetSelectable(ChatInfo, 0);
  61.     return 1;
  62. }
  63.  
  64. public OnFilterScriptExit()
  65. {
  66.     return 1;
  67. }
  68.  
  69. public OnPlayerConnect(playerid)
  70. {
  71.     SetPVarInt(playerid,"Chat",0);
  72.     SetPVarInt(playerid,"Farbe",0);
  73.     SendClientMessage(playerid,-1,"Um die Chatbox anzuzeigen, tippe /chatbox.");
  74.    
  75.     #if defined ALLOW_COLORS
  76.         SendClientMessage(playerid,-1,"Deine Chatfarbe kannst du mit /farbe ändern.");
  77.     #endif
  78.     return 1;
  79. }
  80.  
  81. public OnPlayerText(playerid, text[])
  82. {
  83.     new tstr[128], name[MAX_PLAYER_NAME];
  84.     GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  85.    
  86.     new maxlen = floatround(((CHAT_WIDTH * 0.24)-strlen(name))-1,floatround_ceil);
  87.     switch(GetPVarInt(playerid,"Farbe"))
  88.     {
  89.         case 0:
  90.         {
  91.             format(tstr,128,"%s~w~: %s",name,text);
  92.         }
  93.         case 1:
  94.         {
  95.             format(tstr,128,"~r~~h~~h~%s~w~: %s",name,text);
  96.         }
  97.         case 2:
  98.         {
  99.             format(tstr,128,"~y~%s~w~: %s",name,text);
  100.         }
  101.         case 3:
  102.         {
  103.             format(tstr,128,"~b~~h~%s~w~: %s",name,text);
  104.         }
  105.         case 4:
  106.         {
  107.             format(tstr,128,"~g~~h~~h~%s~w~: %s",name,text);
  108.         }
  109.     }
  110.        
  111.     if(strlen(text) > maxlen)
  112.     {
  113.         format(tstr,128,"Maximale Textlänge überschritten(>>%d/%d<<)",strlen(text),maxlen);
  114.         SendClientMessage(playerid,-1,tstr);
  115.     }
  116.     else
  117.     {
  118.         new line = FreeChatLine();
  119.         format(ChatStr[line],128,tstr);
  120.  
  121.         for(new i=0;i<10;i++)
  122.         {
  123.             TextDrawSetString(ChatLine[i],ChatStr[i]);
  124.         }
  125.  
  126.         for(new i=0;i<MAX_PLAYERS;i++)
  127.         {
  128.             if(IsPlayerConnected(i))
  129.             {
  130.                 if(GetPVarInt(i,"Chat") == 1)
  131.                 {
  132.                     HideChatBox(i);
  133.                     ShowChatBox(i);
  134.                 }
  135.             }
  136.         }
  137.     }
  138.     return 0;
  139. }
  140.  
  141. public OnPlayerCommandText(playerid, cmdtext[])
  142. {
  143.     if(!strcmp(cmdtext,"/chatbox",true))
  144.     {
  145.         if(GetPVarInt(playerid,"Chat") == 0)
  146.         {
  147.             ShowChatBox(playerid);
  148.         }
  149.         else if(GetPVarInt(playerid,"Chat") == 1)
  150.         {
  151.             HideChatBox(playerid);
  152.         }
  153.         return 1;
  154.     }
  155.  
  156.     #if defined ALLOW_COLORS
  157.         if(!strcmp(cmdtext,"/farbe",true))
  158.         {
  159.             ShowPlayerDialog(playerid,DIALOG_FARBE,DIALOG_STYLE_LIST,"{FFFFFF}Chatfarbe auswählen","{FFFFFF}Weiß\n{FF4450}Rot\n{FFD100}Gelb\n{00A1FF}Blau\n{00FF73}Grün","Wählen","Abbr.");
  160.             return 1;
  161.         }
  162.     #endif
  163.     return 0;
  164. }
  165.  
  166. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  167. {
  168.     if(response)
  169.     {
  170.         if(dialogid == DIALOG_FARBE)
  171.         {
  172.             switch(listitem)
  173.             {
  174.                 case 0:
  175.                 {
  176.                     SetPVarInt(playerid,"Farbe",0);
  177.                     SendClientMessage(playerid,-1,"Deine Chatfarbe ist jetzt Weiß.");
  178.                 }
  179.                 case 1:
  180.                 {
  181.                     SetPVarInt(playerid,"Farbe",1);
  182.                     SendClientMessage(playerid,0xFF4500FF,"Deine Chatfarbe ist jetzt Rot.");
  183.                 }
  184.                 case 2:
  185.                 {
  186.                     SetPVarInt(playerid,"Farbe",2);
  187.                     SendClientMessage(playerid,0xECE65BFF,"Deine Chatfarbe ist jetzt Gelb.");
  188.                 }
  189.                 case 3:
  190.                 {
  191.                     SetPVarInt(playerid,"Farbe",3);
  192.                     SendClientMessage(playerid,0x33CCFFAA,"Deine Chatfarbe ist jetzt Blau.");
  193.                 }
  194.                 case 4:
  195.                 {
  196.                     SetPVarInt(playerid,"Farbe",4);
  197.                     SendClientMessage(playerid,0x10F441AA,"Deine Chatfarbe ist jetzt Grün.");
  198.                 }
  199.             }
  200.         }
  201.     }
  202.     return 1;
  203. }
  204.  
  205. stock ShowChatBox(playerid)
  206. {
  207.     SetPVarInt(playerid,"Chat",1);
  208.     TextDrawShowForPlayer(playerid,ChatBox);
  209.    
  210.     for(new i=0;i<10;i++)
  211.     {
  212.         TextDrawShowForPlayer(playerid,ChatLine[i]);
  213.     }
  214.    
  215.     #if defined SHOW_INFO
  216.         TextDrawShowForPlayer(playerid,ChatInfo);
  217.     #endif
  218.     return 1;
  219. }
  220.  
  221. stock HideChatBox(playerid)
  222. {
  223.     SetPVarInt(playerid,"Chat",0);
  224.     TextDrawHideForPlayer(playerid,ChatBox);
  225.  
  226.     for(new i=0;i<10;i++)
  227.     {
  228.         TextDrawHideForPlayer(playerid,ChatLine[i]);
  229.     }
  230.    
  231.     #if defined SHOW_INFO
  232.         TextDrawHideForPlayer(playerid,ChatInfo);
  233.     #endif
  234.     return 1;
  235. }
  236.  
  237. stock FreeChatLine()
  238. {
  239.     new line = -1;
  240.     for(new i=0;i<10;i++)
  241.     {
  242.         if(!strcmp(ChatStr[i],"_",false))
  243.         {
  244.             line = i;
  245.             break;
  246.         }
  247.     }
  248.    
  249.     if(line == -1)
  250.     {
  251.         for(new i=0;i<9;i++)
  252.         {
  253.             format(ChatStr[i],128,ChatStr[i+1]);
  254.         }
  255.        
  256.         line = 9;
  257.         format(ChatStr[9],128,"_");
  258.     }
  259.     return line;
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement