Raised This Month: $51 Target: $400
 12% 

Individual Weapon Restrictions


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-01-2008 , 07:26   Re: Individual Weapon Restrictions
Reply With Quote #11

SVC_BAD is not reliable channel overflow. Reliable channel overflow occurs when too many reliable messages (MSG_ONE, MSG_ALL, client_print(), show_hudmessage(), etc.) are sent at 1 time to a player, and the player disconnects.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-01-2008 , 11:21   Re: Individual Weapon Restrictions
Reply With Quote #12

Quote:
Originally Posted by Exolent[jNr] View Post
SVC_BAD is not reliable channel overflow. Reliable channel overflow occurs when too many reliable messages (MSG_ONE, MSG_ALL, client_print(), show_hudmessage(), etc.) are sent at 1 time to a player, and the player disconnects.
Ok then I think this is caused by my buy key being pressed. At the time of the errors, I was pressing my buy key multiple times at spawn which caused the plugin to tell me the weapons I am trying to buy are restricted. Each buy press caused a client_print about 4 times.
__________________
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-01-2008 , 11:26   Re: Individual Weapon Restrictions
Reply With Quote #13

In that case, you should add a delay for the message so it isn't spammed:
Code:
new Float:g_msg_delay[33]; // when message is shown: new Float:gametime = get_gametime(); if( gametime >= g_msg_delay[id] ) {     client_print(id, print_chat, "message");         // This will make the message only show at intervals of 1 second.     // Change as you see fit.     g_msg_delay[id] = gametime + 1.0; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-01-2008 , 11:51   Re: Individual Weapon Restrictions
Reply With Quote #14

A problem I am now seeing is if I purchase a restricted weapon manually, it gets dropped and deleted as it should.

But if I buy via my buy script key, it drops and deletes the first purchased as it should but any thereafter only get dropped but not deleted.

Example:
My buy key buys deagle and sg552, both of these are on restricted list. When I press buy, both get purchased, deagle is dropped and deleted, sg552 gets dropped but not deleted.
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2008 , 00:51   Re: Individual Weapon Restrictions
Reply With Quote #15

Fixed by re-adding WeapPickup to detect purchase.
__________________
Bugsy is offline
YKH =]
Senior Member
Join Date: Sep 2008
Location: Hong Kong
Old 10-02-2008 , 10:06   Re: Individual Weapon Restrictions
Reply With Quote #16

Quote:
Originally Posted by Exolent[jNr] View Post
This is a full (almost) list of cstrike -> fakemeta conversions.
For the cs_[s|g|res]et_user_model() functions, look at Mercylezz tutorial on lowering SVC_BAD.
may i use this inc for my bp ammo plugin??
change cstrike to fakemeta
__________________
Approved Plugins

[ZP] Effect Plugins :
Damage Effect
Real Death
YKH =] is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-02-2008 , 13:31   Re: Individual Weapon Restrictions
Reply With Quote #17

I finally got around to doing it with hamsandwich.

It really is more elegant: your code is ~800 lines, my code is ~380 lines, and they both do the same thing. There might be slight differences in the chat messages displayed to clients.

Feel free to criticize, copy+paste, comment, etc.

Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
#include <nvault>

#define PLUGIN "Individual Weapon Restriction"
#define VERSION "1.0"
#define AUTHOR "stupok69"

#define OFFSET_WEAPONTYPE	43
#define OFFSET_CSMONEY		115

#define NVAULT_FILE      "iwr_data"

new const g_weapons[][] =
{
    "empty",
    "p228",	//1
    "empty",
    "scout",	//3
    "hegrenade",	//4
    "xm1014",	//5
    "c4",	//6
    "mac10",	//7
    "aug",	//8
    "smokegrenade",//9
    "elite",	//10
    "fiveseven",	//11
    "ump45",	//12
    "sg550",	//13
    "galil",	//14
    "famas",	//15
    "usp",	//16
    "glock18",	//17
    "awp",	//18
    "mp5navy",	//19
    "m249",	//20
    "m3",	//21
    "m4a1",	//22
    "tmp",	//23
    "g3sg1",	//24
    "flashbang",	//25
    "deagle",	//26
    "sg552",	//27
    "ak47",	//28
    "knife",	//29
    "p90"	//30
}

new bool:g_idwid[33][31]
new g_nvaulth
new g_oldmoney[33][3]

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_concmd("amx_restrictadd",    "AddRestrict",    ADMIN_CVAR , "- <player> <weapon> - Add weapon restriction to player.")
	register_concmd("amx_restrictremove" ,"RemoveRestrict", ADMIN_CVAR,  "- <player> <weapon> - Remove weapon restriction to player.")
	register_concmd("amx_restrictclear" , "ClearRestrict",  ADMIN_CVAR,  "- <player> - Clear all weapon restrictions for player.")
	register_concmd("amx_restrictshow" ,  "ShowRestrict",   ADMIN_CVAR,  "- <player> - Display a players weapon restrictions.")
	
	register_clcmd("say /restrict" ,     "NotifyPlayer",   ADMIN_ALL,   "- Display your weapon restrictions")
	
	register_event("Money", "event_money", "be")
	
	new temp[32]
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		if(i == 2)
			continue
		
		formatex(temp, 31, "weapon_%s", g_weapons[i])
		
		RegisterHam(Ham_Item_AddToPlayer, temp, "bacon_item_addtoplayer", 0)
	}
	
	g_nvaulth = nvault_open(NVAULT_FILE)
}

public plugin_end()
{
	nvault_close(g_nvaulth)
}

public event_money(id)
{
	// If player deserves his money back.
	if(g_oldmoney[id][0])
	{
		g_oldmoney[id][0] = 0
		fm_set_user_money(id, g_oldmoney[id][1])
	}
}

public client_authorized(id)
{
	for(new i = 1; i < sizeof g_weapons; i++)
	{	
		g_idwid[id][i] = false
	}
	
	load_from_vault(id)
}

public bacon_item_addtoplayer(this, id)
{
	// Player's money before the transaction.
	g_oldmoney[id][1] = fm_get_user_money(id)
	
	if(g_idwid[id][fm_get_weapon_id(this)])
	{
		client_print(id, print_chat, "* You have been restricted from using %s.", g_weapons[fm_get_weapon_id(this)])
		client_print(id, print_chat,"* Say '/restrict' in chat to view your restrictions.")
		engfunc(EngFunc_RemoveEntity, this)
		
		// Player should get his money back.
		g_oldmoney[id][0] = 1
		return HAM_SUPERCEDE
	}
	return HAM_IGNORED
}

public AddRestrict(id, level, cid)
{
	if(!cmd_access(id, level, cid, 3))
		return PLUGIN_HANDLED
	
	new argName[32]
	
	read_argv(1, argName, 31)
	
	new targetid
	
	targetid = cmd_target(id, argName)
	
	if(!targetid)
		return PLUGIN_HANDLED
	
	new argWeap[32], weaponid
	
	read_argv(2, argWeap, 31)
	
	weaponid = PLUGIN_HANDLED
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		if(containi(g_weapons[i], argWeap) != -1)
		{
			weaponid = i
		}
	}
	
	if(weaponid == -1)
		return PLUGIN_HANDLED
	
	g_idwid[targetid][weaponid] = true
	
	new targetname[32]
	get_user_name(targetid, targetname, 31)
	
	console_print(id, "* Restricted %s for %s.", g_weapons[weaponid], targetname)
	client_print(targetid, print_chat, "* You have been restricted from using %s.", g_weapons[weaponid])
	client_print(targetid, print_chat,"* Say '/restrict' in chat to view your restrictions.")
	
	save_to_vault(targetid)
	
	return PLUGIN_HANDLED
}

public RemoveRestrict(id, level, cid)
{
	if(!cmd_access(id, level, cid, 3))
		return PLUGIN_HANDLED
	
	new argName[32]
	
	read_argv(1, argName, 31)
	
	new targetid
	
	targetid = cmd_target(id, argName)
	
	if(!targetid)
		return PLUGIN_HANDLED
	
	new argWeap[32], weaponid
	
	read_argv(2, argWeap, 31)
	
	weaponid = PLUGIN_HANDLED
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		if(containi(g_weapons[i], argWeap) != -1)
		{
			weaponid = i
		}
	}
	
	if(weaponid == -1)
		return PLUGIN_HANDLED
	
	g_idwid[targetid][weaponid] = false
	
	new targetname[32]
	get_user_name(targetid, targetname, 31)
	
	console_print(id, "* %s no longer restricted for %s.", g_weapons[weaponid], targetname)
	client_print(targetid, print_chat, "* You have been unrestricted from using %s.", g_weapons[weaponid])
	client_print(targetid, print_chat,"* Say '/restrict' in chat to view your restrictions.")
	
	save_to_vault(targetid)
	
	return PLUGIN_HANDLED
}

public ClearRestrict(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED
	
	new argName[32]
	
	read_argv(1, argName, 31)
	
	new targetid
	
	targetid = cmd_target(id, argName)
	
	if(!targetid)
		return PLUGIN_HANDLED
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		g_idwid[targetid][i] = false
	}
	
	new targetname[32]
	get_user_name(targetid, targetname, 31)
	
	console_print(id, "* %s no longer has any restricted weapons.", targetname)
	client_print(targetid, print_chat, "* You are no longer restricted from using any weapons.")
	
	save_to_vault(targetid)
	
	return PLUGIN_HANDLED
}

