Advertisement
ipsCorey

ipsCorey - CoyCard

Oct 11th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.19 KB | None | 0 0
  1. /*
  2. ________________________________________________________________________________
  3.                                                                                    
  4.     # - @Nome:        - CoyCard - Sistema de Carteirinha
  5.     # - @Desenvolvedor:   - [iPs]Corey                                  
  6.     # - @Ínicio:          - 11/10/2013
  7.     # - @Término:         - 11/10/2013
  8.                                                                                
  9.      @Visite: - http://ipsbr.net/
  10. ________________________________________________________________________________
  11.  
  12. */
  13.  
  14. /* Includes */
  15.  
  16. #include "a_samp"
  17. #include "DOF2"
  18. #include "ZCMD"
  19. #include "streamer"
  20.  
  21. /* Defines */
  22.  
  23. #define DialogCard 1542
  24. #define DialogCard2 1543
  25. #define DialogCard3 1544
  26. #define DialogCard4 1545
  27. #define DialogCard5 1546
  28. #define sCards "CoyCard/%s.ini"
  29. #define xErro 0xFF0000FF
  30.  
  31. /* Variáveis */
  32.  
  33. new CP1, CP2, PK1, PK2;
  34. new Meia[ MAX_PLAYERS ] = 1;
  35. new Inteira[ MAX_PLAYERS ] = 2;
  36.  
  37. /* CallBacks */
  38.  
  39. public OnFilterScriptInit()
  40. {
  41.     CP1 = CreateDynamicCP( 361.9933, 173.7507, 1008.3828, 1.0, -1, -1, -1, 100.0 );
  42.     CP2 = CreateDynamicCP( 359.8259, 178.5319, 1008.3828, 1.0, -1, -1, -1, 100.0 );
  43.     PK1 = CreatePickup( 1318, 23, 1154.0476, -1771.9907, 16.5992, -1);
  44.     PK2 = CreatePickup( 1318, 23, 389.8954, 173.6960, 1008.3828, -1);
  45.     Create3DTextLabel("CoyCard - Escritório\n{FFFFFF}/Entrar", 0xFFB90FFF, 1154.0476, -1771.9907, 16.5992, 40.0, 0, 0);
  46.     Create3DTextLabel("CoyCard\n{FFFFFF}/Carteirinha", 0xFFB90FFF, 361.9933, 173.7507, 1008.3828, 40.0, 0, 0);
  47.     Create3DTextLabel("CoyCard\n{FFFFFF}/CardCred", 0xFFB90FFF, 359.8259, 178.5319, 1008.3828, 40.0, 0, 0);
  48.     CreateVehicle(431, 1094.1263,-1761.1437,13.3584,271.8659, 222, 222, 60);
  49.     printf("------------------------------\n");
  50.     printf("CoyCard / v1.0 / [iPs]Corey\n");
  51.     printf("------------------------------");
  52.     return 1;
  53. }
  54. public OnFilterScriptExit()
  55. {
  56.     DOF2_Exit();
  57.     return 1;
  58. }
  59.  
  60. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  61. {
  62.     new xArq[ 50 ];
  63.     format(xArq, sizeof xArq, sCards, PlayerName(playerid));
  64.     if(dialogid == DialogCard)
  65.     {
  66.         if(response)
  67.         {
  68.             if(!DOF2_FileExists(xArq))
  69.             {
  70.                 DOF2_CreateFile(xArq);
  71.                 DOF2_SetInt(xArq, "Carteirinha", 1);
  72.                 DOF2_SetInt(xArq, "Creditos", 0);
  73.                 DOF2_SaveFile();
  74.                 SendClientMessage(playerid, -1,"[ {00FF00}•{FFFFFF} ] Você se cadastrou em nosso sistema com sucesso!");
  75.                 return 1;
  76.             }
  77.             else SendClientMessage(playerid, xErro,"[ x ] Você já é cadastrado em nosso sistema.");
  78.         }
  79.     }
  80.     if(dialogid == DialogCard2)
  81.     {
  82.         if(response)
  83.         {
  84.             if(GetPlayerMoney(playerid) > Meia[ playerid ])
  85.             {
  86.                 GivePlayerMoney(playerid, - Meia[ playerid ]);
  87.                 SendClientMessage(playerid, -1,"[ {00FF00}•{FFFFFF} ] Tarifa paga!");
  88.                 return 1;
  89.             }
  90.             else
  91.             {
  92.                 SendClientMessage(playerid, xErro,"[ x ] Dinheiro insuficiente.");
  93.                 RemovePlayerFromVehicle(playerid);
  94.                 return 1;
  95.             }
  96.         }
  97.         else
  98.         {
  99.             if(GetPlayerMoney(playerid) > Inteira[ playerid ])
  100.             {
  101.                 GivePlayerMoney(playerid, - Inteira[ playerid ]);
  102.                 SendClientMessage(playerid, -1,"[ {00FF00}•{FFFFFF} ] Tarifa paga!");
  103.                 return 1;
  104.             }
  105.             else
  106.             {
  107.                 SendClientMessage(playerid, xErro,"[ x ] Dinheiro insuficiente.");
  108.                 RemovePlayerFromVehicle(playerid);
  109.                 return 1;
  110.             }
  111.         }
  112.     }
  113.     if(dialogid == DialogCard3)
  114.     {
  115.         if(response)
  116.         {
  117.             new credt = strval(inputtext);
  118.             new creditos = DOF2_GetInt(xArq, "Creditos");
  119.             new money = GetPlayerMoney(playerid);
  120.        
  121.             if( strfind(inputtext, "-", true) != -1 || credt <= 0 ) return SendClientMessage(playerid, -1 ,"[ {FF0000}x {FFFFFF}] Valor inválido.");
  122.             if( money < credt) return SendClientMessage(playerid, xErro,"[ x ] Você não tem essa quantia.");
  123.            
  124.             DOF2_SetInt(xArq, "Creditos", credt + creditos);
  125.             GivePlayerMoney(playerid, -credt);
  126.             DOF2_SaveFile();
  127.             new acredit = DOF2_GetInt(xArq, "Creditos");
  128.             new xCoy[ 200 ];
  129.             format(xCoy, sizeof xCoy,"{FFA500}Parabéns!\n\n{FFFFFF}Você adicionou em sua carteirinha R$%d de créditos. Os créditos já estão disponíveis para serem usados.\n\nSeu crédito: R$%d", credt, acredit);
  130.             ShowPlayerDialog(playerid, DialogCard4, DIALOG_STYLE_MSGBOX,"CoyCard - Comprovante", xCoy, #Fechar, #);
  131.             return 1;
  132.         }
  133.         return 1;
  134.     }
  135.     return 1;
  136. }
  137.  
  138. public OnPlayerStateChange(playerid, newstate, oldstate)
  139. {
  140.     new xArq[ 50 ];
  141.     format(xArq, sizeof xArq, sCards, PlayerName(playerid));
  142.     if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_PASSENGER)
  143.     {
  144.         if(IsPlayerInBus(playerid))
  145.         {
  146.             if(DOF2_GetInt(xArq,"Carteirinha") == 1)
  147.             {
  148.                 if(DOF2_GetInt(xArq,"Creditos") == 0)
  149.                 {
  150.                     new creditos = DOF2_GetInt(xArq, "Creditos");
  151.                     new xCoy[ 180 ];
  152.                     format(xCoy, sizeof xCoy, "{FFD700}Escolha abaixo a forma que você deseja para pagar sua passagem.\n\n{FFFFFF}Você não possui créditos em sua carteirinha, portanto, terá que pagar com seu dinheiro.", creditos);
  153.                     ShowPlayerDialog(playerid, DialogCard2, DIALOG_STYLE_MSGBOX, "{FFFFFF}[ ~ ] CoyCard", xCoy, #Meia, #Inteira);
  154.                     return 1;
  155.                 }
  156.                 else if(DOF2_GetInt(xArq,"Creditos") >= Meia[ playerid ])
  157.                 {
  158.                     new creditos = DOF2_GetInt(xArq, "Creditos");
  159.                     new xCoy[ 190 ];
  160.                     DOF2_SetInt(xArq, "Creditos", creditos - Meia[ playerid ]);
  161.                     DOF2_SaveFile();
  162.                     new acredit = DOF2_GetInt(xArq, "Creditos");
  163.                     format(xCoy, sizeof xCoy, "{FFD700}Você possui créditos em sua carteirinha, portanto, não precisa pagar nada.\nSua passagem será descontada nos créditos de sua carteirinha.\n\nMeia: $%d\nNovo saldo: $%d", Meia[ playerid ], acredit);
  164.                     ShowPlayerDialog(playerid, DialogCard5, DIALOG_STYLE_MSGBOX, "{FFFFFF}CoyCard", xCoy, #Fechar, #);
  165.                     return 1;
  166.                 }
  167.             }
  168.         }
  169.     }
  170.     return 1;
  171. }
  172.  
  173. public OnPlayerPickUpPickup(playerid, pickupid)
  174. {
  175.     if(pickupid == PK1) return SendClientMessage(playerid, 0xDCDCDCFF,"[ • ] Para entrar no escritório CoyCard, digite '{FFFFFF}/entrar{DCDCDC}'.");
  176.     else if(pickupid == PK2) return SendClientMessage(playerid, 0xDCDCDCFF, "[ • ] Para sair do escritório CoyCard, digite '{FFFFFF}/sair{DCDCDC}'.");
  177.     return 1;
  178. }
  179. /* Commands */
  180.  
  181. CMD:entrar(playerid)
  182. {
  183.     if(IsPlayerInRangeOfPoint(playerid, 2.0, 1154.0476,-1771.9907,16.5992))
  184.     {
  185.         SetPlayerPos(playerid, 380.0053, 173.6629, 1008.3828 );
  186.         SetPlayerInterior(playerid, 3 );
  187.         return 1;
  188.     }
  189.     else SendClientMessage(playerid, xErro,"[ x ] Você não está na entrada do escritório do terminal.");
  190.     return 1;
  191. }
  192.  
  193. CMD:sair(playerid)
  194. {
  195.     if(IsPlayerInRangeOfPoint(playerid, 2.0, 389.8954, 173.6960, 1008.3828))
  196.     {
  197.         SetPlayerPos(playerid,  1154.0476 ,-1771.9907, 16.5992);
  198.         SetPlayerInterior(playerid, 0);
  199.         return 1;
  200.     }
  201.     else SendClientMessage(playerid, xErro,"[ x ] Você não está na saída do escritório do terminal.");
  202.     return 1;
  203. }
  204.  
  205. CMD:carteirinha(playerid)
  206. {
  207.     if(IsPlayerInDynamicCP(playerid, CP1))
  208.     {
  209.         new xCoy[ 510 ], xCoy1[ 510 ];
  210.         format(xCoy, sizeof xCoy,"{FFFFFF}Ao se cadastrar no sistema de carteirinha, você irá pagar apenas uma Meia passagem.\n\n");
  211.         strcat(xCoy1, xCoy);
  212.         format(xCoy, sizeof xCoy,"{FFFFFF}Ao entrar em um ônibus, se você for cadastrado no sistema, você receberá uma notificação\nperguntando se você quer utilizar a carteirinha para pagar a tarifa, ou não.\n");
  213.         strcat(xCoy1, xCoy);
  214.         format(xCoy, sizeof xCoy,"{FFFFFF}Se você não tiver um cadastro no sistema, você irá pagar a passagem Inteira. ( Tabela de preços abaixo. )\n\n");
  215.         strcat(xCoy1, xCoy);
  216.         format(xCoy, sizeof xCoy,"{FFFFFF}• Tabela de preços:\n 1) - Meia passagem: {32CD32}$%d\n {FFFFFF}2) - Passagem Inteira: {32CD32}$%d\n\n", Meia[ playerid ], Inteira[ playerid ]);
  217.         strcat(xCoy1, xCoy);
  218.         ShowPlayerDialog(playerid, DialogCard, DIALOG_STYLE_MSGBOX, "CoyCard - Cadastro", xCoy1, #Cadastrar, #Cancelar);
  219.         return 1;
  220.     }
  221.     else SendClientMessage(playerid, xErro,"[ x ] Você não esta no escritório CoyCard.");
  222.     return 1;
  223. }
  224.  
  225. CMD:cardcred(playerid)
  226. {
  227.     if(IsPlayerInDynamicCP(playerid, CP2))
  228.     {
  229.         new xArq[ 50 ];
  230.         format(xArq, sizeof xArq, sCards, PlayerName(playerid));
  231.         if(DOF2_FileExists(xArq))
  232.         {
  233.             new xCoy[ 200 ];
  234.             format(xCoy, sizeof xCoy, "{FFFFFF}Digite abaixo a quantia de créditos que você deseja colocar em sua carteirinha.\n\nObs: Os créditos só podem ser usados para pagar sua passagem.");
  235.             ShowPlayerDialog(playerid, DialogCard3, DIALOG_STYLE_INPUT, "{FFFFFF}[ - ]CoyCard", xCoy, #Comprar, #Cancelar);
  236.             return 1;
  237.         }
  238.         else SendClientMessage(playerid, xErro,"[ x ] Você não possui um cadastro em nosso sistema.");
  239.     }
  240.     else SendClientMessage(playerid, xErro, "[ x ] Você não está na área para colocar créditos em sua carteirinha.");
  241.     return 1;
  242. }
  243.  
  244. CMD:ircoycard(playerid)
  245.     return SetPlayerPos(playerid, 1153.6833, -1766.8528, 16.5938);
  246.    
  247. /* Stocks */
  248.  
  249. PlayerName(playerid)
  250. {
  251.     new pname[ MAX_PLAYER_NAME+1 ];
  252.     GetPlayerName(playerid, pname, sizeof pname);
  253.     return pname;
  254. }
  255.  
  256. IsPlayerInBus(playerid)
  257. {
  258.     new Bus[] = {431,437};
  259.     new veiculoid = GetPlayerVehicleID(playerid);
  260.     if(IsPlayerInVehicle(playerid, veiculoid))
  261.     {
  262.         for(new i = 0; i < sizeof(Bus); ++i)
  263.         {
  264.             if(GetVehicleModel(veiculoid) == Bus[i])
  265.             {
  266.                 return true;
  267.             }
  268.         }
  269.     }
  270.     return 0;
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement