Advertisement
kmatsu

Caixas Eletronicos - By: Kmatsu

Jan 1st, 2012
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.99 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <a_mysql>
  4. #include <zcmd>
  5. #include <sscanf2>
  6.  
  7.  
  8. //------------------------------------------------------------------------------
  9. //  IMPORTANTE - IMPORTANTE - IMPORTANTE - IMPORTANTE - IMPORTANTE - IMPORTANTE
  10. //------------------------------------------------------------------------------
  11. //SE NAO USAR ANTI-MONEY-HACK OU ALGUM DINHEIRO SECUNDARIO APAGUE A LINHA ABAIXO
  12. #define GivePlayerMoney(%0,%1)  CallRemoteFunction("DarDinheiro","dd",%0,%1)
  13. //------------------------------------------------------------------------------
  14.  
  15. #define MAX_CAIXAS (100)
  16. #define PAG_PADRAO 30000
  17. #define PAG_RANDOM 50000
  18. #define TEMPO_PADRAO 60000 //Tempo para assaltar + random(Tempo_Random)
  19. #define TEMPO_RANDOM 60000 //Tempo para assaltar + random(Tempo_Random)
  20. #define TEMPO_LIBERAR_CAIXA 60000
  21. #define VALOR_CABECA 50000
  22. #define VALOR_CABECA_RANDOM 50000
  23.  
  24. #define AZULZINHO 0x10CCF3AA
  25. #define COR_ASSALTO 0xFF5B60AA
  26. #define COR_MARCADOS 0x14CC00AA
  27.  
  28. #define SQL_HOST                                                                "HOST"
  29. #define SQL_USER                                                                "USUARIO"
  30. #define SQL_PASS                                                                "SENHA"
  31. #define SQL_DB                                                                  "DATABASE"
  32. #define mysql_fetch_row(%1)                                                     mysql_fetch_row_format(%1,"|")
  33. #define MAXIMO_TENTATIVAS 10
  34.  
  35. new mQuery[200],
  36.     string[128];
  37.  
  38. enum CaixaInfoEnum
  39. {
  40.     Criado,
  41.     Float:CPX, //Pos X
  42.     Float:CPY, //Pos Y
  43.     Float:CPZ, //Pos Z
  44.     Float:CRX, //Rotacao X
  45.     Float:CRY, //Rotacao Y
  46.     Float:CRZ, //Rotacao Z
  47.     Nome[128], //Nome do Caixa
  48.     Roubado,
  49.     Objeto
  50. }
  51. new CaixaInfo[MAX_CAIXAS][CaixaInfoEnum],
  52.     ValorCabeca[MAX_PLAYERS];
  53.  
  54.  
  55. public OnFilterScriptInit()
  56. {
  57.     for(new x = 0; x <= MAXIMO_TENTATIVAS; x++)
  58.     {
  59.         mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  60.         if(mysql_ping() >= 1)
  61.         {
  62.             printf("MYSQL: Conectado com sucesso ao banco de dados %s\n",SQL_DB);
  63.             print("|--------------------------------|");
  64.             print("|Sistema de caixa eletronico v1.0|");
  65.             print("|      Produzido por Kmatsu      |");
  66.             print("|--------------------------------|");
  67.             break;
  68.         }
  69.         else
  70.         {
  71.             printf("MySQL: Falha de conexao tentativa %d de %d", x, MAXIMO_TENTATIVAS);
  72.             if(x == MAXIMO_TENTATIVAS)
  73.             {
  74.                 print("Falha ao conectar à base de dados MySql");
  75.                 print("Talvez o filterscript nao irá funcionar");
  76.                 SendRconCommand("unloadfs Caixas");
  77.                 return true;
  78.             }
  79.         }
  80.     }
  81.     mysql_debug(1);
  82.  
  83.     mysql_query("CREATE TABLE IF NOT EXISTS Caixas(\
  84.    ID INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,\
  85.    Nome VARCHAR(128) NOT NULL,\
  86.    PosX Float(20) NOT NULL,\
  87.    PosY Float(20) NOT NULL,\
  88.    PosZ Float(20) NOT NULL,\
  89.    RotX Float(20) NOT NULL,\
  90.    RotY Float(20) NOT NULL,\
  91.    RotZ Float(20) NOT NULL)");
  92.  
  93.     mysql_query("CREATE TABLE IF NOT EXISTS Marcados(\
  94.    Nome VARCHAR(20) NOT NULL,\
  95.    Valor INT(20) NOT NULL)");
  96.  
  97.     CarregarCaixas();
  98.     return true;
  99. }
  100.  
  101.  
  102.  
  103. //----------------COMANDOS
  104.  
  105. cmd(criarcaixa, playerid, params[])
  106. {
  107.     new Float:cX, Float:cY, Float:cZ, NomeCaixa[50];
  108.     if(sscanf(params, "s[50]", NomeCaixa)) return MSG(playerid, 0x1E90FF99, "Uso correto: /criarcaixa [Nome do caixa]");
  109.     GetPlayerPos(playerid, cX, cY, cZ);
  110.     if(!CriarCaixa(NomeCaixa, cX, cY, cZ-0.2, 0.0, 0.0, 0.0)) return MSG(playerid, -1, "Erro ao criar o caixa eletronico, talvez o limite de caixas foi atingido");
  111.     return true;
  112. }
  113.  
  114. cmd(destruircaixa, playerid, params[])
  115. {
  116.     #pragma unused params
  117.     if(GetPlayerCaixa(playerid) > MAX_CAIXAS+1) return MSG(playerid, -1, "Você nao está perto de nenhum caixa eletronico");
  118.  
  119.     DestroyObject(CaixaInfo[GetPlayerCaixa(playerid)][Objeto]);
  120.     format(mQuery, sizeof(mQuery), "DELETE FROM Caixas WHERE Nome='%s', PosX=%f, PosY=%f, PosZ=%f, RotX=%f, RotY=%f, RotZ=%f",
  121.     CaixaInfo[GetPlayerCaixa(playerid)][Nome], CaixaInfo[GetPlayerCaixa(playerid)][CPX], CaixaInfo[GetPlayerCaixa(playerid)][CPY], CaixaInfo[GetPlayerCaixa(playerid)][CPZ], CaixaInfo[GetPlayerCaixa(playerid)][CRX], CaixaInfo[GetPlayerCaixa(playerid)][CRY], CaixaInfo[GetPlayerCaixa(playerid)][CRZ]);
  122.     return true;
  123. }
  124.  
  125. cmd(assaltarcaixa, playerid, params[])
  126. {
  127.     #pragma unused params
  128.     if(GetPlayerCaixa(playerid) > MAX_CAIXAS+1) return MSG(playerid, -1, "Você nao está perto de nenhum caixa eletronico");
  129.     AssaltarCaixa(playerid, GetPlayerCaixa(playerid));
  130.     return true;
  131. }
  132.  
  133. cmd(marcados, playerid, params[])
  134. {
  135.     #pragma unused params
  136.     new Cont;
  137.     MSG(playerid, COR_MARCADOS, "Jogadores com a vida marcada:");
  138.     for(new i, j = GetMaxPlayers(); i < j; i++)
  139.     {
  140.         if(ValorCabeca[i] == 0) continue;
  141.         MSG(playerid, COR_MARCADOS, "%s [%d] - Valor: R$ %d", pNome(i), i, ValorCabeca[i]);
  142.         Cont++;
  143.     }
  144.     if(Cont == 0) MSG(playerid, COR_MARCADOS, "Ninguem está marcadado :(");
  145.     return true;
  146. }
  147.  
  148. cmd(meucaixa, playerid, params[])
  149. {
  150.     #pragma unused params
  151.     new caixa = GetPlayerCaixa(playerid);
  152.     if(caixa == MAX_CAIXAS+1) MSG(playerid, -1, "Você nao está em nenhum caixa");
  153.     else MSG(playerid, -1, "Você está no caixa %s", CaixaInfo[GetPlayerCaixa(playerid)][Nome]);
  154.     return true;
  155. }
  156.  
  157. //-----------------PUBLICS
  158.  
  159. public OnPlayerConnect(playerid)
  160. {
  161.     CarregarMarcado(playerid);
  162.     //SendClientMessage(playerid, -1, "OnPlayerConnect - KAC");
  163. }
  164.  
  165. public OnPlayerDeath(playerid, killerid, reason)
  166. {
  167.     printf("OnPlayerDeath - caixas");
  168.     if(killerid != INVALID_PLAYER_ID)
  169.     {
  170.         if(ValorCabeca[playerid] > 0)
  171.         {
  172.             GivePlayerMoney(killerid, ValorCabeca[playerid]);
  173.             format(string, sizeof(string), "O Player %s matou o procurado %s e ganhou R$ %d", pNome(playerid), pNome(killerid), ValorCabeca[playerid]);
  174.             SendClientMessageToAll(AZULZINHO, string);
  175.             ValorCabeca[playerid] = 0;
  176.             format(mQuery, sizeof(mQuery), "DELETE FROM Marcados WHERE Nome='%s'", pNome(playerid));
  177.             mysql_query(mQuery);
  178.         }
  179.     }
  180. }
  181.  
  182. //----------------STOCKS
  183.  
  184. stock CarregarCaixas()
  185. {
  186.     new idx, a;
  187.     printf("\n");
  188.     printf("===============[CARREGANDO CAIXAS]=============");
  189.     format(mQuery, sizeof(mQuery), "SELECT * FROM Caixas");
  190.     mysql_query(mQuery);
  191.     mysql_store_result();
  192.  
  193.     while(mysql_fetch_row_format(mQuery,"|"))
  194.     {
  195.         idx++;
  196.         sscanf(mQuery, "p<|>ds[128]ffffff", a, CaixaInfo[idx][Nome], CaixaInfo[idx][CPX], CaixaInfo[idx][CPY], CaixaInfo[idx][CPZ], CaixaInfo[idx][CRX], CaixaInfo[idx][CRY], CaixaInfo[idx][CRZ]);
  197.  
  198.         CaixaInfo[idx][Objeto] = CreateObject(2942, CaixaInfo[idx][CPX], CaixaInfo[idx][CPY], CaixaInfo[idx][CPZ], CaixaInfo[idx][CRX], CaixaInfo[idx][CRY], CaixaInfo[idx][CRZ], 150.0);
  199.         CaixaInfo[idx][Criado] = 1;
  200.  
  201.         printf("|-----------------[CAIXA %03d]----------------|", idx);
  202.         if(strlen(CaixaInfo[idx][Nome]) <= 36) printf("| Nome: %36s |", CaixaInfo[idx][Nome]);
  203.         if(strlen(CaixaInfo[idx][Nome]) >= 37) printf("| Nome: %34s...|", CaixaInfo[idx][Nome]);
  204.         printf("| PosX: %04.2f  PosY: %04.2f  PosZ: %04.2f|", CaixaInfo[idx][CPX], CaixaInfo[idx][CPY], CaixaInfo[idx][CPZ]);
  205.         printf("| RotX: %04.2f  RotY: %04.2f  RotZ: %04.2f|", CaixaInfo[idx][CRX], CaixaInfo[idx][CRY], CaixaInfo[idx][CRZ]);
  206.         printf("|--------------------------------------------|");
  207.         printf("\n");
  208.     }
  209.     printf("Todos os Caixas Eletronicos foram carregados com sucesso!");
  210.     return true;
  211. }
  212.  
  213. stock CriarCaixa(nome[], Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ)
  214. {
  215.     for(new i = 0; i <= MAX_CAIXAS; i++)
  216.     {
  217.         if(CaixaInfo[i][Criado] == 0)
  218.         {
  219.             CaixaInfo[i][Criado] = 1;
  220.             CaixaInfo[i][CPX] = X;
  221.             CaixaInfo[i][CPY] = Y;
  222.             CaixaInfo[i][CPZ] = Z;
  223.             CaixaInfo[i][CRX] = RX;
  224.             CaixaInfo[i][CRY] = RY;
  225.             CaixaInfo[i][CRZ] = RZ;
  226.             format(CaixaInfo[i][Nome], 128, "%s", nome);
  227.             CaixaInfo[i][Roubado] = 0;
  228.             CaixaInfo[i][Objeto] = CreateObject(2942, X, Y, Z, RX, RY, RZ, 150.0);
  229.  
  230.             format(mQuery, sizeof(mQuery), "INSERT INTO Caixas (Nome, PosX, PosY, PosZ, RotX, RotY, RotZ) VALUES ('%s', %f, %f, %f, %f, %f, %f)",  CaixaInfo[i][Nome], CaixaInfo[i][CPX], CaixaInfo[i][CPY], CaixaInfo[i][CPZ], CaixaInfo[i][CRX], CaixaInfo[i][CRY], CaixaInfo[i][CRZ]);
  231.             mysql_query(mQuery);
  232.             return true;
  233.         }
  234.     }
  235.     return false;
  236. }
  237.  
  238. stock MarcarPlayer(playerid, valor)
  239. {
  240.     ValorCabeca[playerid] = ValorCabeca[playerid]+valor;
  241.     format(mQuery, sizeof(mQuery), "SELECT * FROM Marcados WHERE Nome='%s'", pNome(playerid));
  242.     mysql_query(mQuery);
  243.     mysql_store_result();
  244.     if(mysql_num_rows() > 0)
  245.     {
  246.         format(mQuery, sizeof(mQuery), "UPDATE Marcados SET Valor=%d WHERE Nome='%s'", ValorCabeca[playerid], pNome(playerid));
  247.         mysql_query(mQuery);
  248.     }
  249.     else
  250.     {
  251.         format(mQuery, sizeof(mQuery), "INSERT INTO Marcados (Nome, Valor) VALUES ('%s', %d)", pNome(playerid), ValorCabeca[playerid]);
  252.         mysql_query(mQuery);
  253.     }
  254. }
  255.  
  256. stock CarregarMarcado(playerid)
  257. {
  258.     ValorCabeca[playerid] = 0;
  259.     format(mQuery, sizeof(mQuery), "SELECT * FROM Marcados WHERE Nome='%s'", pNome(playerid));
  260.     mysql_query(mQuery);
  261.     mysql_store_result();
  262.     new Nomea[20];
  263.     if(mysql_num_rows() > 0)
  264.     {
  265.         while(mysql_fetch_row_format(mQuery,"|"))
  266.         {
  267.             sscanf(mQuery, "p<|>s[20]d", Nomea, ValorCabeca[playerid]);
  268.         }
  269.     }
  270. }
  271.  
  272. stock AssaltarCaixa(playerid, caixa)
  273. {
  274.     if(CaixaInfo[caixa][Roubado] == 1) return MSG(playerid, -1, "Esse caixa eletronico ja foi ou está sendo assaltado");
  275.     CaixaInfo[caixa][Roubado] = 1;
  276.     MSG(playerid, AZULZINHO, "Você está assaltando o caixa \"%s\", Aguarde alguns minutos para levar a grana", CaixaInfo[caixa][Nome]);
  277.     format(string, sizeof(string), "O Player %s está assaltando o caixa eletronico %s", pNome(playerid), CaixaInfo[caixa][Nome]);
  278.     SendClientMessageToAll(COR_ASSALTO, string);
  279.  
  280.     new rand = random(VALOR_CABECA_RANDOM)+VALOR_CABECA;
  281.     MarcarPlayer(playerid, rand);
  282.     format(string, sizeof(string), "A Prefeitura está dando um premio de R$ %d pela vida de %s", rand, pNome(playerid));
  283.     SendClientMessageToAll(AZULZINHO, string);
  284.     SetTimerEx("PegarGrana", TEMPO_PADRAO+random(TEMPO_RANDOM), false, "dd", playerid, caixa);
  285.     return true;
  286. }
  287.  
  288. forward PegarGrana(playerid, caixa);
  289. public PegarGrana(playerid, caixa)
  290. {
  291.     if(!IsPlayerInCaixa(playerid, caixa)) return MSG(playerid, -1, "Você nao está perto de nenhum caixa eletronico, por isso nao levou a grana");
  292.     new rand = random(PAG_RANDOM)+PAG_PADRAO;
  293.     GivePlayerMoney(playerid, PAG_PADRAO);
  294.     MSG(playerid, AZULZINHO, "Você assaltou o caixa eletronico e levou R$ %d", rand+PAG_PADRAO);
  295.     format(string, sizeof(string), "O Player assaltou o caixa eletronico %s", CaixaInfo[caixa][Nome]);
  296.     SendClientMessageToAll(COR_ASSALTO, string);
  297.     SetTimerEx("LiberarCaixa", TEMPO_LIBERAR_CAIXA, false, "d", caixa);
  298.     return true;
  299. }
  300.  
  301. forward LiberarCaixa(caixa);
  302. public LiberarCaixa(caixa)
  303. {
  304.     CaixaInfo[caixa][Roubado] = 0;
  305. }
  306.  
  307.  
  308. stock GetPlayerCaixa(playerid)
  309. {
  310.     for(new c = 0; c <= MAX_CAIXAS; c++)
  311.     {
  312.         if(CaixaInfo[c][Criado] == 0) continue;
  313.         if(IsPlayerInRangeOfPoint(playerid, 2.0, CaixaInfo[c][CPX], CaixaInfo[c][CPY], CaixaInfo[c][CPZ]))
  314.         return c;
  315.     }
  316.     return MAX_CAIXAS+1;
  317. }
  318.  
  319. stock IsPlayerInCaixa(playerid, caixa)
  320. {
  321.     if(IsPlayerInRangeOfPoint(playerid, 2.0, CaixaInfo[caixa][CPX], CaixaInfo[caixa][CPY], CaixaInfo[caixa][CPZ])) return true;
  322.     return false;
  323. }
  324.  
  325. stock pNome(playerid)
  326. {
  327.     new name[20];
  328.     GetPlayerName(playerid, name, sizeof(name));
  329.     return name;
  330. }
  331.  
  332. stock MSG(playerid, color, fstring[], {Float, _}:...)  //Stock feita por LeLeTe
  333. {
  334.     static const STATIC_ARGS = 3;
  335.     static const BYTES_PER_CELL = 4;
  336.     new n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
  337.     if (n)
  338.     {
  339.         new message[128],
  340.             arg_start,
  341.             arg_end;
  342.  
  343.         #emit CONST.alt        fstring
  344.         #emit LCTRL          5
  345.         #emit ADD
  346.         #emit STOR.S.pri       arg_start
  347.  
  348.         #emit LOAD.S.alt       n
  349.         #emit ADD
  350.         #emit STOR.S.pri       arg_end
  351.  
  352.         do
  353.         {
  354.             #emit LOAD.I
  355.             #emit PUSH.pri
  356.             arg_end -= BYTES_PER_CELL;
  357.             #emit LOAD.S.pri     arg_end
  358.         }
  359.         while (arg_end > arg_start);
  360.  
  361.         #emit PUSH.S         fstring
  362.         #emit PUSH.C         128
  363.         #emit PUSH.ADR        message
  364.  
  365.         n += BYTES_PER_CELL * 3;
  366.         #emit PUSH.S         n
  367.         #emit SYSREQ.C        format
  368.  
  369.         n += BYTES_PER_CELL;
  370.         #emit LCTRL          4
  371.         #emit LOAD.S.alt       n
  372.         #emit ADD
  373.         #emit SCTRL          4
  374.  
  375.         return SendClientMessage(playerid, color, message);
  376.     }
  377.     else
  378.     {
  379.         return SendClientMessage(playerid, color, fstring);
  380.     }
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement