Raised This Month: $10 Target: $400
 2% 

!wp command once per round


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
combocarte112
Senior Member
Join Date: Jun 2016
Location: Romania
Old 03-12-2021 , 03:28   !wp command once per round
Reply With Quote #1

Hi, I want to be able to use the !wp command once per round, can anyone help me?

Code:
#include <sdktools>
#include <vip_core>

public Plugin myinfo = {name = "VIP_WeaponPack | Комплект оружий", author = "Drumanid", version = "2.0 [ FINAL ? ]", url = "http://vk.com/drumanid | http://hlmod.ru"}

#pragma newdecls required
#pragma semicolon 1

int g_iRounds;
int g_iRound[MAXPLAYERS+1];

int g_iGrenadeOffsets[] = {15, 17, 16, 14, 18, 17};

#define VIP_WEAPONPACK	"Weaponpack"

ConVar c_RoundMenu;
ConVar c_RoundLimit;

Handle kv;
char MenuName[PLATFORM_MAX_PATH];

//======================================================================================================================================================================
// Регистрация
//======================================================================================================================================================================
public void OnPluginStart()
{
	RegConsoleCmd("wp", WeaponMenuCmd);

	
	HookEvent("round_start", RoundStart, EventHookMode_Pre);

	c_RoundMenu = CreateConVar("c_RoundMenu", "0", "1 - Включить / 0 - Выключить | Выводит менюшку в начале раунда для вип игроков");
	c_RoundLimit = CreateConVar("c_RoundLimit", "3", "0 - Можно использовать всегда | Cколько раундов запрещать вип игроку снова использовать WeaponPack");	
	
	if(VIP_IsVIPLoaded())
	{
		VIP_OnVIPLoaded();
	}
	
	kv = CreateKeyValues("WeaponPack");
	if(FileToKeyValues(kv, "addons/sourcemod/data/vip/modules/WeaponPack.ini"))
	{
		
	}
	else
	{
		PrintToServer("No found: addons/sourcemod/data/vip/modules/WeaponPack.ini");
		LogError("No found: addons/sourcemod/data/vip/modules/WeaponPack.ini");
	}
	
	AutoExecConfig(true, "VIP_WeaponPack", "vip");
}

//======================================================================================================================================================================
// Выдаем меню "Хотите ли" в начале каждого раунда вип игроку
//======================================================================================================================================================================
public Action RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
	if(GetConVarInt(c_RoundMenu) == 1)
	{
		for(int i = 1; i <= MaxClients; i++)
		{
			if(IsClientInGame(i))
			{
				if(VIP_IsClientVIP(i) && VIP_IsClientFeatureUse(i, VIP_WEAPONPACK))
				{
					RoundMenu(i);
				}
			}
		}
	}
}

public void RoundMenu(int client)
{
	char map[PLATFORM_MAX_PATH];
	GetCurrentMap(map, sizeof(map));
 
	if((strncmp(map, "35hp_", 5) == 0) || (strncmp(map, "awp_", 4) == 0))
	{
		return;
	}
	else
	{
		if(GameRules_GetProp("m_bWarmupPeriod") == 1)
		{
			return;
		}
		else
		{
			g_iRounds = GetRound();
			if(g_iRounds < 2)
			{
				return;
			}
		}
    
		if(IsPlayerAlive(client))
		{
			if(g_iRound[client] > g_iRounds)
			{
				PrintToChat(client, " \x07Комплект оружия будет доступен через: \x04%i\x07 раунд(а)!", g_iRound[client] - g_iRounds);
				return;
			}
			else
			{
				Panel hPanel = new Panel();
				hPanel.SetTitle( "Хотите ли воспользоваться WeaponPack?\n \n");
				hPanel.DrawItem("Да");
				hPanel.DrawItem("Нет");

				hPanel.Send(client, SelectMenu, 0);
				delete hPanel;
			}
		}
	}
}

public int SelectMenu(Menu hPanel, MenuAction action, int client, int option)
{
    if(action == MenuAction_Select && option == 1)
    {
        WeaponMenu(client);
    }
}

//======================================================================================================================================================================
// Обнуляем данные отыгранных раундов
//======================================================================================================================================================================
public void OnMapStart()
{
	g_iRounds = 0;
}

public void OnClientPostAdminCheck(int client)
{
	g_iRound[client] = 0;
}

//======================================================================================================================================================================
// Регистрируем модуль в вип системе
//======================================================================================================================================================================
public void VIP_OnVIPLoaded()
{
	VIP_RegisterFeature(VIP_WEAPONPACK, BOOL, SELECTABLE, OnSelectItem);
}

public bool OnSelectItem(int client, const char[] sFeatureName)
{
	WeaponMenu(client);
	return;
}

//======================================================================================================================================================================
// Проверка и выполнение команды !wp
//======================================================================================================================================================================
public Action WeaponMenuCmd(int client, int args)
{
	if(client > 0 && args < 1 && VIP_IsClientVIP(client) && VIP_IsClientFeatureUse(client, VIP_WEAPONPACK))
	{
		WeaponMenu(client);
	}
	return Plugin_Handled;
}

