Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined _include_weapon_reload
- #endinput
- #endif
- #define _include_weapon_reload
- // ========================== INCLUDES ================================
- // --------------------------------------------------------------------
- #tryinclude <a_samp>
- #tryinclude <sscanf2>
- #tryinclude <Pawn.CMD>
- // ------------------------------------------------------------------
- // ========================== MACROS ================================
- // ------------------------------------------------------------------
- #define PRESSED(%0) (((newkeys&(%0))==(%0))&&((oldkeys&(%0))!=(%0)))
- #define PRESSING(%0,%1) (%0&(%1))
- #define KEY_AIM KEY_HANDBRAKE
- // ------------------------------------------------------------------
- // ========================== OUTROS ================================
- #define NAME_PROJECT "Weapon - Reload"
- #define CREATOR_PROJECT "Felipe_Alves"
- #define VERSION_PROJECT "2.0a"
- // ========================== VARIÁVEIS ================================
- // ---------------------------------------------------------------------
- enum Weapon_DATA{
- w_Weapon[13],
- w_Ammo[13],
- bool:w_TdShow,
- }
- static // Mude para 'new' para poder usar externamente
- w_Info[MAX_PLAYERS][Weapon_DATA],
- w_x_weapon[MAX_PLAYERS][13],
- w_x_ammo[MAX_PLAYERS][13],
- w_Timer_Player[MAX_PLAYERS][2],
- PlayerText:Weapon_InfosTD[MAX_PLAYERS][5]
- ;
- // ---------------------------------------------------------------------
- public OnGameModeInit()
- {
- print("\n--------------------------------------");
- print(" Carregado");
- printf("\n Nome: %s", NAME_PROJECT);
- printf(" By: %s", CREATOR_PROJECT);
- printf(" Versão: %s\n", VERSION_PROJECT);
- print("--------------------------------------\n");
- #if defined hook_OnGameModeInit
- return hook_OnGameModeInit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit hook_OnGameModeInit
- #if defined hook_OnGameModeInit
- forward hook_OnGameModeInit();
- #endif
- public OnGameModeExit(){
- print("\n--------------------------------------");
- print(" Encerrado");
- printf("\n Nome: %s", NAME_PROJECT);
- print("--------------------------------------\n");
- #if defined hook_OnGameModeExit
- return hook_OnGameModeExit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit hook_OnGameModeExit
- #if defined hook_OnGameModeExit
- forward hook_OnGameModeExit();
- #endif
- public OnPlayerConnect(playerid){
- w_Timer_Player[playerid][0] = SetTimerEx("Timer_Weapon_Check", 50, 1, "d", playerid);
- w_Timer_Player[playerid][1] = SetTimerEx("Timer_Weapon_Ammo", 50, 1, "d", playerid);
- Weapon_InfosTD[playerid][0] = CreatePlayerTextDraw(playerid, 505.599945, 96.915557, "Reserva");
- PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][0], 0.400000, 1.600000);
- PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][0], 1);
- PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][0], -50331393);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][0], 0);
- PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][0], 0);
- PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][0], 255);
- PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][0], 2);
- PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][0], 1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][0], 0);
- Weapon_InfosTD[playerid][1] = CreatePlayerTextDraw(playerid, 550.800292, 114.337753, "000/000");
- PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][1], 0.400000, 1.600000);
- PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][1], 2);
- PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][1], -1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][1], 0);
- PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][1], 0);
- PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][1], 255);
- PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][1], 3);
- PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][1], 1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][1], 0);
- Weapon_InfosTD[playerid][2] = CreatePlayerTextDraw(playerid, 507.200134, 115.333351, "box");
- PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][2], 0.000000, 1.608999);
- PlayerTextDrawTextSize(playerid, Weapon_InfosTD[playerid][2], 594.450439, 0.000000);
- PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][2], 1);
- PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][2], -1);
- PlayerTextDrawUseBox(playerid, Weapon_InfosTD[playerid][2], 1);
- PlayerTextDrawBoxColor(playerid, Weapon_InfosTD[playerid][2], 113);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][2], 0);
- PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][2], 0);
- PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][2], 255);
- PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][2], 1);
- PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][2], 1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][2], 0);
- Weapon_InfosTD[playerid][3] = CreatePlayerTextDraw(playerid, 506.800079, 60.720031, "box");
- PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][3], 0.000000, 1.560000);
- PlayerTextDrawTextSize(playerid, Weapon_InfosTD[playerid][3], 535.000000, 0.000000);
- PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][3], 1);
- PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][3], -1);
- PlayerTextDrawUseBox(playerid, Weapon_InfosTD[playerid][3], 1);
- PlayerTextDrawBoxColor(playerid, Weapon_InfosTD[playerid][3], 185);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][3], 0);
- PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][3], 0);
- PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][3], 255);
- PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][3], 1);
- PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][3], 1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][3], 0);
- Weapon_InfosTD[playerid][4] = CreatePlayerTextDraw(playerid, 520.598999, 60.422233, "0");
- PlayerTextDrawLetterSize(playerid, Weapon_InfosTD[playerid][4], 0.400000, 1.600000);
- PlayerTextDrawAlignment(playerid, Weapon_InfosTD[playerid][4], 2);
- PlayerTextDrawColor(playerid, Weapon_InfosTD[playerid][4], -1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][4], 0);
- PlayerTextDrawSetOutline(playerid, Weapon_InfosTD[playerid][4], 0);
- PlayerTextDrawBackgroundColor(playerid, Weapon_InfosTD[playerid][4], 255);
- PlayerTextDrawFont(playerid, Weapon_InfosTD[playerid][4], 1);
- PlayerTextDrawSetProportional(playerid, Weapon_InfosTD[playerid][4], 1);
- PlayerTextDrawSetShadow(playerid, Weapon_InfosTD[playerid][4], 0);
- for(new i = 0; i < 13; ++i){
- w_Info[playerid][w_Ammo][i] = 0;
- w_Info[playerid][w_Weapon][i] = 0;
- }
- #if defined hook_OnPlayerConnect
- return hook_OnPlayerConnect(playerid);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect hook_OnPlayerConnect
- #if defined hook_OnPlayerConnect
- forward hook_OnPlayerConnect(playerid);
- #endif
- public OnPlayerDisconnect(playerid, reason){
- KillTimer(w_Timer_Player[playerid][0]);
- KillTimer(w_Timer_Player[playerid][1]);
- w_Info[playerid][w_TdShow] = false;
- for(new x = 0; x < sizeof(Weapon_InfosTD[]); ++x){
- PlayerTextDrawHide(playerid, Weapon_InfosTD[playerid][x]);
- PlayerTextDrawDestroy(playerid, Weapon_InfosTD[playerid][x]);
- }
- #if defined hook_OnPlayerDisconnect
- return hook_OnPlayerDisconnect(playerid, reason);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect hook_OnPlayerDisconnect
- #if defined hook_OnPlayerDisconnect
- forward hook_OnPlayerDisconnect(playerid, reason);
- #endif
- forward Timer_Weapon_Ammo(playerid);
- public Timer_Weapon_Ammo(playerid){
- if(!IsPlayerConnected(playerid)) return 1;
- for(new i = 0; i < 13; ++i){
- GetPlayerWeaponData(playerid, i, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
- if(w_x_weapon[playerid][i] != 0 && w_x_ammo[playerid][i] == 0){
- SetPlayerAmmo(playerid, w_x_weapon[playerid][i], 1);
- continue;
- }
- }
- return 1;
- }
- forward Timer_Weapon_Check(playerid);
- public Timer_Weapon_Check(playerid){
- if(!IsPlayerConnected(playerid)) return 1;
- new weaponid = GetPlayerWeapon(playerid);
- if(weaponid >= 0 && weaponid <= 15 || weaponid == 44 && weaponid == 45 && weaponid == 46){
- if(w_Info[playerid][w_TdShow]){
- Esconder_wTD(playerid);
- }
- }else if(weaponid != 0){ // Verifica se ele está com uma arma na mão.
- if(!w_Info[playerid][w_TdShow])
- Mostrar_wTD(playerid);
- // ---------------------------
- new Text_w[14];
- new slot = SlotsWeapons(GetPlayerWeapon(playerid));
- format(Text_w, sizeof(Text_w), "%d", w_Info[playerid][w_Ammo][slot]);
- PlayerTextDrawSetString(playerid, Weapon_InfosTD[playerid][1], Text_w);
- if(w_x_ammo[playerid][slot] > 1){
- format(Text_w, sizeof(Text_w), "%d", w_x_ammo[playerid][slot]);
- }else if(w_x_ammo[playerid][slot] <= 0 && w_Info[playerid][w_Ammo][slot] >= 1){
- Text_w = "0";
- }else if(w_x_ammo[playerid][slot] == 1 && w_Info[playerid][w_Ammo][slot] >= 1){
- Text_w = "~r~Y";
- }
- PlayerTextDrawSetString(playerid, Weapon_InfosTD[playerid][4], Text_w);
- }else{
- Esconder_wTD(playerid);
- }
- return 1;
- }
- public OnPlayerUpdate(playerid){
- if(IsPlayerConnected(playerid)){
- new newkeys, x, y, oldkeys;
- GetPlayerKeys(playerid,newkeys,x,y);
- if(Closed_Weapon(playerid) && (PRESSING(newkeys, KEY_AIM | KEY_FIRE) || PRESSING(newkeys, KEY_FIRE) || PRESSED(KEY_FIRE))){
- SetPlayerArmedWeapon(playerid, 0);
- ClearAnimations(playerid);
- }
- }
- #if defined hook_OnPlayerUpdate
- return hook_OnPlayerUpdate(playerid);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerUpdate
- #undef OnPlayerUpdate
- #else
- #define _ALS_OnPlayerUpdate
- #endif
- #define OnPlayerUpdate hook_OnPlayerUpdate
- #if defined hook_OnPlayerUpdate
- forward hook_OnPlayerUpdate(playerid);
- #endif
- public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ){
- if(weaponid != 0){
- if(Closed_Weapon(playerid)){
- SetPlayerArmedWeapon(playerid, 0);
- ClearAnimations(playerid);
- }
- }
- #if defined hook_OnPlayerWeaponShot
- return hook_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerWeaponShot
- #undef OnPlayerWeaponShot
- #else
- #define _ALS_OnPlayerWeaponShot
- #endif
- #define OnPlayerWeaponShot hook_OnPlayerWeaponShot
- #if defined hook_OnPlayerWeaponShot
- forward hook_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
- #endif
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
- if(PRESSED(KEY_YES)){
- new weaponid = GetPlayerWeapon(playerid);
- if(weaponid != 0){
- new slot = SlotsWeapons(weaponid);
- new sammo = w_x_ammo[playerid][slot];
- new lammo = Weapon_Ammo_Limit(weaponid);
- if(weaponid == 1 || weaponid >= 1 && weaponid <= 15 || weaponid == 44 || weaponid == 45 || weaponid == 46) return true;
- if(sammo >= 1 && sammo < lammo){
- if(!(w_Info[playerid][w_Ammo][slot] >= 1)){
- w_Info[playerid][w_Ammo][slot] = 0;
- return SendClientMessage(playerid, 0xC1C1C1FF, "Você não possui bala reserva para recarregar.");
- }
- new r_weapon = w_Info[playerid][w_Ammo][slot];
- new calc = lammo - sammo;
- if(r_weapon >= calc){
- w_Info[playerid][w_Ammo][slot] -= calc;
- }else{
- w_Info[playerid][w_Ammo][slot] = 0;
- calc = r_weapon;
- }
- GivePlayerWeapon(playerid, weaponid, calc);
- }else{
- SendClientMessage(playerid, 0xC1C1C1FF, "Sua arma já está com o pente cheio.");
- }
- }
- }
- #if defined hook_OnPlayerKeyStateChange
- return hook_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerKeyStateChange
- #undef OnPlayerKeyStateChange
- #else
- #define _ALS_OnPlayerKeyStateChange
- #endif
- #define OnPlayerKeyStateChange hook_OnPlayerKeyStateChange
- #if defined hook_OnPlayerKeyStateChange
- forward hook_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- #endif
- stock Closed_Weapon(playerid){
- new weaponid = GetPlayerWeapon(playerid);
- new slot = SlotsWeapons(weaponid);
- if(weaponid == 1 || weaponid >= 1 && weaponid <= 15 || weaponid == 44 || weaponid == 45 || weaponid == 46) return false;
- if(weaponid != 0 && GetPlayerWeapon(playerid) == w_x_weapon[playerid][slot]){
- if(w_x_ammo[playerid][slot] == 1)
- return true;
- }
- return false;
- }
- stock GivePlayerWeaponEx(playerid, weaponid, ammo){
- new slot = SlotsWeapons(weaponid);
- new sammo = w_x_ammo[playerid][slot];
- new lammo = Weapon_Ammo_Limit(weaponid);
- if(w_x_weapon[playerid][slot] != weaponid){
- RemovePlayerWeaponSlot(playerid, slot);
- }
- PlayerGetWeapons(playerid, slot);
- if(weaponid == 1 || weaponid >= 1 && weaponid <= 15 || weaponid == 44 || weaponid == 45 || weaponid == 46){
- w_Info[playerid][w_Ammo][slot] = 0;
- GivePlayerWeapon(playerid, weaponid, 1);
- return 1;
- }
- if(sammo > 0 && lammo >= 1){
- w_Info[playerid][w_Ammo][slot] += ammo;
- return 1;
- }else if(ammo > lammo){
- w_Info[playerid][w_Ammo][slot] += ammo - lammo;
- GivePlayerWeapon(playerid, weaponid, lammo);
- return 1;
- }
- GivePlayerWeapon(playerid, weaponid, ammo);
- return 1;
- }
- stock PlayerGetWeapons(playerid, slot){
- for(new i = 0; i < 13; ++i){
- GetPlayerWeaponData(playerid, i, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
- if(w_x_weapon[playerid][i] != 0 && w_x_ammo[playerid][i] == 0){
- RemovePlayerWeaponSlot(playerid, slot);
- return true;
- }
- if(w_x_weapon[playerid][i] != 0 && w_x_ammo[playerid][i] != 0){
- return false;
- }
- }
- return false;
- }
- stock RemovePlayerWeaponSlot(playerid, slot){
- for(new i = 0; i < 13; ++i){
- GetPlayerWeaponData(playerid, i, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
- }
- ResetPlayerWeapons(playerid);
- for(new i = 0; i < 13; ++i){
- if(slot == i) continue;
- GivePlayerWeapon(playerid, w_x_weapon[playerid][i], w_x_ammo[playerid][i]);
- }
- return 1;
- }
- stock SlotsWeapons(armaid){
- new slot;
- switch(armaid){
- case 0..1: slot = 0; // FIST
- case 2..9: slot = 1; // ARMA BRANCA
- case 10..15: slot = 10; // ARMAS SLAOQ
- case 16..18, 39: slot = 8; // EXPLOSIVOS
- case 22..24: slot = 2; // PISTOLAS
- case 25..27: slot = 3; // DOZES
- case 28..29, 32: slot = 4; // SUBS
- case 30..31: slot = 5; // FUZIS
- case 33..34: slot = 6; // SNIPERS
- case 35..38: slot = 7; // BAZUCAS
- case 40: slot = 12; // DETONADOR
- case 41..43: slot = 9; // SLAS
- case 44..46: slot = 11; // VISÃO
- }
- return slot;
- }
- stock Weapon_Ammo_Limit(weaponid){
- new limit = 0;
- switch(weaponid){
- case 16..18, 28, 32, 29..30, 35..37, 39, 40..43: limit = 30;
- case 22: limit = 15;
- case 23: limit = 17;
- case 25: limit = 5;
- case 24, 27: limit = 7;
- case 26: limit = 4;
- case 31: limit = 50;
- case 33, 34: limit = 10;
- case 38: limit = 500;
- default: limit = 1;
- }
- return limit;
- }
- stock Mostrar_wTD(playerid){
- w_Info[playerid][w_TdShow] = true;
- for(new i = 0; i < sizeof(Weapon_InfosTD[]); ++i){
- PlayerTextDrawHide(playerid, Weapon_InfosTD[playerid][i]);
- PlayerTextDrawShow(playerid, Weapon_InfosTD[playerid][i]);
- }
- return 1;
- }
- stock Esconder_wTD(playerid){
- w_Info[playerid][w_TdShow] = false;
- for(new i = 0; i < sizeof(Weapon_InfosTD[]); ++i){
- PlayerTextDrawHide(playerid, Weapon_InfosTD[playerid][i]);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement