View Single Post
eyal282
Veteran Member
Join Date: Aug 2011
Old 03-21-2017 , 17:18   Re: I need script Infinite Ammo/Clip for vip
Reply With Quote #2

Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <colors>

#define ADMFLAG_NEEDED ADMFLAG_CUSTOM3

#define DATA "2.0"

new Handle:trie_armas;

new Handle:timers[MAXPLAYERS+1];

new ACCOUNT_OFFSET;

public OnPluginStart()
{
	CreateConVar("sm_franugvipfeatures_version", DATA, "", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	CreateConVar("sm_enable_unlimitedammo", "1");
	CreateConVar("sm_enable_unlimitedclip", "1");
	
	trie_armas = CreateTrie();
	
	HookEvent("player_spawn", Event_PlayerSpawn);
	HookEvent("player_spawn", Event_OnPlayerSpawn);
	HookEvent("round_end", RoundEnd);
	HookEvent("weapon_fire", Event_WeaponFire, EventHookMode_Post);
	
	ACCOUNT_OFFSET = FindSendPropOffs("CCSPlayer", "m_iAccount");
	
	for(new i = 1; i <= MaxClients; i++)
		if(IsClientInGame(i))
		{
			OnClientPutInServer(i);
			OnClientPostAdminCheck(i);
		}
}


public Action:Event_WeaponFire(Handle hEvent, const char[] name, bool dontBroadcast))
{
	new client = GetClientOfUserId(GetEventInt(hEvent, "userid")); 
	new weapon = GetEventInt(hEvent, "weaponid");
	if(!(GetUserFlagBits(client) & ADMFLAG_NEEDED)) return;
	
	if(GetConVarInt(FindConVar("sm_enable_unlimitedammo")) == 1) // This is to prevent the VIP from picking up a weapon just to refill it and leave it back. Each bullet fired restores 1 unit of ammunition.
	{
		SetEntProp(weapon, Prop_Data, "m_iAmmo", GetEntProp(weapon, Prop_Data, "m_iAmmo") + 1);
	}
	else if(GetConVarInt(FindConVar("sm_enable_unlimitedclip")) == 1)
	{
		new maxclip;
		if(GetMaxClip1(weapon, maxclip)) // This is in order to block the reload function.
		{
			SetEntProp(weapon, Prop_Data, "m_iClip1", maxclip);
		}
	}
	 
}
public Event_OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new team = GetClientTeam(client);
	new money = GetEntProp(client, Prop_Send, "m_iAccount");
	
	if (client > 0 && IsPlayerAlive(client))
	{
		if ((client))
		{
			PrintToChat(client, "\x01[\x043Mod\x01] Primiti, helm, +5hp, +200$, setat pentru a dezarma, o parasuta si un set de grenade, pentru c? tu e?ti un VIP");
			SetEntityHealth(client, 120);  //hp
			SetEntProp(client, Prop_Send, "m_ArmorValue", 120, 4); //armor
			SetEntProp(client, Prop_Send, "m_bHasHelmet", 1); //helm
			SetEntProp(client, Prop_Send, "m_iAccount", money + 200); //200$ plus
			
			GivePlayerItem(client, "weapon_smokegrenade"); //smoke
			GivePlayerItem(client, "weapon_flashbang"); //flash
			GivePlayerItem(client, "weapon_hegrenade"); //grenade
			GivePlayerItem(client, "weapon_flashbang"); //flash
			
			if(team == CS_TEAM_CT)
			{
				GivePlayerItem(client, "item_defuser"); //kombinerki
			}		
		}
	}
}

public OnClientPutInServer(client)
{
	SDKHook(client, SDKHook_WeaponEquipPost, EventItemPickup2);
}

public OnClientPostAdminCheck(client)
{
	if(GetUserFlagBits(client) & ADMFLAG_NEEDED) timers[client] = CreateTimer(3.0, Darm, client, TIMER_REPEAT);
}

public OnClientDisconnect(client)
{
	if(timers[client] != INVALID_HANDLE)
	{
		KillTimer(timers[client]);
		timers[client] = INVALID_HANDLE;
	}
}