public ShowRestrict(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED
	
	new argName[32]
	
	read_argv(1, argName, 31)
	
	new targetid
	
	targetid = cmd_target(id, argName)
	
	if(!targetid)
		return PLUGIN_HANDLED
	
	new restricted_weapons[256]
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		if(g_idwid[targetid][i])
		{
			add(restricted_weapons, 255, g_weapons[i])
			add(restricted_weapons, 255, ", ")
		}
	}
	
	new targetname[32]
	get_user_name(targetid, targetname, 31)
	
	console_print(id, "* %s has the following weapons restricted: %s", targetname, restricted_weapons)
	client_print(targetid, print_chat, "* You are restricted from using the following weapons: %s", restricted_weapons)
	client_print(targetid, print_chat,"* Say '/restrict' in chat to view your restrictions.")
	
	return PLUGIN_HANDLED
}

public NotifyPlayer(id, level, cid)
{
	new restricted_weapons[256]
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		if(g_idwid[id][i])
		{
			add(restricted_weapons, 255, g_weapons[i])
			add(restricted_weapons, 255, ", ")
		}
	}
	
	client_print(id, print_chat, "* You are restricted from using the following weapons: %s", restricted_weapons)
	
	return PLUGIN_HANDLED
}

public save_to_vault(id)
{
	if(!is_user_connected(id))
		return PLUGIN_HANDLED
		
	new key[32]
	get_user_authid(id, key, 31)
	
	new value[64], buffer[8]
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{
		if(g_idwid[id][i])
		{
			num_to_str(i, buffer, 7)
			add(value, 255, buffer)
			add(value, 255, ", ")
		}
	}
	
	nvault_set(g_nvaulth, key, value)
	
	return PLUGIN_HANDLED
}

public load_from_vault(id)
{	
	new key[32]
	get_user_authid(id, key, 31)
	
	new value[64], buffer[64]
	
	if(!nvault_get(g_nvaulth, key, value, 63))
	{
		return PLUGIN_HANDLED
	}
	
	buffer = value
	
	for(new i = 1; i < sizeof g_weapons; i++)
	{	
		split(value, buffer, 63, value, 63, ",")
		
		if(!buffer[1])
			break
		
		g_idwid[id][str_to_num(buffer)] = true
	}
	
	return PLUGIN_HANDLED
}

stock fm_get_weapon_id(index)
{	
	return get_pdata_int(index, OFFSET_WEAPONTYPE, is_linux_server() ? 4 : 0)
}

stock fm_get_user_money(index)
{
	return get_pdata_int(index, OFFSET_CSMONEY)
}

stock fm_set_user_money(index, money, flash = 0)
{
	set_pdata_int(index, OFFSET_CSMONEY, money)
	
	message_begin(MSG_ONE, get_user_msgid("Money"), {0,0,0}, index)
	write_long(money)
	write_byte(flash ? 1 : 0)
	message_end()
}

Last edited by stupok; 10-02-2008 at 16:41.
stupok is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2008 , 22:03   Re: Individual Weapon Restrictions
Reply With Quote #18

Quote:
Originally Posted by stupok69 View Post
I finally got around to doing it with hamsandwich.

It really is more elegant: your code is ~800 lines, my code is ~380 lines, and they both do the same thing. There might be slight differences in the chat messages displayed to clients.

Feel free to criticize, copy+paste, comment, etc.
The first time I loaded your script I had no problems. I tried to add a restrict to myself but was told I have immunity. I changed my admin flags to remove immunity, reconnected, and my server crashed. I reconnected and got the same result.

My code is large because it was thrown together rather quickly since it was made by request in the suggestions\requests forum. Most of my scripting spare time (which is very little) goes to the aimbot detection plugin. When I get some time I will clean up and do what I can to reduce the code.

Thanks for the effort
__________________

Last edited by Bugsy; 10-02-2008 at 22:07.
Bugsy is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-02-2008 , 23:56   Re: Individual Weapon Restrictions
Reply With Quote #19

I'm not trying to pick on you, I was just bored and felt like trying hamsandwich.

But... my server never crashes with the code above. Is your server on a linux box? That's the first thing that comes to mind.
stupok is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-03-2008 , 00:10   Re: Individual Weapon Restrictions
Reply With Quote #20

Quote:
Originally Posted by stupok69 View Post
I'm not trying to pick on you, I was just bored and felt like trying hamsandwich.

But... my server never crashes with the code above. Is your server on a linux box? That's the first thing that comes to mind.
I didn't think you were. How would that be picking on me anyway?

No, it is win32
__________________
Bugsy 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 05:12.


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