Raised This Month: $32 Target: $400
 8% 

Detect players weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nezo96
Junior Member
Join Date: May 2018
Old 05-12-2018 , 12:05   Detect players weapon
Reply With Quote #1

Hello.

(i am noob)

So i am trying to made plugin which will give you weapon if you write !vipmenu.

It work but i have question:

1. How to detect if player have weapon in slot or no because when you have weapon in your weapon slot and you write !vipmenu it will give another weapon to player, so he will have 2x AK-47 insteed of 1.

2. How to connect this GivePlayerItem with display menu.

3. Why it say (decl Float:clients[3];): warning 203: symbol is never used: "clients"


Thank you for help
############################################# ##########

1.

Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "0.1"

public Plugin:myinfo = 
{
	name = "New Plugin",
	author = "Unknown",
	description = "<- Description ->",
	version = "0.1",
	url = "<- URL ->"
}

public OnPluginStart()
{
	RegConsoleCmd("vipmenu", VipMenu);
}

public Action:VipMenu(int client, int args)
{
	decl Float:clients[3];
	GivePlayerItem(client, "weapon_ak47");
	return Plugin_Handled;
}
and vipmenu

Code:
public Action VipMenu(int client, int args)
{
	Menu menu = new Menu(MenuHandler1);
	menu.SetTitle("Select weapon:");
	menu.AddItem("ak-47", "AK-47");
	menu.AddItem("ma41", "M4A1");
	menu.AddItem("ma41-s", "M4A1-S");
	menu.AddItem("awp", "AWP");
	menu.ExitButton = false;
	menu.Display(client, 20);
 
	return Plugin_Handled;
}
Nezo96 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 05-12-2018 , 12:13   Re: Detect players weapon
Reply With Quote #2

1. you can use GetPlayerWeaponSlot to check if player have weapon at corresponding slot
2. https://wiki.alliedmods.net/Menus_St...eMod_Scripting)
3. its just a warning telling you you have a variable not used
you can just remove decl Float:clients[3]; if you are not going to use it
__________________
8guawong is offline
Nezo96
Junior Member
Join Date: May 2018
Old 05-12-2018 , 12:22   Re: Detect players weapon
Reply With Quote #3

Yes i was thinking about GetPlayerWeaponSlot but i do not know how to do it or better say what to write GetPlayerWeaponSlot(int client, int slot) what to write in slot.
Nezo96 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 05-12-2018 , 12:42   Re: Detect players weapon
Reply With Quote #4

Quote:
Originally Posted by Nezo96 View Post
Yes i was thinking about GetPlayerWeaponSlot but i do not know how to do it or better say what to write GetPlayerWeaponSlot(int client, int slot) what to write in slot.
primary weapon = slot 0
secondary waepon = slot 1
knife = slot 3

i THINK if i remember correctly
__________________
8guawong is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 05-12-2018 , 12:48   Re: Detect players weapon
Reply With Quote #5

Quote:
Originally Posted by 8guawong View Post
primary weapon = slot 0
secondary waepon = slot 1
knife = slot 3

i THINK if i remember correctly
https://github.com/alliedmodders/sou...ke.inc#L43-L47

PHP Code:
#define CS_SLOT_PRIMARY        0    /**< Primary weapon slot. */
#define CS_SLOT_SECONDARY    1    /**< Secondary weapon slot. */
#define CS_SLOT_KNIFE        2    /**< Knife slot. */
#define CS_SLOT_GRENADE        3    /**< Grenade slot (will only return one grenade). */
#define CS_SLOT_C4            4    /**< C4 slot. */ 
__________________
coding & free software
shanapu is offline
Nezo96
Junior Member
Join Date: May 2018
Old 05-12-2018 , 13:03   Re: Detect players weapon
Reply With Quote #6

Okay now i have this error and i do not know why? (145) : error 100: function prototypes do not match

But
Code:
Menu menu = new Menu(MenuHandler1, MENU_ACTIONS_ALL);
is same as
Code:
public int MenuHandler1(int client, Menu menu, MenuAction action, int param1, int param2)
Code:

Code:
/* Plugin Template generated by Pawn Studio */

#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define weaponAK "#AK-47"
#define weaponM4A1 "#M4A1"
#define weaponM4AS "#M4A1S"
#define weaponAWP "#AWP"

public Plugin:myinfo = 
{
	name = "New Plugin",
	author = "Unknown",
	description = "<- Description ->",
	version = "1.0",
	url = "<- URL ->"
}

public OnPluginStart()
{
	RegConsoleCmd("vipmenu", VipMenu);
}

