Guest User

ButtonsTest.pwn

a guest
Mar 30th, 2012
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.99 KB | None | 0 0
  1. #include <a_samp>
  2. #include <buttons>
  3.  
  4. new PlayerText:Header;
  5. new PlayerText:Body;
  6. new PlayerText:TDText;
  7.  
  8. new Button:btn1;
  9. new Button:btn2;
  10. new Button:btn3;
  11. new Button:moneybutton;
  12. public OnFilterScriptInit()
  13. {
  14.     print("\n--------------------------------------");
  15.     print(" Buttons Test Filterscript by SpiritEvil");
  16.     print("--------------------------------------\n");
  17.  
  18.    
  19.     return 1;
  20. }
  21.  
  22. public OnFilterScriptExit()
  23. {
  24.     for(new playerid = 0; playerid <= MAX_PLAYERS; playerid++)
  25.     {
  26.         for(new i = 0; i <= MAX_TEXT_DRAWS; i++)
  27.         {
  28.             PlayerTextDrawDestroy(playerid, PlayerText:i);
  29.         }
  30.     }
  31.     return 1;
  32. }
  33.  
  34. public OnGameModeExit()
  35. {
  36.     return 1;
  37. }
  38.  
  39. public OnPlayerConnect(playerid)
  40. {
  41.     //--------------------------------------------------------------------------
  42.     //                    TEXTDRAWS FOR THE DIALOG LAYOUT
  43.     //--------------------------------------------------------------------------
  44.     Header = CreatePlayerTextDraw(playerid, 190.000000, 126.000000, "Example Dialog with 3 buttons");
  45.     PlayerTextDrawBackgroundColor(playerid, Header, 255);
  46.     PlayerTextDrawFont(playerid, Header, 1);
  47.     PlayerTextDrawLetterSize(playerid, Header, 0.400000, 1.000000);
  48.     PlayerTextDrawColor(playerid, Header, -1);
  49.     PlayerTextDrawSetOutline(playerid, Header, 1);
  50.     PlayerTextDrawSetProportional(playerid, Header, 1);
  51.     PlayerTextDrawUseBox(playerid, Header, 1);
  52.     PlayerTextDrawBoxColor(playerid, Header, 255);
  53.     PlayerTextDrawTextSize(playerid, Header, 470.000000, 0.000000);
  54.  
  55.     Body = CreatePlayerTextDraw(playerid, 190.000000, 141.000000, "_");
  56.     PlayerTextDrawBackgroundColor(playerid, Body, 255);
  57.     PlayerTextDrawFont(playerid, Body, 1);
  58.     PlayerTextDrawLetterSize(playerid, Body, 0.400000, 11.499990);
  59.     PlayerTextDrawColor(playerid, Body, -1);
  60.     PlayerTextDrawSetOutline(playerid, Body, 1);
  61.     PlayerTextDrawSetProportional(playerid, Body, 1);
  62.     PlayerTextDrawUseBox(playerid, Body, 1);
  63.     PlayerTextDrawBoxColor(playerid, Body, 150);
  64.     PlayerTextDrawTextSize(playerid, Body, 470.000000, 0.000000);
  65.  
  66.     TDText = CreatePlayerTextDraw(playerid, 328.000000, 161.000000, "Do you want to save this text~n~in a file~n~~y~(Will not really be saved)");
  67.     PlayerTextDrawAlignment(playerid, TDText, 2);
  68.     PlayerTextDrawBackgroundColor(playerid, TDText, 255);
  69.     PlayerTextDrawFont(playerid, TDText, 1);
  70.     PlayerTextDrawLetterSize(playerid, TDText, 0.470000, 1.500000);
  71.     PlayerTextDrawColor(playerid, TDText, -1);
  72.     PlayerTextDrawSetOutline(playerid, TDText, 1);
  73.     PlayerTextDrawSetProportional(playerid, TDText, 1);
  74.  
  75.  
  76.     //--------------------------------------------------------------------------
  77.     //                      Creating the buttons
  78.     //--------------------------------------------------------------------------
  79.     btn1 = CreateButtonForPlayer(playerid, "Save", 205, 215, 55, 20);
  80.     ChangeButtonColorsForPlayer(playerid, btn1, 0x000000FF, 0x39C221FF, 0xFFFFFFFF);
  81.  
  82.     btn2 = CreateButtonForPlayer(playerid, "Don'tSave", 278, 215, 100, 20);
  83.     ChangeButtonColorsForPlayer(playerid, btn2, 0x000000FF, 0xFF0000FF, 0xFFFFFFFF);
  84.  
  85.     btn3 = CreateButtonForPlayer(playerid, "Cancel", 395, 215, 65, 20);
  86.     ChangeButtonColorsForPlayer(playerid, btn3, 0x000000FF, 0xFFFF00FF, 0xFFFFFFFF);
  87.     //------------------------------- Money Button -----------------------------
  88.     moneybutton = CreateButtonForPlayer(playerid, "$$Click For Money$$", 210, 150, 200, 40);
  89.     //We are using the default colors here (black for stroke, red for button and white for text)
  90.  
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96.     for(new i = 0; i <= MAX_TEXT_DRAWS; i++)
  97.     {
  98.         PlayerTextDrawDestroy(playerid, PlayerText:i);
  99.     }
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerSpawn(playerid)
  104. {
  105.     SendClientMessage(playerid, -1, "Use /testbuttons or /moneybutton to test the buttons!");
  106.     return 1;
  107. }
  108.  
  109. public OnPlayerDeath(playerid, killerid, reason)
  110. {
  111.     return 1;
  112. }
  113.  
  114. public OnVehicleSpawn(vehicleid)
  115. {
  116.     return 1;
  117. }
  118.  
  119. public OnVehicleDeath(vehicleid, killerid)
  120. {
  121.     return 1;
  122. }
  123.  
  124. public OnPlayerText(playerid, text[])
  125. {
  126.     return 1;
  127. }
  128.  
  129. public OnPlayerCommandText(playerid, cmdtext[])
  130. {
  131.     if (strcmp("/testbuttons", cmdtext, true, 10) == 0)
  132.     {
  133.         PlayerTextDrawShow(playerid, Header);
  134.         PlayerTextDrawShow(playerid, Body);
  135.         PlayerTextDrawShow(playerid, TDText);
  136.         ShowButtonForPlayer(playerid, btn1);
  137.         ShowButtonForPlayer(playerid, btn2);
  138.         ShowButtonForPlayer(playerid, btn3);
  139.         return 1;
  140.     }
  141.    
  142.     if (strcmp("/moneybutton", cmdtext, true, 10) == 0)
  143.     {
  144.         ShowButtonForPlayer(playerid, moneybutton);
  145.         SendClientMessage(playerid, -1, "To change the button's colors type /colors and to change the text type /text");
  146.         SetPVarInt(playerid, "MoneyButton", 1);
  147.         return 1;
  148.     }
  149.    
  150.     if (strcmp("/colors", cmdtext, true, 10) == 0)
  151.     {
  152.         if(GetPVarInt(playerid, "MoneyButton") == 0) return SendClientMessage(playerid, 0xFF000FF, "You must type /moneybutton first!");
  153.         new Colors[] =
  154.         {
  155.             0xFF0000FF,
  156.             0xFFFF00FF,
  157.             0x852479FF,
  158.             0x3AE048FF,
  159.             0xFFB508FF,
  160.             0xDE5DDCFF,
  161.             0x15D8E6FF,
  162.             0x15D8E6FF
  163.         };
  164.         new rand1 = random(sizeof(Colors));
  165.         new rand2 = random(sizeof(Colors));
  166.         new rand3 = random(sizeof(Colors));
  167.         ChangeButtonColorsForPlayer(playerid, moneybutton, Colors[rand1], Colors[rand2], Colors[rand3]);
  168.         UpdateButtonForPlayer(playerid, moneybutton);
  169.         return 1;
  170.     }
  171.    
  172.     if (strcmp("/text", cmdtext, true, 10) == 0)
  173.     {
  174.         if(GetPVarInt(playerid, "MoneyButton") == 0) return SendClientMessage(playerid, 0xFF000FF, "You must type /moneybutton first!");
  175.         new text[][] =
  176.         {
  177.             {"$$Click For Money$$"},
  178.             {"!!!Free Cash FTW!!!"},
  179.             {"$.................$"},
  180.             {"Click me for Free $"}
  181.         };
  182.         new rand1 = random(sizeof(text));
  183.         SetButtonTextForPlayer(playerid, moneybutton, text[rand1]);
  184.         return 1;
  185.     }
  186.     return 0;
  187. }
  188.  
  189. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  190. {
  191.     if(_:clickedid == INVALID_TEXT_DRAW)
  192.     {
  193.         PlayerTextDrawHide(playerid, Header);
  194.         PlayerTextDrawHide(playerid, Body);
  195.         PlayerTextDrawHide(playerid, TDText);
  196.         HideButtonForPlayer(playerid, btn1);
  197.         HideButtonForPlayer(playerid, btn2);
  198.         HideButtonForPlayer(playerid, btn3);
  199.         HideButtonForPlayer(playerid, moneybutton);
  200.     }
  201.     return 1;
  202. }
  203.  
  204. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  205. {
  206.     B_OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid);
  207.     return 1;
  208. }
  209.  
  210. public OnPlayerClickButton(playerid, Button:btnid)
  211. {
  212.     if(btnid == btn1)
  213.     {
  214.         SendClientMessage(playerid, -1, "File will be saved!");
  215.     }
  216.     else if(btnid == btn2)
  217.     {
  218.         SendClientMessage(playerid, -1, "File will NOT be saved!");
  219.     }
  220.     else if(btnid == btn3)
  221.     {
  222.         SendClientMessage(playerid, -1, "Canceling...");
  223.         PlayerTextDrawHide(playerid, Header);
  224.         PlayerTextDrawHide(playerid, Body);
  225.         PlayerTextDrawHide(playerid, TDText);
  226.         HideButtonForPlayer(playerid, btn1);
  227.         HideButtonForPlayer(playerid, btn2);
  228.         HideButtonForPlayer(playerid, btn3);
  229.         CancelSelectTextDraw(playerid);
  230.     }
  231.     else if(btnid == moneybutton)
  232.     {
  233.         GivePlayerMoney(playerid, 1);
  234.         SendClientMessage(playerid, 0x36B32BFF, "+$1");
  235.     }
  236.     return 1;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment