19.12.2013, 00:27
Sistema de inventario
comando /minhaarma:
(caso tenham duvidas, criticas, sujestoes.. comentem pf)
Eai pessoa vim hoje postar meu sistema de inventario,comando /inventario:
esta bem simples no momento, nao usei cores nem nada mas resolvi postar aqui para vocкs verem
e usarem se quiser...
Quote:
[subcomandos] info (exibe todas as armas no inventario) colocararma (coloca a arma no inventrario) retirararma [slot] (retira a arma do inventario) |
Quote:
[subcomandos] deixar (laga sua arma no chгo e cria um objeto idкntico a sua arma prуximo aos pкs do personagem) pegar (remove o objeto do chгo e da a arma para o jogador) |
pawn Код:
#include a_samp
#include zcmd
#include sscanf2
#include streamer
#define max_armas 10 //maximo de armas por inventario (ex: o inventario ira do slot 0 ao 9);
enum _enum_inv
{
wm_objeto,
Text3D:wm_label,
Float:wm_pos[3],
wm_interior,
wm_world,
wm_data[2]
}
enum enum_p
{
pl_armaid,
pl_balas
}
new drop@inventario[MAX_PLAYERS][_enum_inv]; //drop;
new player@inventario[MAX_PLAYERS][max_armas][enum_p]; //inventario;
new _string[100];
new GetDynamicWeaponObject[47] = {
0,331,333,334,335,336,337,338,339,341,321,322,323,324,325,326,342,343,344,
0,0,0,346,347,348,349,350,351,352,353,355,356,372,357,358,359,360,361,362,
363,364,365,366,367,368,368,371
};
new GetDynamicWeaponName[48][] = {
"Nothink", "Brass Knuckles", "Golf Club", "Nitestick", "Knife", "Baseball Bat",
"Showel", "Pool Cue", "Katana", "Chainsaw", "Purple Dildo", "Small White Dildo",
"Long White Dildo", "Vibrator", "Flowers", "Cane", "Grenade", "Tear Gas", "Molotov",
"Vehicle Missile", "Hydra Flare", "Jetpack", "Glock", "Silenced Colt", "Desert Eagle",
"Shotgun", "Sawn Off", "Combat Shotgun", "Micro UZI", "MP5", "AK47", "M4", "Tec9",
"Rifle", "Sniper Rifle", "Rocket Launcher", "HS Rocket Launcher", "Flamethrower", "Minigun",
"Satchel Charge", "Detonator", "Spraycan", "Fire Extinguisher", "Camera", "Nightvision",
"Infrared Vision", "Parachute", "Fake Pistol"
};
command(inventario, playerid, params [])
{
new subcmd[128], i, armaid, balas, arma;
if(sscanf(params, "s[128]I(-1)", subcmd, i))
{
SendClientMessage(playerid, -1, "[Comandos Disponнveis]");
SendClientMessage(playerid, -1, "[subcmds] info | colocararma | retirararma [slot]");
SendClientMessage(playerid, -1, "[exemplo] /inventario retirararma [slot]");
return 1;
}
if(!strcmp(subcmd, "info", true))
{
SendClientMessage(playerid, -1, "[ Minhas Armas ]");
for(new y = 0; y < max_armas; y++)
{
if(player@inventario[playerid][y][pl_armaid] > 0)
{
armaid = player@inventario[playerid][y][pl_armaid];
balas = player@inventario[playerid][y][pl_balas];
format(_string, sizeof(_string), "[SLOT %d] | %s | balas = %d |", y, GetDynamicWeaponName[armaid], balas);
SendClientMessage(playerid, -1, _string);
}
}
return 1;
}
if(!strcmp(subcmd, "colocararma", true))
{
for(new y = 0; y < max_armas; y++)
{
if(player@inventario[playerid][y][pl_armaid] != 0) continue;
armaid = y;
break;
}
arma = GetPlayerWeapon(playerid), balas = GetPlayerAmmo(playerid);
player@inventario[playerid][armaid][pl_armaid] = arma;
player@inventario[playerid][armaid][pl_balas] = balas;
format(_string, sizeof(_string), "voce colocou uma %s no slot %d.", GetDynamicWeaponName[arma], armaid);
SendClientMessage(playerid, -1, _string);
RemovePlayerWeapon(playerid, arma);
return 1;
}
if(!strcmp(subcmd, "retirararma", true))
{
if(i == -1) return SendClientMessage(playerid, 0x33AA3300, "erro: comando: inventario pegararma <armaid>");
if(player@inventario[playerid][i][pl_armaid] == 0) return SendClientMessage(playerid, 0x33AA3300, "erro: voce nгo possue uma arma nesse slot");
arma = player@inventario[playerid][i][pl_armaid];
balas = player@inventario[playerid][i][pl_balas];
player@inventario[playerid][i][pl_armaid] = 0,
player@inventario[playerid][i][pl_balas] = 0;
format(_string, sizeof(_string), "voce retirou uma %s do slot %d.", GetDynamicWeaponName[arma], i);
SendClientMessage(playerid, -1, _string);
GivePlayerWeapon(playerid, arma, balas);
return 1;
}
return 1;
}
command(minhaarma, playerid, params [])
{
new subcmd[128], balas, arma;
if(sscanf(params, "s[128]", subcmd))
{
SendClientMessage(playerid, -1, "[Comandos Disponнveis]");
SendClientMessage(playerid, -1, "[subcmds] deixar | pegar");
SendClientMessage(playerid, -1, "[exemplo] /minhaarma deixar");
return 1;
}
if(!strcmp(subcmd, "deixar", true))
{
new Float:pos[3], interior, world, y = max_armas+1;
if(GetPlayerWeapon(playerid) == 0) return SendClientMessage(playerid, 0x33AA3300, "erro: voce nгo possue uma arma em suas maos.");
for(new i = 0; i < max_armas; i++)
{
if(drop@inventario[i][wm_objeto] != 0) continue;
y = i;
break;
}
if(y > max_armas) return true;
arma = GetPlayerWeapon(playerid);
balas = GetPlayerAmmo(playerid);
GetPlayerPos(playerid, pos[0], pos[1], pos[2]), interior = GetPlayerInterior(playerid), world = GetPlayerVirtualWorld(playerid);
drop@inventario[y][wm_objeto] = CreateDynamicObject(GetDynamicWeaponObject[arma], pos[0], pos[1], pos[2]-1, 93.7, 120.0, 120.0, world, interior);
format(_string, sizeof(_string), "%s\n%d", GetDynamicWeaponName[arma], balas), drop@inventario[y][wm_label] = Create3DTextLabel(_string, -1, pos[0], pos[1], pos[2], 3.0, world, interior);
drop@inventario[y][wm_pos][0] = pos[0];
drop@inventario[y][wm_pos][1] = pos[1];
drop@inventario[y][wm_pos][2] = pos[2];
drop@inventario[y][wm_interior] = interior;
drop@inventario[y][wm_world] = world;
drop@inventario[y][wm_data][0] = arma;
drop@inventario[y][wm_data][1] = balas;
format(_string, sizeof(_string), "voce largou uma %s com %d no slot %d.", GetDynamicWeaponName[arma], balas, y);
SendClientMessage(playerid, -1, _string);
RemovePlayerWeapon(playerid, arma);
return true;
}
if(!strcmp(subcmd, "pegar", true))
{
new y = max_armas+1;
for(new x = 0; x < max_armas; x++)
{
if(!IsPlayerInRangeOfPoint(playerid, 1.0, drop@inventario[x][wm_pos][0],drop@inventario[x][wm_pos][1], drop@inventario[x][wm_pos][2])) continue;
y = x;
break;
}
if(y > max_armas) return true;
Delete3DTextLabel(drop@inventario[y][wm_label]);
DestroyDynamicObject(drop@inventario[y][wm_objeto]);
drop@inventario[y][wm_pos][0] = 0.0;
drop@inventario[y][wm_pos][1] = 0.0;
drop@inventario[y][wm_pos][2] = 0.0;
drop@inventario[y][wm_interior] = 0;
drop@inventario[y][wm_world] = 0;
arma = drop@inventario[y][wm_data][0];
balas = drop@inventario[y][wm_data][1];
drop@inventario[y][wm_data][0] = 0;
drop@inventario[y][wm_data][1] = 0;
format(_string, sizeof(_string), "voce pegou uma %s com %d no slot %d.", GetDynamicWeaponName[arma], balas, y);
SendClientMessage(playerid, -1, _string);
GivePlayerWeapon(playerid, arma, balas);
return true;
}
return true;
}
command(armas, playerid, params []) //teste cmd
{
GivePlayerWeapon(playerid, 24, 50); //eagle
GivePlayerWeapon(playerid, 30, 50); //ak47
return true;
}
forward RemovePlayerWeapon(playerid, weaponid);
public RemovePlayerWeapon(playerid, weaponid)
{
if(!IsPlayerConnected(playerid) || weaponid < 0 || weaponid > 50) return;
new saveweapon[13], saveammo[13];
for(new slot = 0; slot < 13; slot++)
GetPlayerWeaponData(playerid, slot, saveweapon[slot], saveammo[slot]);
ResetPlayerWeapons(playerid);
for(new slot; slot < 13; slot++)
{
if(saveweapon[slot] == weaponid || saveammo[slot] == 0)
continue;
GivePlayerWeapon(playerid, saveweapon[slot], saveammo[slot]);
}
GivePlayerWeapon(playerid, 0, 1);
}