public int MenuHandler1(int client, Menu menu, MenuAction action, int param1, int param2)
{
	switch(action)
	{
		case MenuAction_Display:
		{
			char buffer[255];
			Format (buffer, sizeof(buffer), "%T", "Vote next");
			
			Panel panel = view_as<Panel>(param2);
			panel.SetTitle(buffer);
			PrintToServer("Client %d was sent menu with panel %x", param1, param2);
		}
		
		case MenuAction_Select:
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
			if (StrEqual(info, weaponAK)) 
			{
				GivePlayerItem(client, "weapon_ak47");
				PrintToServer("Client %d selected", param1, info)
			}
			else if (StrEqual(info, weaponM4A1)) 
			{
				GivePlayerItem(client, "weapon_m4a1");
				PrintToServer("Client %d selected", param1, info)
			}
			else if (StrEqual(info, weaponM4AS))
			{
				GivePlayerItem(client, "weapon_m4a1_silencer");
				PrintToServer("Client %d selected", param1, info)
			}
			else if (StrEqual(info, weaponAWP))
			{
				GivePlayerItem(client, "weapon_awp");
				PrintToServer("Client %d selected", param1, info)
			}
			else
			{
				return Plugin_Handled;
			}
		}
		
		case MenuAction_Cancel:
		{
			PrintToServer("Client %d's menu was canceled for reason: %d", param1, param2);
		}
		
		case MenuAction_End:
		{
			delete menu;
		}
		
		case MenuAction_DrawItem:
		{
			int style;
			char info[32];
			menu.GetItem(param2, info, sizeof(info), style);
			if (StrEqual(info, weaponAK))
			{
				return ITEMDRAW_DISABLED;
			}
			else if (StrEqual(info, weaponM4A1))
			{
				return ITEMDRAW_DISABLED;
			}
			else if (StrEqual(info, weaponM4A1))
			{
				return ITEMDRAW_DISABLED;
			}
			else if (StrEqual(info, weaponM4AS))
			{
				return ITEMDRAW_DISABLED;
			}
			else if (StrEqual(info, weaponAWP))
			{
				return ITEMDRAW_DISABLED;
			}
			else
			{
				return style;
			}
		}
		
		case MenuAction_DisplayItem:
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
			
			char display[64];
			
			if (StrEqual(info, weaponAK))
			{
				Format(display, sizeof(display), "%T", "Choice 1", param1);
				return RedrawMenuItem(display);
			}
			else if (StrEqual(info, weaponM4A1))
			{
				Format(display, sizeof(display), "%T", "Choice 2", param1);
				return RedrawMenuItem(display);
			}
			else if (StrEqual(info, weaponM4AS))
			{
				Format(display, sizeof(display), "%T", "Choice 3", param1);
				return RedrawMenuItem(display);
			}
			else if (StrEqual(info, weaponAWP))
			{
				Format(display, sizeof(display), "%T", "Choice 4", param1);
				return RedrawMenuItem(display);
			}
		}
	}
	return 0;
}

public Action VipMenu(int client, int args)
{
	Menu menu = new Menu(MenuHandler1, MENU_ACTIONS_ALL);
	menu.SetTitle("%T", "Weapon Menu", LANG_SERVER);
	menu.AddItem(weaponAK, "AK-47");
	menu.AddItem(weaponM4A1, "M4A1");
	menu.AddItem(weaponM4AS, "M4A1S");
	menu.AddItem(weaponAWP, "AWP");
	menu.ExitButton = true;
	menu.Display(client, 20);
 
	return Plugin_Handled;
}
Nezo96 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 05-12-2018 , 18:34   Re: Detect players weapon
Reply With Quote #7

public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
__________________
8guawong is offline
Nezo96
Junior Member
Join Date: May 2018
Old 05-13-2018 , 09:45   Re: Detect players weapon
Reply With Quote #8

Okay i tried something else:

Can you tell me why is this not working? I mean there is no error with compiler but it is not working.

When i try sm_vip_version to console it say: Unknown command: sm_vip_version


Code:
/* Plugin Template generated by Pawn Studio */

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

#define VERSION "0.1"

public Plugin:myinfo = 
{
	name = "New Plugin",
	author = "Nezo",
	description = "New Plugin",
	version = "0.1",
	url = "<- URL ->"
}

new Handle:g_hVersion, Handle:g_hCvar[21], g_iCvar[20], String:g_szFlags[AdminFlags_TOTAL + 1], g_iPlayerRounds[MAXPLAYERS + 1];
new bool:g_bIsVip[MAXPLAYERS + 1];

public OnPluginStart()
{
	g_hVersion = CreateConVar("sm_vip_version", VERSION, "VIP VERSION", FCVAR_NONE|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
	SetConVarString(g_hVersion, VERSION);
	
	g_hCvar[0] = CreateConVar("vip_weapons_menu", "3", "Menu after laps: 0:nedostatok", FCVAR_NONE, true, 3.0);
	g_hCvar[1] = CreateConVar("vip_give_equipment", "1", "Give weapon: 0:nedostatok", FCVAR_NONE, true, 0.0, true, 1.0);
	g_hCvar[2] = CreateConVar("vip_set_health", "100", "Health set: 0:štandardné");
	g_hCvar[3] = CreateConVar("vip_set_armor", "100", "Armor set: 0:nedostatok");
	g_hCvar[4] = CreateConVar("vip_give_money", "100", "Money set: 0:nedostatok");
}

public OnMapStart()
{
	g_iCvar[0] = GetConVarInt(g_hCvar[0]);
	g_iCvar[1] = GetConVarBool(g_hCvar[1]);
	g_iCvar[2] = GetConVarInt(g_hCvar[2]);
	g_iCvar[3] = GetConVarInt(g_hCvar[3]);
	g_iCvar[4] = GetConVarInt(g_hCvar[4]);
	GetConVarString(g_hCvar[18], g_szFlags, sizeof g_szFlags);
}

public Action:OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(IsPlayerAlive(client)) {
		if(g_iCvar[1]) CreateTimer(0.1, GiveEquipment, client);
		if(g_iCvar[0]) {
			g_iPlayerRounds[client]++;
			
			if(g_iPlayerRounds[client] >= g_iCvar[3])
				CreateTimer(0.2, WeaponsMenu, client);
		}
	}
}

public Action:GiveEquipment(Handle:timer, any:client) {
	if(GetClientTeam(client) == CS_TEAM_CT) GivePlayerItem(client, "item_defuser");
	GivePlayerItem(client, "weapon_flashbang");
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_smokegrenade");
	GivePlayerItem(client, "weapon_molotov");

	if(g_iCvar[3]) {
		SetEntProp(client, Prop_Data, "m_ArmorValue", g_iCvar[3]);
		SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
	}
	if(g_iCvar[4]) SetEntProp(client, Prop_Send, "m_iAccount", GetEntProp(client, Prop_Send, "m_iAccount") + g_iCvar[4]);
	PrintToChat(client, "\x04[VIP]\x01 Free nades.");
}

public Action:WeaponsMenu(Handle:timer, any:client) {
	new Handle:hMenu = CreateMenu(WeaponsMenuHandler, MenuAction_Display|MenuAction_Select|MenuAction_Cancel);

	AddMenuItem(hMenu, "weapon_m4a1", "M4A1 + Deagle");
	AddMenuItem(hMenu, "weapon_m4a1_silencer", "M4A1S + Deagle");
	AddMenuItem(hMenu, "weapon_ak47", "AK47 + Deagle");
	AddMenuItem(hMenu, "weapon_awp", "AWP + Deagle");

	SetMenuTitle(hMenu, "[VIP] Weapons");
	SetMenuExitButton(hMenu, true);
	SetMenuExitBackButton(hMenu, false);
}

public WeaponsMenuHandler(Handle:hMenu, MenuAction:action, client, item) {
	if(action != MenuAction_Select || !g_bIsVip[client] || g_iPlayerRounds[client] < g_iCvar[3] || !IsPlayerAlive(client)) return;

	decl String:szInfo[32];
	if(!GetMenuItem(hMenu, item, szInfo, sizeof szInfo)) return;

	new i, iWeapon;
	for(; i <= CS_SLOT_SECONDARY; i++) {
		if((iWeapon = GetPlayerWeaponSlot(client, i)) != -1) {
			RemovePlayerItem(client, iWeapon);
			RemoveEdict(iWeapon);
		}
	}
	GivePlayerItem(client, szInfo);
	GivePlayerItem(client, "weapon_deagle");
}
Nezo96 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 05-13-2018 , 11:22   Re: Detect players weapon
Reply With Quote #9

Quote:
Originally Posted by Nezo96 View Post
Okay i tried something else:

Can you tell me why is this not working? I mean there is no error with compiler but it is not working.

When i try sm_vip_version to console it say: Unknown command: sm_vip_version


Code:
/* Plugin Template generated by Pawn Studio */

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

#define VERSION "0.1"

