Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #pragma newdecls required
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- int g_iAmmo[2048 + 1][10];
- static const int g_iAmmoLimits[] =
- {
- 210,
- 330,
- 332,
- 210,
- 50,
- 48,
- 125,
- 180,
- 48,
- 50,
- 90,
- 150,
- 100,
- 45,
- 210,
- 190,
- 8
- };
- static const char gWeapons[][] =
- {
- "weapon_rifle",
- "weapon_smg_mp5",
- "weapon_smg",
- "weapon_smg_silenced",
- "weapon_shotgun_chrome",
- "weapon_pumpshotgun",
- "weapon_hunting_rifle",
- "weapon_rifle_m60",
- "weapon_autoshotgun",
- "weapon_shotgun_spas",
- "weapon_sniper_military",
- "weapon_rifle_ak47",
- "weapon_rifle_desert",
- "weapon_sniper_awp",
- "weapon_rifle_sg552",
- "weapon_sniper_scout",
- "weapon_grenade_launcher"
- };
- public void OnPluginStart()
- {
- HookEvent("upgrade_pack_used", eEvent);
- }
- public void eEvent(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("userid"));
- if (!client || !IsClientInGame(client))
- return;
- int iEntity = event.GetInt("upgradeid");
- if (!IsValidEntity(iEntity))
- return;
- float vOrigin[3], vAngles[3]; vAngles[0] = 89.0;
- int iTarget;
- bool bSwitch;
- GetClientAbsOrigin(client,vOrigin);
- int iAmmo = CreateEntityByName("weapon_ammo_spawn");
- DispatchSpawn(iAmmo);
- DispatchKeyValueVector(iAmmo, "origin", vOrigin);
- AcceptEntityInput(iEntity, "kill");
- g_iAmmo[iAmmo][1] = 600;
- g_iAmmo[iAmmo][2] = 360;
- g_iAmmo[iAmmo][3] = 160;
- g_iAmmo[iAmmo][4] = 80;
- g_iAmmo[iAmmo][5] = 84;
- g_iAmmo[iAmmo][6] = 84;
- g_iAmmo[iAmmo][7] = 240;
- g_iAmmo[iAmmo][8] = 16;
- g_iAmmo[iAmmo][9] = 360;
- Handle hRayTrace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceFilter, iAmmo);
- if(TR_DidHit(hRayTrace))
- {
- TR_GetEndPosition(vOrigin, hRayTrace);
- iTarget = TR_GetEntityIndex(hRayTrace);
- }
- char szClass2[36];
- GetEntityClassname(iTarget, szClass2, sizeof szClass2);
- if (IsValidEntity(iTarget) && iTarget > MaxClients)
- {
- char szClass[36];
- GetEntityClassname(iTarget, szClass, sizeof szClass);
- if (strcmp(szClass, "func_elevator") == 0 || strcmp(szClass, "func_tracktrain") == 0)
- bSwitch = true;
- }
- delete hRayTrace;
- if (bSwitch)
- {
- SetVariantString("!activator");
- AcceptEntityInput(iAmmo, "SetParent", iTarget);
- }
- }
- public bool TraceFilter(int entity, int contentsMask, int iEntity)
- {
- if (entity > MaxClients && entity != iEntity)
- return true;
- return false;
- }
- public void OnEntityCreated(int entity, const char[] clsname)
- {
- if (!IsValidEntity(entity) || strcmp(clsname, "weapon_ammo_spawn") != 0)
- return;
- g_iAmmo[entity][1] = GetRandomInt(0, 600);
- g_iAmmo[entity][2] = GetRandomInt(0, 360);
- g_iAmmo[entity][3] = GetRandomInt(0, 160);
- g_iAmmo[entity][4] = GetRandomInt(0, 80);
- g_iAmmo[entity][5] = GetRandomInt(0, 84);
- g_iAmmo[entity][6] = GetRandomInt(0, 84);
- g_iAmmo[entity][7] = GetRandomInt(0, 240);
- g_iAmmo[entity][8] = GetRandomInt(0, 16);
- g_iAmmo[entity][9] = GetRandomInt(0, 360);
- SDKHook(entity, SDKHook_Use, OnPlayerUse);
- }
- public Action OnPlayerUse(int iTarget, int client, int caller, UseType type, float value)
- {
- if (!client || !IsClientInGame(client))
- return;
- if (!IsValidEntity(iTarget))
- return;
- int iAmmoSave[2];
- iSaveAmmo(client, iAmmoSave);
- char szBuffer[36];
- GetEntityClassname(iTarget, szBuffer, sizeof szBuffer);
- if (strcmp(szBuffer, "weapon_ammo_spawn") != 0)
- return;
- int iWeapon = GetPlayerWeaponSlot(client, 0);
- if (!IsValidEntity(iWeapon))
- return;
- int iBits = iBitsWeapon(iWeapon);
- int iMaxAmmo = iAmmoBits(iWeapon);
- int iBitsType = GetEntProp(iWeapon, Prop_Data, "m_iPrimaryAmmoType");
- if (iBitsType == INVALID_ENT_REFERENCE || iBits <= 0)
- return;
- if (iMaxAmmo == GetEntProp(iWeapon, Prop_Send, "m_iClip1") + GetEntProp(client, Prop_Send, "m_iAmmo", _, iBitsType))
- {
- PrintHintText(client, "Нельзя унести больше.");
- return;
- }
- if (g_iAmmo[iTarget][iBits] > 0)
- {
- int iResult = iMaxAmmo - (GetEntProp(iWeapon, Prop_Send, "m_iClip1") + GetEntProp(client, Prop_Send, "m_iAmmo", _, iBitsType));
- g_iAmmo[iTarget][iBits] -= iResult;
- int iTotal = GetEntProp(client, Prop_Send, "m_iAmmo", _, iBitsType) + iResult;
- SetEntProp(client, Prop_Send, "m_iAmmo", iTotal, _, iBitsType);
- if (g_iAmmo[iTarget][iBits] < 0)
- {
- int iDelete = iTotal + g_iAmmo[iTarget][iBits];
- SetEntProp(client, Prop_Send, "m_iAmmo", iDelete, _, iBitsType);
- DataPack dPack;
- CreateDataTimer(0.01, tFix, dPack, TIMER_DATA_HNDL_CLOSE);
- dPack.WriteCell(GetClientUserId(client));
- dPack.WriteCell(iDelete);
- dPack.WriteCell(iBitsType);
- PrintHintText(client, "Последние.");
- g_iAmmo[iTarget][iBits] = 0;
- }
- else
- PrintHintText(client, "Подобрано патронов %i, осталось %i", iResult, g_iAmmo[iTarget][iBits]);
- }
- else
- {
- DataPack dPack;
- CreateDataTimer(0.01, tReset, dPack, TIMER_DATA_HNDL_CLOSE);
- dPack.WriteCell(GetClientUserId(client));
- dPack.WriteCell(EntIndexToEntRef(iWeapon));
- dPack.WriteCell(iAmmoSave[0]);
- dPack.WriteCell(iAmmoSave[1]);
- PrintHintText(client, "Нет патронов вашего калибра.");
- }
- }
- public Action tFix (Handle timer, DataPack dPack)
- {
- dPack.Reset();
- int client = GetClientOfUserId(dPack.ReadCell());
- int iTotal = dPack.ReadCell();
- int iBitsType = dPack.ReadCell();
- if (client > 0 && client <= MaxClients && IsClientInGame(client))
- {
- SetEntProp(client, Prop_Send, "m_iAmmo", iTotal, _, iBitsType);
- }
- }
- public Action tReset (Handle timer, DataPack dPack)
- {
- dPack.Reset();
- int client = GetClientOfUserId(dPack.ReadCell());
- int iWeapon = EntRefToEntIndex(dPack.ReadCell());
- int iAmmo = dPack.ReadCell();
- int iClip = dPack.ReadCell();
- if (!IsValidEntity(iWeapon) || client <= 0 || client > MaxClients || !IsClientInGame(client))
- return;
- iResetAmmo(client, iAmmo, iClip, iWeapon);
- }
- void iResetAmmo(int client, int iAmmo, int iClip, int iWeapon)
- {
- int iBits;
- if(IsValidEntity(iWeapon))
- {
- iBits = GetEntProp(iWeapon, Prop_Data, "m_iPrimaryAmmoType");
- if (iBits <= 0)
- return;
- SetEntProp(client, Prop_Send, "m_iAmmo", iAmmo, _, iBits);
- SetEntProp(iWeapon, Prop_Send, "m_iClip1", iClip);
- }
- }
- stock void iSaveAmmo (int client, int array[2])
- {
- int iWeapon = GetPlayerWeaponSlot(client, 0);
- int iBits, iAmmo, iClip;
- if(IsValidEntity(iWeapon))
- {
- iBits = GetEntProp(iWeapon, Prop_Data, "m_iPrimaryAmmoType");
- if (iBits <= 0)
- return;
- iAmmo = GetEntProp(client, Prop_Send, "m_iAmmo", _, iBits);
- iClip = GetEntProp(iWeapon, Prop_Send, "m_iClip1");
- array[0] = iAmmo;
- array[1] = iClip;
- }
- }
- stock int iBitsWeapon (int iWeapon)
- {
- char szBuffer[36];
- GetEntityClassname(iWeapon, szBuffer, sizeof szBuffer);
- if (strcmp(szBuffer, "weapon_smg_silenced") == 0)
- return 9;
- else if (StrContains(szBuffer, "weapon_smg") != -1)
- return 1;
- else if (strcmp(szBuffer, "weapon_rifle") == 0 || strcmp(szBuffer, "weapon_rifle_sg552") == 0 || strcmp(szBuffer, "weapon_sniper_scout") == 0)
- return 2;
- else if (strcmp(szBuffer, "weapon_rifle_desert") == 0 || strcmp(szBuffer, "weapon_sniper_military") == 0 || strcmp(szBuffer, "weapon_rifle_m60") == 0)
- return 3;
- else if (strcmp(szBuffer, "weapon_sniper_awp") == 0)
- return 4;
- else if (strcmp(szBuffer, "weapon_pumpshotgun") == 0 || strcmp(szBuffer, "weapon_autoshotgun") == 0)
- return 5;
- else if (strcmp(szBuffer, "weapon_shotgun_chrome") == 0 || strcmp(szBuffer, "weapon_shotgun_spas") == 0)
- return 6;
- else if (strcmp(szBuffer, "weapon_hunting_rifle") == 0 || strcmp(szBuffer, "weapon_rifle_ak47") == 0)
- return 7;
- else if (strcmp(szBuffer, "weapon_grenade_launcher") == 0)
- return 8;
- return INVALID_ENT_REFERENCE;
- }
- stock int iAmmoBits (int iWeapon)
- {
- char szBuffer[36];
- GetEntityClassname(iWeapon, szBuffer, sizeof szBuffer);
- for (int i; i < sizeof g_iAmmoLimits; i++)
- if (strcmp(szBuffer, gWeapons[i]) == 0)
- return g_iAmmoLimits[i];
- return INVALID_ENT_REFERENCE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement