toribio

toribio

Dec 17th, 2009
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.51 KB | None | 0 0
  1. /*
  2.  * Skin selection by Flávio Toribio
  3.  * http://www.orkut.com.br/Main#Community.aspx?cmm=38308205
  4. **/
  5.  
  6. #include <a_samp>
  7. #include <dini>
  8.  
  9. // <config>
  10. #define SKIN_FILE           "skins.ini" //arquivo para salvar as skins
  11. #define SKIN_FREE           false       //false = tem que pagar; true = não precisa pagar
  12. #define MALE_SKIN_PRICE     1000000     //preço da skin masculina
  13. #define FEMALE_SKIN_PRICE   2000000     //preço da skin feminina
  14. // </config>
  15.  
  16. #if MALE_SKIN_PRICE < 0
  17.     #undef MALE_SKIN_PRICE
  18.     #define MALE_SKIN_PRICE 0
  19. #endif
  20.  
  21. #if FEMALE_SKIN_PRICE < 0
  22.     #undef FEMALE_SKIN_PRICE
  23.     #define FEMALE_SKIN_PRICE 0
  24. #endif
  25.  
  26. #define ZerarSkinSelection(%1)      \
  27.     inskin[%1] = 0,                 \
  28.     cuskin[%1] = 0,                 \
  29.     ltskin[%1] = 0,                 \
  30.     skindt[%1][p_s_x] = 0.0,        \
  31.     skindt[%1][p_s_y] = 0.0,        \
  32.     skindt[%1][p_s_z] = 0.0,        \
  33.     skindt[%1][p_s_a] = 0.0,        \
  34.     skindt[%1][p_s_interior] = 0,   \
  35.     skindt[%1][p_s_skin] = 0
  36.  
  37. #if SKIN_FREE == false
  38.     forward bool:IsSkinFemale(skinid);
  39. #endif
  40. forward bool:IsInvalidSkin(skinid);
  41.  
  42. new inskin[MAX_PLAYERS];
  43. new cuskin[MAX_PLAYERS];
  44. new ltskin[MAX_PLAYERS];
  45.  
  46. enum p_s_data
  47. {
  48.     Float:p_s_x,
  49.     Float:p_s_y,
  50.     Float:p_s_z,
  51.     Float:p_s_a,
  52.     p_s_interior,
  53.     p_s_world,
  54.     p_s_skin
  55. }
  56.  
  57. new skindt[MAX_PLAYERS][p_s_data];
  58.  
  59. public OnFilterScriptInit()
  60. {
  61.     if(!dini_Exists(SKIN_FILE))
  62.         dini_Create(SKIN_FILE);
  63.     printf("Filterscript de selecao de skins by Flavio Toribio carregado.");
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerCommandText(playerid, cmdtext[])
  68. {
  69.     if(!strcmp(cmdtext, "/skin", true))
  70.     {
  71.         if(!inskin[playerid])
  72.         {
  73.             GetPlayerPos(playerid, skindt[playerid][p_s_x], skindt[playerid][p_s_y], skindt[playerid][p_s_z]);
  74.             GetPlayerFacingAngle(playerid, skindt[playerid][p_s_a]);
  75.             skindt[playerid][p_s_interior] = GetPlayerInterior(playerid);
  76.             skindt[playerid][p_s_world] = GetPlayerVirtualWorld(playerid);
  77.             skindt[playerid][p_s_skin] = GetPlayerSkin(playerid);
  78.             cuskin[playerid] = GetPlayerSkin(playerid);
  79.             SetPlayerInterior(playerid, 14);
  80.             SetPlayerPos(playerid, 258.5, -41.4, 1002.0);
  81.             SetPlayerFacingAngle(playerid, -270.0);
  82.             SetPlayerCameraPos(playerid, 256.1, -43.0, 1004.0);
  83.             SetPlayerCameraLookAt(playerid, 258.5, -41.4, 1002.0);
  84.             TogglePlayerControllable(playerid, 0);
  85.             SetPlayerVirtualWorld(playerid, playerid + 56);
  86.             inskin[playerid] = 1;
  87.             SendClientMessage(playerid, 0xFFF000AA, "Escolha de skin:");
  88.             #if SKIN_FREE == true
  89.                 SendClientMessage(playerid, 0xFFFFFFAA, "Pressione as setas para alternar entre as skins. Use SHIFT (Tecla Pular) para obter a skin");
  90.                 SendClientMessage(playerid, 0xFFFFFFAA, "Ou ENTER (Etrar Veículo) para sair.");
  91.             #else
  92.                 SendClientMessage(playerid, 0xFFFFFFAA, "Pressione as setas para alternar entre as skins. Use SHIFT (Tecla Pular) para comprar a skin");
  93.                 SendClientMessage(playerid, 0xFFFFFFAA, "Ou ENTER (Etrar Veículo) para sair. Skins masculinas: $" #MALE_SKIN_PRICE ", femininas: $" #FEMALE_SKIN_PRICE);
  94.             #endif
  95.             SendClientMessage(playerid, 0xFFFFFFAA, "Caso você queira voltar a nascer com a skin normal, use /skinnormal");
  96.         } else {
  97.             SendClientMessage(playerid, 0xFF0000AA, "Calma, você já está na seleção de skins.");
  98.         }
  99.         return 1;
  100.     }
  101.    
  102.     if(!strcmp(cmdtext, "/skinnormal", true))
  103.     {
  104.         new pname[MAX_PLAYER_NAME];
  105.         GetPlayerName(playerid, pname, sizeof pname);
  106.         if(dini_Isset(SKIN_FILE, pname))
  107.         {
  108.             dini_Unset(SKIN_FILE, pname);
  109.             SendClientMessage(playerid, 0xFFF000AA, "Skin voltada ao normal.");
  110.             SpawnPlayer(playerid);
  111.         } else {
  112.             SendClientMessage(playerid, 0xFF0000AA, "Você já está com a skin normal.");
  113.         }
  114.     }
  115.     return 0;
  116. }
  117.  
  118. public OnPlayerUpdate(playerid)
  119. {
  120.     if(inskin[playerid])
  121.     {
  122.         new keys, updown, leftright, string[128];
  123.  
  124.         GetPlayerKeys(playerid, keys, updown, leftright);
  125.  
  126.         if(leftright == KEY_RIGHT)
  127.         {
  128.             cuskin[playerid] = cuskin[playerid] == 299 ? 0 : cuskin[playerid] + 1;
  129.             while(IsInvalidSkin(cuskin[playerid])) cuskin[playerid]++;
  130.         }
  131.         if(leftright == KEY_LEFT)
  132.         {
  133.             cuskin[playerid] = cuskin[playerid] == 0 ? 299 : cuskin[playerid] - 1;
  134.             while(IsInvalidSkin(cuskin[playerid])) cuskin[playerid]--;
  135.         }
  136.  
  137.         if(ltskin[playerid] != cuskin[playerid]) SetPlayerSkin(playerid, cuskin[playerid]);
  138.         format(string, sizeof string, "~n~~n~~n~~n~~n~~n~~n~~w~Skin: %3d", cuskin[playerid]);
  139.         GameTextForPlayer(playerid, string, 2000, 3);
  140.         ltskin[playerid] = cuskin[playerid];
  141.  
  142.         if(keys == KEY_JUMP)
  143.         {
  144.             #if SKIN_FREE == false
  145.                 if((IsSkinFemale(cuskin[playerid]) && GetPlayerMoney(playerid) < FEMALE_SKIN_PRICE) ||
  146.                     (!IsSkinFemale(cuskin[playerid]) && GetPlayerMoney(playerid) < MALE_SKIN_PRICE))
  147.                 {
  148.                     SendClientMessage(playerid, 0xFF0000AA, "Você não tem dinheiro suficiente! Skin masculino: $" #MALE_SKIN_PRICE ", feminina: $" #FEMALE_SKIN_PRICE);
  149.                     SendClientMessage(playerid, 0xFFF000AA, "Pressione ENTER para sair da escolha de skin.");
  150.                     return 1;
  151.                 }
  152.                 GivePlayerMoney(playerid, ((IsSkinFemale(cuskin[playerid])) ? (-FEMALE_SKIN_PRICE) : (-MALE_SKIN_PRICE)));
  153.             #endif
  154.             TogglePlayerControllable(playerid, 1);
  155.             SetCameraBehindPlayer(playerid);
  156.             SetPlayerInterior(playerid, 0);
  157.             SetPlayerVirtualWorld(playerid, skindt[playerid][p_s_world]);
  158.  
  159.             new pname[MAX_PLAYER_NAME];
  160.             GetPlayerName(playerid, pname, sizeof pname);
  161.             dini_IntSet(SKIN_FILE, pname, cuskin[playerid]);
  162.  
  163.             SpawnPlayer(playerid);
  164.             #if SKIN_FREE == true
  165.                 SendClientMessage(playerid, 0x000FFFAA, "Skin selecionada. Agora você sempre nascerá com ela.");
  166.             #else
  167.                 format(string, sizeof string, "Você comprou sua skin por $%d, agora você sempre nascerá com ela.", IsSkinFemale(cuskin[playerid]) ? FEMALE_SKIN_PRICE : MALE_SKIN_PRICE);
  168.                 SendClientMessage(playerid, 0x000FFFAA, string);
  169.             #endif
  170.             inskin[playerid] = 0;
  171.         }
  172.         else if(keys == KEY_SECONDARY_ATTACK)
  173.         {
  174.             SetPlayerPos(playerid, skindt[playerid][p_s_x], skindt[playerid][p_s_y], skindt[playerid][p_s_z]);
  175.             SetPlayerFacingAngle(playerid, skindt[playerid][p_s_a]);
  176.             SetPlayerInterior(playerid, skindt[playerid][p_s_interior]);
  177.             SetPlayerVirtualWorld(playerid, skindt[playerid][p_s_world]);
  178.             SetPlayerSkin(playerid, skindt[playerid][p_s_skin]);
  179.             TogglePlayerControllable(playerid, 1);
  180.             SetCameraBehindPlayer(playerid);
  181.             ZerarSkinSelection(playerid);
  182.             SendClientMessage(playerid, 0xFFF000AA, "Escolha de skin cancelada.");
  183.         }
  184.     }
  185.     return 1;
  186. }
  187.  
  188. public OnPlayerSpawn(playerid)
  189. {
  190.     new pname[MAX_PLAYER_NAME];
  191.     ZerarSkinSelection(playerid);
  192.     GetPlayerName(playerid, pname, sizeof pname);
  193.     if(dini_Isset(SKIN_FILE, pname))
  194.         SetPlayerSkin(playerid, dini_Int(SKIN_FILE, pname));
  195.     return 1;
  196. }
  197.  
  198. public OnPlayerDisconnect(playerid, reason)
  199. {
  200.     ZerarSkinSelection(playerid);
  201.     return 1;
  202. }
  203.  
  204. public OnPlayerDeath(playerid, killerid, reason)
  205. {
  206.     ZerarSkinSelection(playerid);
  207.     return 1;
  208. }
  209.  
  210. #if SKIN_FREE == false
  211. stock bool:IsSkinFemale(skinid)
  212. {
  213.     static skins[] = {
  214.         9,  10, 11, 12, 13, 31, 39, 40, 41, 54,
  215.         55, 56, 63, 64, 69, 75, 76, 77, 85, 86,
  216.         87, 88, 89, 90, 92, 93, 129, 130,  131,
  217.         138, 140, 141, 145, 148, 150, 151, 152,
  218.         157, 169, 172, 178, 190, 191, 192, 193,
  219.         194, 195, 196, 197, 198, 199, 201, 205,
  220.         207, 211, 214, 215, 216, 218, 219, 224,
  221.         225, 226, 231, 232, 233, 237, 238, 243,
  222.         244, 245, 246, 251, 256, 257, 263, 298
  223.     };
  224.     for(new i = 0; i < sizeof skins; i++)
  225.         if(skinid == skins[i])
  226.             return true;
  227.     return false;
  228. }
  229. #endif
  230.  
  231. stock bool:IsInvalidSkin(skinid)
  232. {
  233.     static skins[] = {
  234.         3, 4, 5, 6, 8, 42,  65, 74,
  235.         86, 119, 149, 208, 273, 289
  236.     };
  237.     for(new i = 0; i < sizeof skins; i++)
  238.         if(skinid == skins[i])
  239.             return true;
  240.     return false;
  241. }
  242.  
Add Comment
Please, Sign In to add comment