public Plugin:myinfo = 
{
	name = "New Plugin",
	author = "Nezo",
	description = "New Plugin",
	version = "0.1",
	url = "<- URL ->"
}

new Handle:g_hVersion, Handle:g_hCvar[21], g_iCvar[20], String:g_szFlags[AdminFlags_TOTAL + 1], g_iPlayerRounds[MAXPLAYERS + 1];
new bool:g_bIsVip[MAXPLAYERS + 1];

public OnPluginStart()
{
	g_hVersion = CreateConVar("sm_vip_version", VERSION, "VIP VERSION", FCVAR_NONE|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
	SetConVarString(g_hVersion, VERSION);
	
	g_hCvar[0] = CreateConVar("vip_weapons_menu", "3", "Menu after laps: 0:nedostatok", FCVAR_NONE, true, 3.0);
	g_hCvar[1] = CreateConVar("vip_give_equipment", "1", "Give weapon: 0:nedostatok", FCVAR_NONE, true, 0.0, true, 1.0);
	g_hCvar[2] = CreateConVar("vip_set_health", "100", "Health set: 0:štandardné");
	g_hCvar[3] = CreateConVar("vip_set_armor", "100", "Armor set: 0:nedostatok");
	g_hCvar[4] = CreateConVar("vip_give_money", "100", "Money set: 0:nedostatok");
}

public OnMapStart()
{
	g_iCvar[0] = GetConVarInt(g_hCvar[0]);
	g_iCvar[1] = GetConVarBool(g_hCvar[1]);
	g_iCvar[2] = GetConVarInt(g_hCvar[2]);
	g_iCvar[3] = GetConVarInt(g_hCvar[3]);
	g_iCvar[4] = GetConVarInt(g_hCvar[4]);
	GetConVarString(g_hCvar[18], g_szFlags, sizeof g_szFlags);
}

public Action:OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(IsPlayerAlive(client)) {
		if(g_iCvar[1]) CreateTimer(0.1, GiveEquipment, client);
		if(g_iCvar[0]) {
			g_iPlayerRounds[client]++;
			
			if(g_iPlayerRounds[client] >= g_iCvar[3])
				CreateTimer(0.2, WeaponsMenu, client);
		}
	}
}

public Action:GiveEquipment(Handle:timer, any:client) {
	if(GetClientTeam(client) == CS_TEAM_CT) GivePlayerItem(client, "item_defuser");
	GivePlayerItem(client, "weapon_flashbang");
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_smokegrenade");
	GivePlayerItem(client, "weapon_molotov");

	if(g_iCvar[3]) {
		SetEntProp(client, Prop_Data, "m_ArmorValue", g_iCvar[3]);
		SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
	}
	if(g_iCvar[4]) SetEntProp(client, Prop_Send, "m_iAccount", GetEntProp(client, Prop_Send, "m_iAccount") + g_iCvar[4]);
	PrintToChat(client, "\x04[VIP]\x01 Free nades.");
}

public Action:WeaponsMenu(Handle:timer, any:client) {
	new Handle:hMenu = CreateMenu(WeaponsMenuHandler, MenuAction_Display|MenuAction_Select|MenuAction_Cancel);

	AddMenuItem(hMenu, "weapon_m4a1", "M4A1 + Deagle");
	AddMenuItem(hMenu, "weapon_m4a1_silencer", "M4A1S + Deagle");
	AddMenuItem(hMenu, "weapon_ak47", "AK47 + Deagle");
	AddMenuItem(hMenu, "weapon_awp", "AWP + Deagle");

	SetMenuTitle(hMenu, "[VIP] Weapons");
	SetMenuExitButton(hMenu, true);
	SetMenuExitBackButton(hMenu, false);
}

public WeaponsMenuHandler(Handle:hMenu, MenuAction:action, client, item) {
	if(action != MenuAction_Select || !g_bIsVip[client] || g_iPlayerRounds[client] < g_iCvar[3] || !IsPlayerAlive(client)) return;

	decl String:szInfo[32];
	if(!GetMenuItem(hMenu, item, szInfo, sizeof szInfo)) return;

	new i, iWeapon;
	for(; i <= CS_SLOT_SECONDARY; i++) {
		if((iWeapon = GetPlayerWeaponSlot(client, i)) != -1) {
			RemovePlayerItem(client, iWeapon);
			RemoveEdict(iWeapon);
		}
	}
	GivePlayerItem(client, szInfo);
	GivePlayerItem(client, "weapon_deagle");
}
because its a convar not a command
if you do sm_cvar sm_vip_version then it'll show
__________________
8guawong is offline
Reply



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 21:41.


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