SHARE
TWEET

Message2.inc

Jakwob-WG Jun 20th, 2015 (edited) 31 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if defined _Message2_included
  2.         #endinput
  3. #endif
  4. #define _Message2_included
  5.  
  6. #define MSG_STYLE_ERROR 1
  7. #define MSG_STYLE_INFO  2
  8. #define MSG_STYLE_USAGE 3
  9.  
  10. new PlayerText:MessageTD[MAX_PLAYERS];
  11. new MessageTimer[MAX_PLAYERS];
  12. new bool:TimerActive[MAX_PLAYERS] = false;
  13. new Float:CustomX[MAX_PLAYERS];
  14. new Float:CustomY[MAX_PLAYERS];
  15. new bool:CustomMessage[MAX_PLAYERS] = false;
  16.  
  17. forward SendServerMessage(playerid, msgstyle, const message[]);
  18. public SendServerMessage(playerid, msgstyle, const message[])
  19. {
  20.         if(msgstyle == MSG_STYLE_ERROR)
  21.         {
  22.                 if(TimerActive[playerid] == true)
  23.                 {
  24.                         KillTimer(MessageTimer[playerid]);
  25.                 }
  26.                 new msg[138];
  27.                 format(msg, sizeof msg, "~r~Error: ~w~%s", message);
  28.         PlayerTextDrawSetString(playerid, MessageTD[playerid], msg);
  29.                 PlayerTextDrawShow(playerid, MessageTD[playerid]);
  30.                 MessageTimer[playerid] = SetTimerEx("RemoveMessage", 5000, false, "i", playerid);
  31.                 TimerActive[playerid] = true;
  32.         }
  33.         else if(msgstyle == MSG_STYLE_USAGE)
  34.         {
  35.                 if(TimerActive[playerid] == true)
  36.                 {
  37.                         KillTimer(MessageTimer[playerid]);
  38.                 }
  39.                 new msg[138];
  40.                 format(msg, sizeof msg, "~y~Usage: ~w~%s", message);
  41.         PlayerTextDrawSetString(playerid, MessageTD[playerid], msg);
  42.                 PlayerTextDrawShow(playerid, MessageTD[playerid]);
  43.                 TimerActive[playerid] = true;
  44.                 MessageTimer[playerid] = SetTimerEx("RemoveMessage", 5000, false, "i", playerid);
  45.         }
  46.         else if(msgstyle == MSG_STYLE_INFO)
  47.         {
  48.                 if(TimerActive[playerid] == true)
  49.                 {
  50.                         KillTimer(MessageTimer[playerid]);
  51.                 }
  52.                 new msg[138];
  53.                 format(msg, sizeof msg, "~g~Info: ~w~%s", message);
  54.         PlayerTextDrawSetString(playerid, MessageTD[playerid], msg);
  55.                 PlayerTextDrawShow(playerid, MessageTD[playerid]);
  56.                 TimerActive[playerid] = true;
  57.                 MessageTimer[playerid] = SetTimerEx("RemoveMessage", 5000, false, "i", playerid);
  58.         }
  59.         return 1;
  60. }
  61.  
  62. forward RemoveMessage(playerid);
  63. public RemoveMessage(playerid)
  64. {
  65.     PlayerTextDrawHide(playerid, MessageTD[playerid]);
  66.     printf("Message hidden for playerid %d", playerid);
  67.     TimerActive[playerid] = false;
  68.         return 1;
  69. }
  70.  
  71. CreateMessageTextDraw(playerid)
  72. {
  73.         MessageTD[playerid] = CreatePlayerTextDraw(playerid,139.000000, 370.000000, "Msg: ~w~%s");
  74.         PlayerTextDrawBackgroundColor(playerid,MessageTD[playerid], 255);
  75.         PlayerTextDrawFont(playerid,MessageTD[playerid], 1);
  76.         PlayerTextDrawLetterSize(playerid,MessageTD[playerid], 0.300000, 1.000000);
  77.         PlayerTextDrawColor(playerid,MessageTD[playerid], -16711681);
  78.         PlayerTextDrawSetOutline(playerid,MessageTD[playerid], 0);
  79.         PlayerTextDrawSetProportional(playerid,MessageTD[playerid], 1);
  80.         PlayerTextDrawSetShadow(playerid,MessageTD[playerid], 1);
  81.         PlayerTextDrawSetSelectable(playerid,MessageTD[playerid], 0);  
  82.         printf("** Message Textdraw Created for playerid %d **", playerid);
  83. }
  84.  
  85. CreateCustomMessageTextDraw(playerid)
  86. {
  87.         MessageTD[playerid] = CreatePlayerTextDraw(playerid,CustomX[playerid], CustomY[playerid], "Msg: ~w~%s");
  88.         PlayerTextDrawBackgroundColor(playerid,MessageTD[playerid], 255);
  89.         PlayerTextDrawFont(playerid,MessageTD[playerid], 1);
  90.         PlayerTextDrawLetterSize(playerid,MessageTD[playerid], 0.300000, 1.000000);
  91.         PlayerTextDrawColor(playerid,MessageTD[playerid], -16711681);
  92.         PlayerTextDrawSetOutline(playerid,MessageTD[playerid], 0);
  93.         PlayerTextDrawSetProportional(playerid,MessageTD[playerid], 1);
  94.         PlayerTextDrawSetShadow(playerid,MessageTD[playerid], 1);
  95.         PlayerTextDrawSetSelectable(playerid,MessageTD[playerid], 0);  
  96.         printf("** Message Textdraw Created for playerid %d **", playerid);
  97. }
  98.  
  99. DestroyMessageTextDraw(playerid)
  100. {
  101.         PlayerTextDrawDestroy(playerid, MessageTD[playerid]);
  102. }
  103.  
  104. CMD:msgpos(playerid, params[])
  105. {
  106.         new Float:x[MAX_PLAYERS], Float:y[MAX_PLAYERS], str[128];
  107.         if(sscanf(params, "ff", x[playerid], y[playerid])) return SendServerMessage(playerid, MSG_STYLE_USAGE, "/msgpos [custom x] [custom y]");
  108.         if(y[playerid] > 600.0) return SendServerMessage(playerid, MSG_STYLE_ERROR, "You can not go any higher then 600.00");
  109.         if(y[playerid] < 0.0) return SendServerMessage(playerid, MSG_STYLE_ERROR, "You can not go any lower then 0.00");
  110.         if(y[playerid] > 430.0) return SendServerMessage(playerid, MSG_STYLE_ERROR, "You can not go any higher then 430.00");
  111.         if(y[playerid] < 0.0) return SendServerMessage(playerid, MSG_STYLE_ERROR, "You can not go any lower then 0.00");
  112.         CustomX[playerid] = x[playerid];
  113.         CustomY[playerid] = y[playerid];
  114.         DestroyMessageTextDraw(playerid);
  115.         CreateCustomMessageTextDraw(playerid);
  116.         format(str, sizeof str, "You have changed your message text to %0.2f, %0.2f", CustomX[playerid], CustomY[playerid]);
  117.         SendServerMessage(playerid, MSG_STYLE_INFO, str);
  118.         CustomMessage[playerid] = true;
  119.         return 1;
  120. }
  121.  
  122. CMD:defaultmsg(playerid, params[])
  123. {
  124.         if(CustomMessage[playerid] == false) return SendServerMessage(playerid, MSG_STYLE_ERROR, "You do not have a custom message position");
  125.         DestroyMessageTextDraw(playerid);
  126.         CreateMessageTextDraw(playerid);
  127.         SendServerMessage(playerid, MSG_STYLE_INFO, "You have set your message text to the default position.");
  128.         return 1;
  129. }
RAW Paste Data
Top