//======================================================================================================================================================================
// Сама менюшка
//======================================================================================================================================================================
public void WeaponMenu(int client)
{
	char map[PLATFORM_MAX_PATH];
	GetCurrentMap(map, sizeof(map));
 
	if((strncmp(map, "35hp_", 5) == 0) || (strncmp(map, "awp_", 4) == 0))
	{
		PrintToChat(client, " \x07You can't take a gun from menu on this map!");
		ClientCommand(client,"play buttons/weapon_cant_buy.wav");
		return;
	}
	else
	{
		if(GameRules_GetProp("m_bWarmupPeriod") == 1)
		{
			PrintToChat(client, " \x07You can't take a pistol from menu in warmup time!");
			ClientCommand(client,"play buttons/weapon_cant_buy.wav");
			return;
		}
		else
		{
			g_iRounds = GetRound();
			if(g_iRounds < 2)
			{
				PrintToChat(client, " \x07You can't take weapons from menu in the first round");
				ClientCommand(client,"play buttons/weapon_cant_buy.wav");
				return;
			}
		}
    
		if(IsPlayerAlive(client))
		{
			if(g_iRound[client] > g_iRounds)
			{
			
				ClientCommand(client,"play buttons/weapon_cant_buy.wav");
				return;
			}
			else
			{
				Handle menu = CreateMenu(SelectWeapon);
				SetMenuTitle(menu, "Gun Menu ^_^");
				
				KvRewind(kv);
				if(KvGotoFirstSubKey(kv))
				{
					do
					{
						if(KvGetSectionName(kv, MenuName, sizeof(MenuName)))
						{
							if(GetClientTeam(client) == KvGetNum(kv, "Team", 0) || KvGetNum(kv, "Team", 0) == 0)
							{
								AddMenuItem(menu, MenuName, MenuName);
							}
						}
					}
					while(KvGotoNextKey(kv));
				}
				SetMenuExitButton(menu, true);
				DisplayMenu(menu, client, 0);
			}
		}
		else
		{
			PrintToChat(client, " \x07You have to be alive to take gun from menu!");
			ClientCommand(client,"play buttons/weapon_cant_buy.wav");
		}
	}
}

//======================================================================================================================================================================
// Выполняем пункты в меню
//======================================================================================================================================================================
public int SelectWeapon(Handle menu, MenuAction action, int client, int option)
{
	switch(action)
	{
		case MenuAction_End:
		{
			CloseHandle(menu);
		}
		case MenuAction_Select:
		{
			GetMenuItem(menu, option, MenuName, sizeof(MenuName));

			KvRewind(kv);
			if(KvJumpToKey(kv, MenuName, false))
			{
				char sBuffer[64];
				if(KvGotoFirstSubKey(kv, false))
				{
					WeaponDelete(client);
					
					g_iRound[client] = g_iRounds + GetConVarInt(c_RoundLimit);
					do
					{
						KvGetSectionName(kv, sBuffer, sizeof(sBuffer));
						if(!StrEqual(sBuffer, "weapon"))
						{
							continue;
						}
						KvGetString(kv, NULL_STRING, sBuffer, sizeof(sBuffer));
						GivePlayerItem(client, sBuffer);
					}
					while(KvGotoNextKey(kv, false));
				}
			}
		}
	}
}

//======================================================================================================================================================================
// Удаляем и выдаем оружие...
//======================================================================================================================================================================
public void WeaponDelete(int client)
{
	for (int i = 0; i < 4; ++i)
	{
		if (i == 3)
		{
			RemoveNades(client);
		}
		else
		{
			RemoveWeaponBySlot(client, i);
		}
	}
}

stock void RemoveNades(int client)
{
	while (RemoveWeaponBySlot(client, 3))
	{
		for (int i = 0; i < 6; i++)
		{
			SetEntProp(client, Prop_Send, "m_iAmmo", 0, _, g_iGrenadeOffsets[i]);
		}
	}
}

stock bool RemoveWeaponBySlot(int client, int slot)
{
	int entity = GetPlayerWeaponSlot(client, slot);
	if(IsValidEdict(entity))
	{
		RemovePlayerItem(client, entity);
		AcceptEntityInput(entity, "Kill");
		return true;
	}
	
	return false;
}

//======================================================================================================================================================================
// Проверяем раунды
//======================================================================================================================================================================
stock int GetRound()
{
	static ConVar mp_halftime, mp_maxrounds;
	if(!mp_halftime)
	{
		mp_halftime = FindConVar("mp_halftime");
		mp_maxrounds = FindConVar("mp_maxrounds");
	}
		
	int total_score = GetTeamScore(2) + GetTeamScore(3) + 1;
	if (mp_halftime.IntValue == 1)
	{
		int halftimer = mp_maxrounds.IntValue/2;
		if(halftimer < total_score) return total_score - mp_maxrounds.IntValue/2;
	}
	return total_score;
}

//======================================================================================================================================================================
// Выгружаем модуль
//======================================================================================================================================================================
public void OnPluginEnd()
{
	if(CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "VIP_WEAPONPACK") == FeatureStatus_Available)
    {
		VIP_UnregisterFeature(VIP_WEAPONPACK);
	}
}

Last edited by combocarte112; 03-12-2021 at 03:29.
combocarte112 is offline
Send a message via Skype™ to combocarte112
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:48.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode