Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #if defined _weappick_included
- #endinput
- #endif
- #define _weappick_included
- #define COLOR 0x33ccffff
- #define DRAW_DISTANCE 20.0 //Drawing distance for the 3D text draw.
- #define RANGE 5.4 //The range for the player in which he needs to be to access the pickup
- #define PRIM_INTERVAL 750 //Primary interval for the first check
- #define SEC_INTERVAL 450 //When the player has bought a weapon, reduce the waiting time
- #define ARMOR 0 //Don't touch this
- enum wInfo
- {
- pid,
- weap,
- ammu,
- cost,
- Text3D:label,
- Float:X,
- Float:Y,
- Float:Z,
- bool:created
- }
- new wPick[MAX_PICKUPS][wInfo];
- forward BuyItem(playerid, weappickid);
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(oldkeys & KEY_SECONDARY_ATTACK && !(newkeys & KEY_SECONDARY_ATTACK) && GetPVarInt(playerid, "HID_WeapTimer") != 0)
- {
- KillTimer(GetPVarInt(playerid, "HID_WeapTimer") - 1);
- DeletePVar(playerid, "HID_WeapTimer");
- return 1;
- }
- if(newkeys & KEY_SECONDARY_ATTACK && !(oldkeys & KEY_SECONDARY_ATTACK))
- {
- for(new p; p < MAX_PICKUPS; p++)
- {
- if(!wPick[p][created]) continue;
- if(IsPlayerInRangeOfPoint(playerid, RANGE, wPick[p][X], wPick[p][Y], wPick[p][Z]))
- {
- SetPVarInt(playerid, "HID_WeapTimer", SetTimerEx("BuyItem", PRIM_INTERVAL, 0, "ii", playerid, p) + 1);
- break;
- }
- }
- }
- CallLocalFunction("WEAPHID_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);
- return 1;
- }
- #if defined _ALS_OnPlayerKeyStateChange
- #undef OnPlayerKeyStateChange
- #else
- #define _ALS_OnPlayerKeyStateChange
- #endif
- #define OnPlayerKeyStateChange WEAPHID_OnPlayerKeyStateChange
- forward WEAPHID_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- public BuyItem(playerid, weappickid)
- {
- if(!IsPlayerInRangeOfPoint(playerid, RANGE, wPick[weappickid][X], wPick[weappickid][Y], wPick[weappickid][Z])) return;
- if(GetPlayerMoney(playerid) < wPick[weappickid][cost]) PlayerPlaySound(playerid, 1055, 0, 0, 0);
- else
- {
- new slot = RetrieveWeaponSlotFromWeaponID(wPick[weappickid][weap]);
- new weapon, ammo;
- GetPlayerWeaponData(playerid, slot, weapon, ammo);
- if(IsNonStackingWeapon(weapon) && ammo != 0 && wPick[weappickid][weap] != ARMOR && weapon == wPick[weappickid][weap])
- {
- PlayerPlaySound(playerid, 1055, 0, 0, 0);
- }
- else if(wPick[weappickid][weap] == ARMOR)
- {
- new Float:AP;
- GetPlayerArmour(playerid, AP);
- if(AP >= 100) PlayerPlaySound(playerid, 1055, 0, 0, 0);
- else if(AP + wPick[weappickid][ammu] < 100) SetPlayerArmour(playerid, AP + wPick[weappickid][ammu]);
- else SetPlayerArmour(playerid, 100);
- }
- else
- {
- GivePlayerMoney(playerid, -wPick[weappickid][cost]);
- if(wPick[weappickid][weap] != 0) GivePlayerWeapon(playerid, wPick[weappickid][weap], wPick[weappickid][ammu]);
- else SetPlayerArmour(playerid, 100);
- PlayerPlaySound(playerid, 1054, 0, 0, 0);
- }
- }
- if(!IsNonStackingWeapon(wPick[weappickid][weap]) || wPick[weappickid][weap] == ARMOR) SetPVarInt(playerid, "HID_WeapTimer", SetTimerEx("BuyItem", SEC_INTERVAL, 0, "ii", playerid, weappickid) + 1);
- else DeletePVar(playerid, "HID_WeapTimer");
- }
- stock CreateWeaponPickup(weaponid, ammo, money, Float:x, Float:y, Float:z)
- {
- for(new p; p < MAX_PICKUPS; p++)
- {
- if(wPick[p][created] == false && !IsValidObject(p))
- {
- new string[128];
- GetWeaponName(weaponid, string, sizeof string);
- if(!IsNonStackingWeapon(weaponid) || weaponid == ARMOR) format(string, sizeof string, "%s\n%s: %i\nCost: $%i\nHold F to buy!", string, ((weaponid == ARMOR) ? ("Amount") : ("Ammo")), ammo, money);
- else format(string, sizeof string, "%s\nCost: $%i\nHold F to buy!", string, money);
- wPick[p][pid] = CreatePickup(RetrieveObjectModelFromWeaponID(weaponid), 1, x, y, z);
- wPick[p][weap] = weaponid;
- wPick[p][ammu] = ammo;
- wPick[p][cost] = money;
- wPick[p][label] = Create3DTextLabel(string, COLOR, x, y, z + 0.45, DRAW_DISTANCE, 0, 0);
- wPick[p][X] = x;
- wPick[p][Y] = y;
- wPick[p][Z] = z;
- wPick[p][created] = true;
- return p;
- }
- }
- return 0;
- }
- stock DeleteWeaponPickup(weappickid)
- {
- if(wPick[weappickid][created] == false) return 0;
- DestroyPickup(wPick[weappickid][pid]);
- Delete3DTextLabel(wPick[weappickid][label]);
- wPick[weappickid][created] = false;
- return 1;
- }
- stock SetWeaponPickupWeapon(weappickid, weaponid, ammo)
- {
- if(wPick[weappickid][created] == false) return 0;
- wPick[weappickid][weap] = weaponid;
- wPick[weappickid][ammu] = ammo;
- DestroyPickup(wPick[weappickid][pid]);
- wPick[weappickid][pid] = CreatePickup(RetrieveObjectModelFromWeaponID(weaponid), 1, wPick[weappickid][X], wPick[weappickid][Y], wPick[weappickid][Z]);
- new string[128];
- GetWeaponName(weaponid, string, sizeof string);
- if(!IsNonStackingWeapon(weaponid) || wPick[weappickid][weap] == ARMOR) format(string, sizeof string, "%s\n%s: %i\nCost: $%i\nHold F to buy!", string, ((weaponid == ARMOR) ? ("Amount") : ("Ammo")), ammo, wPick[weappickid][cost]);
- else format(string, sizeof string, "%s\nCost: $%i\nHold F to buy!", string, wPick[weappickid][cost]);
- Update3DTextLabelText(wPick[weappickid][label], COLOR, string);
- return 1;
- }
- stock SetWeaponPickupCost(weappickid, money)
- {
- if(wPick[weappickid][created] == false) return 0;
- wPick[weappickid][cost] = money;
- new string[128];
- GetWeaponName(wPick[weappickid][weap], string, sizeof string);
- if(!IsNonStackingWeapon(wPick[weappickid][weap]) || wPick[weappickid][weap] == ARMOR) format(string, sizeof string, "%s\n%s: %i\nCost: $%i\nHold F to buy!", string, ((wPick[weappickid][weap] == ARMOR) ? ("Amount") : ("Ammo")), wPick[weappickid][ammu], money);
- else format(string, sizeof string, "%s\nCost: $%i\nHold F to buy!", string, money);
- Update3DTextLabelText(wPick[weappickid][label], COLOR, string);
- return 1;
- }
- stock GetWeaponPickupPos(weappickid, &Float:x, &Float:y, &Float:z)
- {
- if(wPick[weappickid][created] == false) return 0;
- x = wPick[weappickid][X];
- y = wPick[weappickid][Y];
- z = wPick[weappickid][Z];
- return 1;
- }
- stock RetrieveObjectModelFromWeaponID(weaponid)
- {
- switch(weaponid)
- {
- case 0: return 373;
- case 1: return 331;
- case 2: return 333;
- case 3: return 334;
- case 4: return 335;
- case 5: return 336;
- case 6: return 337;
- case 7: return 338;
- case 8: return 339;
- case 9: return 341;
- case 10: return 321;
- case 11: return 322;
- case 12: return 323;
- case 13: return 324;
- case 14: return 325;
- case 15: return 326;
- case 16: return 342;
- case 17: return 343;
- case 18: return 344;
- case 22: return 346;
- case 23: return 347;
- case 24: return 348;
- case 25: return 349;
- case 26: return 350;
- case 27: return 351;
- case 28: return 352;
- case 29: return 353;
- case 30: return 355;
- case 31: return 356;
- case 32: return 372;
- case 33: return 357;
- case 34: return 358;
- case 35: return 359;
- case 36: return 360;
- case 37: return 361;
- case 38: return 362;
- case 39: return 363;
- case 40: return 364;
- case 41: return 365;
- case 42: return 366;
- case 43: return 367;
- case 44: return 368;
- case 45: return 369;
- case 46: return 371;
- }
- return 1486;
- }
- stock IsNonStackingWeapon(weaponid)
- {
- switch(weaponid)
- {
- case 0..15, 40, 44..46: return 1;
- default: return 0;
- }
- return 0;
- }
- stock RetrieveWeaponSlotFromWeaponID(weaponid)
- {
- switch(weaponid)
- {
- case 0,1: return 0;
- case 2..9: return 1;
- case 22.24: return 2;
- case 25..27: return 3;
- case 28, 29, 32: return 4;
- case 30, 31: return 5;
- case 33, 34: return 6;
- case 35..38: return 7;
- case 16..18, 39: return 8;
- case 41..43: return 9;
- case 10..15: return 10;
- case 44.46: return 11;
- case 40: return 12;
- }
- return 0;
- }
- /*
- native CreateWeaponPickup(weaponid, ammo, money, Float:x, Float:y, Float:z);
- native DeleteWeaponPickup(weappickid);
- native SetWeaponPickupWeapon(weappickid, weaponid, ammo);
- native SetWeaponPickupCost(weappickid, money);
- native GetWeaponPickupPos(weappickid, &Float:x, &Float:y, &Float:z);
- */
Advertisement
Add Comment
Please, Sign In to add comment