Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- #include <sscanf2>
- //------------------------------------------------------------------------------
- // IMPORTANTE - IMPORTANTE - IMPORTANTE - IMPORTANTE - IMPORTANTE - IMPORTANTE
- //------------------------------------------------------------------------------
- //SE NAO USAR ANTI-MONEY-HACK OU ALGUM DINHEIRO SECUNDARIO APAGUE A LINHA ABAIXO
- #define GivePlayerMoney(%0,%1) CallRemoteFunction("DarDinheiro","dd",%0,%1)
- //------------------------------------------------------------------------------
- #define MAX_CAIXAS (100)
- #define PAG_PADRAO 30000
- #define PAG_RANDOM 50000
- #define TEMPO_PADRAO 60000 //Tempo para assaltar + random(Tempo_Random)
- #define TEMPO_RANDOM 60000 //Tempo para assaltar + random(Tempo_Random)
- #define TEMPO_LIBERAR_CAIXA 60000
- #define VALOR_CABECA 50000
- #define VALOR_CABECA_RANDOM 50000
- #define AZULZINHO 0x10CCF3AA
- #define COR_ASSALTO 0xFF5B60AA
- #define COR_MARCADOS 0x14CC00AA
- #define SQL_HOST "HOST"
- #define SQL_USER "USUARIO"
- #define SQL_PASS "SENHA"
- #define SQL_DB "DATABASE"
- #define mysql_fetch_row(%1) mysql_fetch_row_format(%1,"|")
- #define MAXIMO_TENTATIVAS 10
- new mQuery[200],
- string[128];
- enum CaixaInfoEnum
- {
- Criado,
- Float:CPX, //Pos X
- Float:CPY, //Pos Y
- Float:CPZ, //Pos Z
- Float:CRX, //Rotacao X
- Float:CRY, //Rotacao Y
- Float:CRZ, //Rotacao Z
- Nome[128], //Nome do Caixa
- Roubado,
- Objeto
- }
- new CaixaInfo[MAX_CAIXAS][CaixaInfoEnum],
- ValorCabeca[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- for(new x = 0; x <= MAXIMO_TENTATIVAS; x++)
- {
- mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
- if(mysql_ping() >= 1)
- {
- printf("MYSQL: Conectado com sucesso ao banco de dados %s\n",SQL_DB);
- print("|--------------------------------|");
- print("|Sistema de caixa eletronico v1.0|");
- print("| Produzido por Kmatsu |");
- print("|--------------------------------|");
- break;
- }
- else
- {
- printf("MySQL: Falha de conexao tentativa %d de %d", x, MAXIMO_TENTATIVAS);
- if(x == MAXIMO_TENTATIVAS)
- {
- print("Falha ao conectar à base de dados MySql");
- print("Talvez o filterscript nao irá funcionar");
- SendRconCommand("unloadfs Caixas");
- return true;
- }
- }
- }
- mysql_debug(1);
- mysql_query("CREATE TABLE IF NOT EXISTS Caixas(\
- ID INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,\
- Nome VARCHAR(128) NOT NULL,\
- PosX Float(20) NOT NULL,\
- PosY Float(20) NOT NULL,\
- PosZ Float(20) NOT NULL,\
- RotX Float(20) NOT NULL,\
- RotY Float(20) NOT NULL,\
- RotZ Float(20) NOT NULL)");
- mysql_query("CREATE TABLE IF NOT EXISTS Marcados(\
- Nome VARCHAR(20) NOT NULL,\
- Valor INT(20) NOT NULL)");
- CarregarCaixas();
- return true;
- }
- //----------------COMANDOS
- cmd(criarcaixa, playerid, params[])
- {
- new Float:cX, Float:cY, Float:cZ, NomeCaixa[50];
- if(sscanf(params, "s[50]", NomeCaixa)) return MSG(playerid, 0x1E90FF99, "Uso correto: /criarcaixa [Nome do caixa]");
- GetPlayerPos(playerid, cX, cY, cZ);
- 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");
- return true;
- }
- cmd(destruircaixa, playerid, params[])
- {
- #pragma unused params
- if(GetPlayerCaixa(playerid) > MAX_CAIXAS+1) return MSG(playerid, -1, "Você nao está perto de nenhum caixa eletronico");
- DestroyObject(CaixaInfo[GetPlayerCaixa(playerid)][Objeto]);
- format(mQuery, sizeof(mQuery), "DELETE FROM Caixas WHERE Nome='%s', PosX=%f, PosY=%f, PosZ=%f, RotX=%f, RotY=%f, RotZ=%f",
- 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]);
- return true;
- }
- cmd(assaltarcaixa, playerid, params[])
- {
- #pragma unused params
- if(GetPlayerCaixa(playerid) > MAX_CAIXAS+1) return MSG(playerid, -1, "Você nao está perto de nenhum caixa eletronico");
- AssaltarCaixa(playerid, GetPlayerCaixa(playerid));
- return true;
- }
- cmd(marcados, playerid, params[])
- {
- #pragma unused params
- new Cont;
- MSG(playerid, COR_MARCADOS, "Jogadores com a vida marcada:");
- for(new i, j = GetMaxPlayers(); i < j; i++)
- {
- if(ValorCabeca[i] == 0) continue;
- MSG(playerid, COR_MARCADOS, "%s [%d] - Valor: R$ %d", pNome(i), i, ValorCabeca[i]);
- Cont++;
- }
- if(Cont == 0) MSG(playerid, COR_MARCADOS, "Ninguem está marcadado :(");
- return true;
- }
- cmd(meucaixa, playerid, params[])
- {
- #pragma unused params
- new caixa = GetPlayerCaixa(playerid);
- if(caixa == MAX_CAIXAS+1) MSG(playerid, -1, "Você nao está em nenhum caixa");
- else MSG(playerid, -1, "Você está no caixa %s", CaixaInfo[GetPlayerCaixa(playerid)][Nome]);
- return true;
- }
- //-----------------PUBLICS
- public OnPlayerConnect(playerid)
- {
- CarregarMarcado(playerid);
- //SendClientMessage(playerid, -1, "OnPlayerConnect - KAC");
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- printf("OnPlayerDeath - caixas");
- if(killerid != INVALID_PLAYER_ID)
- {
- if(ValorCabeca[playerid] > 0)
- {
- GivePlayerMoney(killerid, ValorCabeca[playerid]);
- format(string, sizeof(string), "O Player %s matou o procurado %s e ganhou R$ %d", pNome(playerid), pNome(killerid), ValorCabeca[playerid]);
- SendClientMessageToAll(AZULZINHO, string);
- ValorCabeca[playerid] = 0;
- format(mQuery, sizeof(mQuery), "DELETE FROM Marcados WHERE Nome='%s'", pNome(playerid));
- mysql_query(mQuery);
- }
- }
- }
- //----------------STOCKS
- stock CarregarCaixas()
- {
- new idx, a;
- printf("\n");
- printf("===============[CARREGANDO CAIXAS]=============");
- format(mQuery, sizeof(mQuery), "SELECT * FROM Caixas");
- mysql_query(mQuery);
- mysql_store_result();
- while(mysql_fetch_row_format(mQuery,"|"))
- {
- idx++;
- 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]);
- 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);
- CaixaInfo[idx][Criado] = 1;
- printf("|-----------------[CAIXA %03d]----------------|", idx);
- if(strlen(CaixaInfo[idx][Nome]) <= 36) printf("| Nome: %36s |", CaixaInfo[idx][Nome]);
- if(strlen(CaixaInfo[idx][Nome]) >= 37) printf("| Nome: %34s...|", CaixaInfo[idx][Nome]);
- printf("| PosX: %04.2f PosY: %04.2f PosZ: %04.2f|", CaixaInfo[idx][CPX], CaixaInfo[idx][CPY], CaixaInfo[idx][CPZ]);
- printf("| RotX: %04.2f RotY: %04.2f RotZ: %04.2f|", CaixaInfo[idx][CRX], CaixaInfo[idx][CRY], CaixaInfo[idx][CRZ]);
- printf("|--------------------------------------------|");
- printf("\n");
- }
- printf("Todos os Caixas Eletronicos foram carregados com sucesso!");
- return true;
- }
- stock CriarCaixa(nome[], Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ)
- {
- for(new i = 0; i <= MAX_CAIXAS; i++)
- {
- if(CaixaInfo[i][Criado] == 0)
- {
- CaixaInfo[i][Criado] = 1;
- CaixaInfo[i][CPX] = X;
- CaixaInfo[i][CPY] = Y;
- CaixaInfo[i][CPZ] = Z;
- CaixaInfo[i][CRX] = RX;
- CaixaInfo[i][CRY] = RY;
- CaixaInfo[i][CRZ] = RZ;
- format(CaixaInfo[i][Nome], 128, "%s", nome);
- CaixaInfo[i][Roubado] = 0;
- CaixaInfo[i][Objeto] = CreateObject(2942, X, Y, Z, RX, RY, RZ, 150.0);
- 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]);
- mysql_query(mQuery);
- return true;
- }
- }
- return false;
- }
- stock MarcarPlayer(playerid, valor)
- {
- ValorCabeca[playerid] = ValorCabeca[playerid]+valor;
- format(mQuery, sizeof(mQuery), "SELECT * FROM Marcados WHERE Nome='%s'", pNome(playerid));
- mysql_query(mQuery);
- mysql_store_result();
- if(mysql_num_rows() > 0)
- {
- format(mQuery, sizeof(mQuery), "UPDATE Marcados SET Valor=%d WHERE Nome='%s'", ValorCabeca[playerid], pNome(playerid));
- mysql_query(mQuery);
- }
- else
- {
- format(mQuery, sizeof(mQuery), "INSERT INTO Marcados (Nome, Valor) VALUES ('%s', %d)", pNome(playerid), ValorCabeca[playerid]);
- mysql_query(mQuery);
- }
- }
- stock CarregarMarcado(playerid)
- {
- ValorCabeca[playerid] = 0;
- format(mQuery, sizeof(mQuery), "SELECT * FROM Marcados WHERE Nome='%s'", pNome(playerid));
- mysql_query(mQuery);
- mysql_store_result();
- new Nomea[20];
- if(mysql_num_rows() > 0)
- {
- while(mysql_fetch_row_format(mQuery,"|"))
- {
- sscanf(mQuery, "p<|>s[20]d", Nomea, ValorCabeca[playerid]);
- }
- }
- }
- stock AssaltarCaixa(playerid, caixa)
- {
- if(CaixaInfo[caixa][Roubado] == 1) return MSG(playerid, -1, "Esse caixa eletronico ja foi ou está sendo assaltado");
- CaixaInfo[caixa][Roubado] = 1;
- MSG(playerid, AZULZINHO, "Você está assaltando o caixa \"%s\", Aguarde alguns minutos para levar a grana", CaixaInfo[caixa][Nome]);
- format(string, sizeof(string), "O Player %s está assaltando o caixa eletronico %s", pNome(playerid), CaixaInfo[caixa][Nome]);
- SendClientMessageToAll(COR_ASSALTO, string);
- new rand = random(VALOR_CABECA_RANDOM)+VALOR_CABECA;
- MarcarPlayer(playerid, rand);
- format(string, sizeof(string), "A Prefeitura está dando um premio de R$ %d pela vida de %s", rand, pNome(playerid));
- SendClientMessageToAll(AZULZINHO, string);
- SetTimerEx("PegarGrana", TEMPO_PADRAO+random(TEMPO_RANDOM), false, "dd", playerid, caixa);
- return true;
- }
- forward PegarGrana(playerid, caixa);
- public PegarGrana(playerid, caixa)
- {
- if(!IsPlayerInCaixa(playerid, caixa)) return MSG(playerid, -1, "Você nao está perto de nenhum caixa eletronico, por isso nao levou a grana");
- new rand = random(PAG_RANDOM)+PAG_PADRAO;
- GivePlayerMoney(playerid, PAG_PADRAO);
- MSG(playerid, AZULZINHO, "Você assaltou o caixa eletronico e levou R$ %d", rand+PAG_PADRAO);
- format(string, sizeof(string), "O Player assaltou o caixa eletronico %s", CaixaInfo[caixa][Nome]);
- SendClientMessageToAll(COR_ASSALTO, string);
- SetTimerEx("LiberarCaixa", TEMPO_LIBERAR_CAIXA, false, "d", caixa);
- return true;
- }
- forward LiberarCaixa(caixa);
- public LiberarCaixa(caixa)
- {
- CaixaInfo[caixa][Roubado] = 0;
- }
- stock GetPlayerCaixa(playerid)
- {
- for(new c = 0; c <= MAX_CAIXAS; c++)
- {
- if(CaixaInfo[c][Criado] == 0) continue;
- if(IsPlayerInRangeOfPoint(playerid, 2.0, CaixaInfo[c][CPX], CaixaInfo[c][CPY], CaixaInfo[c][CPZ]))
- return c;
- }
- return MAX_CAIXAS+1;
- }
- stock IsPlayerInCaixa(playerid, caixa)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, CaixaInfo[caixa][CPX], CaixaInfo[caixa][CPY], CaixaInfo[caixa][CPZ])) return true;
- return false;
- }
- stock pNome(playerid)
- {
- new name[20];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- stock MSG(playerid, color, fstring[], {Float, _}:...) //Stock feita por LeLeTe
- {
- static const STATIC_ARGS = 3;
- static const BYTES_PER_CELL = 4;
- new n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
- if (n)
- {
- new message[128],
- arg_start,
- arg_end;
- #emit CONST.alt fstring
- #emit LCTRL 5
- #emit ADD
- #emit STOR.S.pri arg_start
- #emit LOAD.S.alt n
- #emit ADD
- #emit STOR.S.pri arg_end
- do
- {
- #emit LOAD.I
- #emit PUSH.pri
- arg_end -= BYTES_PER_CELL;
- #emit LOAD.S.pri arg_end
- }
- while (arg_end > arg_start);
- #emit PUSH.S fstring
- #emit PUSH.C 128
- #emit PUSH.ADR message
- n += BYTES_PER_CELL * 3;
- #emit PUSH.S n
- #emit SYSREQ.C format
- n += BYTES_PER_CELL;
- #emit LCTRL 4
- #emit LOAD.S.alt n
- #emit ADD
- #emit SCTRL 4
- return SendClientMessage(playerid, color, message);
- }
- else
- {
- return SendClientMessage(playerid, color, fstring);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement