Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arquivo: armas.pwn
- * Autor: Fl�vio Toribio
- * Contato: [email protected]
- * Descri��o: Salva as armas dos jogadores indenpendente de qualquer sistema de registro
- * Fun��es:
- * LoadWeapons(playerid)
- * Par�metro 1: playerid - ID do jogador para salvar as armas
- * Retorna: 1 se sucedido, 0 se mal sucedido
- *
- * SaveWepoans(playerid)
- * Par�metro 1: playerid - ID do jogador para salvar as armas
- * Retorna: 1 se sucedido, 0 se mal sucedido
- * Defini��es:
- * WEAPON_FILE - Define em qual arquivo as armas v�o ser salvas
- *
- */
- #include <a_samp>
- #define COLOR_RED 0xAA3333AA
- #define WEAPON_FILE "armas.cfg"
- new Menu:marmas;
- new garma[MAX_PLAYERS][2];
- public OnFilterScriptInit()
- {
- marmas = CreateMenu("Armas", 1, 50.0, 180.0, 200.0, 200.0);
- AddMenuItem(marmas, 0, "M4");
- AddMenuItem(marmas, 0, "Tec9");
- if(!fexist(WEAPON_FILE))
- {
- new File:tmp;
- tmp = fopen(WEAPON_FILE, io_write);
- fclose(tmp);
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)return LoadWeapons(playerid);
- public OnPlayerDeath(playerid, killerid, reason)return SaveWeapons(playerid);
- public OnPlayerDisconnect(playerid, reason)return SaveWeapons(playerid);
- stock LoadWeapons(playerid)
- {
- new File:armas, tmp[256], fname[30], pname[30], arma[13], municao[13];
- armas = fopen(WEAPON_FILE, io_read);
- GetPlayerName(playerid, pname, sizeof pname);
- while(fread(armas, tmp, sizeof tmp, false))
- {
- new off[256], index;
- off = strtok(tmp, index);
- strmid(fname, off, 0, strlen(off));
- if(strcmp(pname, fname, false) != 0)continue;
- for(new a; a < 12; a++)arma[a] = strval(strtok(tmp, index));
- for(new m; m < 12; m++)municao[m] = strval(strtok(tmp, index));
- for(new i; i < 12; i++)
- {
- if(arma[i] > 0 && arma[i] < 47 && municao[i] > 0)
- GivePlayerWeapon(playerid, arma[i], municao[i]);
- }
- }
- fclose(armas);
- return 1;
- }
- stock SaveWeapons(playerid)
- {
- new File:armas, File:ftmp, tmp[256], fname[30], pname[30], arma[13], municao[13];
- armas = fopen(WEAPON_FILE, io_readwrite);
- ftmp = fopen(WEAPON_FILE#.tmp, io_write);
- GetPlayerName(playerid, pname, sizeof pname);
- while(fread(armas, tmp, sizeof tmp, false))
- {
- new off[256], index;
- off = strtok(tmp, index);
- strmid(fname, off, 0, strlen(off));
- if(!strcmp(pname, fname, false))continue;
- format(tmp, sizeof tmp, "%s", tmp);
- fwrite(ftmp, tmp);
- }
- fclose(armas);
- fclose(ftmp);
- fremove(WEAPON_FILE);
- armas = fopen(WEAPON_FILE, io_write);
- ftmp = fopen(WEAPON_FILE#.tmp, io_read);
- while(fread(ftmp, tmp))
- {
- format(tmp, sizeof tmp, "%s", tmp);
- fwrite(armas, tmp);
- }
- fclose(ftmp);
- fremove(WEAPON_FILE#.tmp);
- for(new i; i < 12; i++)GetPlayerWeaponData(playerid, i+1, arma[i+1], municao[i+1]);
- for(new i; i < 12; i++)
- {
- if(arma[i+1] != garma[playerid][0] || arma[i+1] != garma[playerid][1])
- arma[i+1] = 0;
- }
- format(tmp, sizeof tmp, "%s ", pname);
- for(new a; a < 24; a++)
- {
- new s[10];
- if(a < 12)
- {
- format(s, sizeof s, "%d ", arma[a]);
- strcat(tmp, s);
- } else {
- format(s, sizeof s, "%d ", municao[a-12]);
- strcat(tmp, s);
- }
- }
- strcat(tmp, "\r\n");
- fwrite(armas, tmp);
- fclose(armas);
- return 1;
- }
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext, "/teste", true))
- {
- ShowMenuForPlayer(marmas, playerid);
- TogglePlayerControllable(playerid, false);
- return 1;
- }
- return 0;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- new Menu:current;
- new dinheiro;
- dinheiro = GetPlayerMoney(playerid);
- if(current == marmas)
- {
- switch(row)
- {
- case 0:
- {
- if(dinheiro >= 100)
- {
- GivePlayerMoney(playerid, -100);
- GivePlayerWeapon(playerid, 24, 50);
- SendClientMessage(playerid, COLOR_RED, "Voc� comprou uma M4");
- SaveWeapons(playerid);
- } else {
- SendClientMessage(playerid, COLOR_RED, "Voc� n�o tem grana!");
- }
- TogglePlayerControllable(playerid, false);
- return 1;
- }
- case 1:
- {
- if(dinheiro >= 100)
- {
- GivePlayerMoney(playerid, -100);
- GivePlayerWeapon(playerid, 31, 50);
- SendClientMessage(playerid, COLOR_RED, "Voc� comprou uma TEC9");
- SaveWeapons(playerid);
- } else {
- SendClientMessage(playerid, COLOR_RED, "Voc� n�o tem Grana!");
- }
- TogglePlayerControllable(playerid, false);
- return 1;
- }
- }
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys == 16 && GetPlayerMenu(playerid) == marmas)
- HideMenuForPlayer(marmas, playerid);
- return 1;
- }
Add Comment
Please, Sign In to add comment