public Action:Darm(Handle:timer, any:client)
{
	if(IsPlayerAlive(client))
	{
		new weapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
		if(weapon > 0 && (weapon == GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY) || weapon == GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY)))
		{
			new warray;
			decl String:classname[4];
			//GetEdictClassname(weapon, classname, sizeof(classname));
			Format(classname, 4, "%i", GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"));
			
			if(GetTrieValue(trie_armas, classname, warray))
			{
				//PrintToChat(client, "municion fijado a %i",warray[1]);
				if(GetReserveAmmo(weapon) != warray) SetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount", warray);
			}
		}
	}
}

stock GetReserveAmmo(weapon)
{
    return GetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount");
}

public Action:EventItemPickup2(client, weapon)
{
	if(weapon == GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY) || weapon == GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY))
	{
		new warray;
		decl String:classname[4];
		//GetEdictClassname(weapon, classname, sizeof(classname));
		Format(classname, 4, "%i", GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"));
	
		if(!GetTrieValue(trie_armas, classname, warray))
		{
			warray = GetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount");
		
			SetTrieValue(trie_armas, classname, warray);
		}
		else
		{
			if(GetUserFlagBits(client) & ADMFLAG_NEEDED) SetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount", warray);
		}
	}
}

public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{	
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	
	if(GetClientTeam(client) < 2) return;
	
	if(!(GetUserFlagBits(client) & ADMFLAG_NEEDED)) return;

	new iEnt;
	
	while ((iEnt = GetPlayerWeaponSlot(client, 3)) != -1)
	{
		RemovePlayerItem(client, iEnt);
		AcceptEntityInput(iEnt, "Kill");
	}
	
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_flashbang");
	GivePlayerItem(client, "weapon_smokegrenade");
	GivePlayerItem(client, "weapon_molotov");
	if(GetClientTeam(client) == CS_TEAM_CT) SetEntProp(client, Prop_Send, "m_bHasDefuser", 1);
	
	while ((iEnt = GetPlayerWeaponSlot(client, 2)) != -1)
	{
		RemovePlayerItem(client, iEnt);
		AcceptEntityInput(iEnt, "Kill");
	}
	GivePlayerItem(client, "weapon_knife");
	GivePlayerItem(client, "weapon_taser");
	
	FakeClientCommand(client,"use weapon_knife");
	
	SetEntData(client, ACCOUNT_OFFSET, GetEntData(client, ACCOUNT_OFFSET)+300);
}

public RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
	if (CheckMapEnd())
	{
		Pasar();
    }
}

Pasar()
{
	for(new i=1;i<=MaxClients;++i)
	{
		if(!IsClientInGame(i) || GetClientTeam(i) > 1) continue;
		
		if(!(GetUserFlagBits(i) & ADMFLAG_NEEDED)) continue;
		
		ChangeClientTeam(i, GetRandomInt(2, 3));

	}
}


bool:CheckMapEnd()
{
	new win = GetConVarInt(FindConVar("mp_maxrounds"));
	
	if(win > 0)
	{
		win = RoundToNearest(win/2.0);
		
		if(GetTeamScore(CS_TEAM_CT) == win || GetTeamScore(CS_TEAM_T) == win) return true;
		
		return false;
	}
		
	new timeleft;
	GetMapTimeLeft(timeleft);
	if (timeleft <= 0) return true;
	
	return false;
}

public OnEntityCreated(entity, const String:clsname[])
{
    if(StrContains(clsname, "weapon_", false) != -1) SDKHookEx(entity, SDKHook_SpawnPost, SpawnPost);
}

public SpawnPost(entity)
{
    GetMaxClip1(entity, _, true); // store m_iClip1 value
}

bool:GetMaxClip1(entity, &clip = -1, bool:store = false)
{
    clip = -1;

    static Handle:trie_ammo = INVALID_HANDLE;

    if(trie_ammo == INVALID_HANDLE) trie_ammo = CreateTrie();

    if(entity <= MaxClients || !IsValidEntity(entity) || FindDataMapInfo(entity, "m_iClip1") == -1) return false;

    new String:clsname[30];
    if(!GetEntityClassname(entity, clsname, sizeof(clsname))) return false;

    if(store)
    {
        SetTrieValue(trie_ammo, clsname, GetEntProp(entity, Prop_Send, "m_iClip1"));
        return true;
    }

    if(!GetTrieValue(trie_ammo, clsname, clip)) return false;

    return true;
}
I'm quite new so I got this thing. Should work.
eyal282 is offline