26.12.2018, 13:29
Olб, estou a alguns meses estudando sobre a linguagem Pawn e como um trabalho para teste de conhecimentos sobre a mesma decidi fazer essa minha primeira include, vamos considerar como uma prova de aprendizagem.
Sobre a funcionalidade do cуdigo em questгo й simples, ele serve tanto para soltar como para pegar no chгo. As teclas de atalho sгo 'Y' para pegar e 'N' para soltar.
Vocк precisa adicionar em seu cуdigo:Sobre a funcionalidade do cуdigo em questгo й simples, ele serve tanto para soltar como para pegar no chгo. As teclas de atalho sгo 'Y' para pegar e 'N' para soltar.
pawn Code:
#include morningstar_weapons
public OnGameModeInit()
{
inicarMorningstarWeapons();
return true;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
pegarArma(playerid, newkeys);
soltarArma(playerid, newkeys);
return true;
}
pawn Code:
#include a_samp.inc
#define MAX_WEAPONS_IN_GROUND 300
new Float: posicao_arma[MAX_WEAPONS_IN_GROUND][3];
new GunName[47][20] =
{
"Fist","Brass Knuckles","Golf Club","Nightstick","Knife","Basebal Bat","Shovel","Pool Cue","Katana","Chainsaw","Double-ended Dildo","Dildo","Vibrator",
"Silver Vibrator","Flowers","Cane","Grenade","Tear Gas","Molotv Cocktail","?","?","?","9mm","Silenced 9mm","Desert Eagle","Shotgun","Sawnoff-Shotgun",
"Combat Shotgun","Micro-SMG","MP5","Ak-47","M4","Tec9","Country Rifle","Sniper Rifle","RPG","HS-RPG","Flame-Thrower","Minigun","Satchel Charge","Detonator",
"Spray Can","Fire Extinguisher","Camera","Night Goggles","Thermal Goggles","Parachute"
};
enum aInfo
{
aModelo,
aMunicao,
aPickup
}
new arma_info[MAX_WEAPONS_IN_GROUND][aInfo];
stock inicarMorningstarWeapons()
{
for(new i; i < MAX_WEAPONS_IN_GROUND; i++)
{
arma_info[i][aModelo] = 5555;
}
return true;
}
stock pegarArma(playerid, key_pressed)
{
new string_local[128];
if(key_pressed == KEY_YES)
{
for(new i; i < MAX_WEAPONS_IN_GROUND; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, posicao_arma[i][0], posicao_arma[i][1], posicao_arma[i][2]))
{
if(arma_info[i][aModelo] != 5555)
{
GivePlayerWeapon(playerid, arma_info[i][aModelo], arma_info[i][aMunicao]);
format(string_local, sizeof(string_local), "Info: Vocк pegou a arma %s com %03d de muniзгo.", GunName[arma_info[i][aModelo]], arma_info[i][aMunicao]);
SendClientMessage(playerid, 0xA9C4E4FF, string_local);
arma_info[i][aModelo] = 5555;
DestroyPickup(arma_info[i][aPickup]);
break;
}
}
}
}
return true;
}
stock soltarArma(playerid, key_pressed)
{
new string_local[128];
new Float: x, Float: y, Float:z;
GetPlayerPos(playerid, x, y, z);
new weapon = GetPlayerWeapon(playerid);
if(key_pressed == KEY_NO)
{
for(new i; i < MAX_WEAPONS_IN_GROUND; i++)
{
if(arma_info[i][aModelo] == 5555)
{
GetPlayerWeaponData(playerid, GetWeaponSlot(weapon), arma_info[i][aModelo], arma_info[i][aMunicao]);
RemovePlayerWeapon(playerid, weapon);
format(string_local, sizeof(string_local), "Info: Vocк soltou a arma %s com %03d de muniзгo.", GunName[arma_info[i][aModelo]], arma_info[i][aMunicao]);
SendClientMessage(playerid, 0xA9C4E4FF, string_local);
arma_info[i][aPickup] = CreatePickup(GetWeaponModelID(weapon), 23, x, y, z, -1);
posicao_arma[i][0] = x;
posicao_arma[i][1] = y;
posicao_arma[i][2] = z;
break;
}
}
}
return true;
}
stock GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0,1: slot = 0;
case 2 .. 9: slot = 1;
case 10 .. 15: slot = 10;
case 16 .. 18, 39: slot = 8;
case 22 .. 24: slot = 2;
case 25 .. 27: slot = 3;
case 28, 29, 32: slot = 4;
case 30, 31: slot = 5;
case 33, 34: slot = 6;
case 35 .. 38: slot = 7;
case 40: slot = 12;
case 41 .. 43: slot = 9;
case 44 .. 46: slot = 11;
}
return slot;
}
stock RemovePlayerWeapon(playerid, weaponid)
{
new plyWeapons[12];
new plyAmmo[12];
for(new slot = 0; slot != 12; slot++)
{
new wep, ammo;
GetPlayerWeaponData(playerid, slot, wep, ammo);
if(wep != weaponid)
{
GetPlayerWeaponData(playerid, slot, plyWeapons[slot], plyAmmo[slot]);
}
}
ResetPlayerWeapons(playerid);
for(new slot = 0; slot != 12; slot++)
{
GivePlayerWeapon(playerid, plyWeapons[slot], plyAmmo[slot]);
}
}
stock GetWeaponModelID(weaponid)
{
new wm;
switch( weaponid )
{
case WEAPON_BRASSKNUCKLE: wm = 331;
case WEAPON_GOLFCLUB: wm = 333;
case WEAPON_NITESTICK: wm = 334;
case WEAPON_KNIFE: wm = 335;
case WEAPON_BAT: wm = 336;
case WEAPON_SHOVEL: wm = 337;
case WEAPON_POOLSTICK: wm = 338;
case WEAPON_KATANA: wm = 339;
case WEAPON_CHAINSAW: wm = 341;
case WEAPON_DILDO: wm = 321;
case WEAPON_DILDO2: wm = 322;
case WEAPON_VIBRATOR: wm = 323;
case WEAPON_VIBRATOR2: wm = 324;
case WEAPON_FLOWER: wm = 325;
case WEAPON_CANE: wm = 326;
case WEAPON_GRENADE: wm = 342;
case WEAPON_TEARGAS: wm = 343;
case WEAPON_MOLTOV: wm = 344;
case WEAPON_COLT45: wm = 346;
case WEAPON_SILENCED: wm = 347;
case WEAPON_DEAGLE: wm = 348;
case WEAPON_SHOTGUN: wm = 349;
case WEAPON_SAWEDOFF: wm = 350;
case WEAPON_SHOTGSPA: wm = 351;
case WEAPON_UZI: wm = 352;
case WEAPON_MP5: wm = 353;
case WEAPON_AK47: wm = 355;
case WEAPON_M4: wm = 356;
case WEAPON_TEC9: wm = 372;
case WEAPON_RIFLE: wm = 357;
case WEAPON_SNIPER: wm = 358;
case WEAPON_ROCKETLAUNCHER: wm = 359;
case WEAPON_HEATSEEKER: wm = 360;
case WEAPON_FLAMETHROWER: wm = 361;
case WEAPON_MINIGUN: wm = 362;
case WEAPON_SATCHEL: wm = 363;
case WEAPON_BOMB: wm = 364;
case WEAPON_SPRAYCAN: wm = 365;
case WEAPON_FIREEXTINGUISHER: wm = 366;
case WEAPON_CAMERA: wm = 367;
}
return wm;
}
Obrigado e aguardo os feedback's!
sr. Morningstar
sr. Morningstar