Advertisement
Guest User

ButtonsTest.pwn v1.1

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