View Single Post
Author Message
cile1993
Junior Member
Join Date: Dec 2011
Old 10-16-2013 , 05:44   Problem with entities and disconnecting players for same
Reply With Quote #1

Hi there, i have a problem of disconnecting a players from server because of too much entities at once, i would change max entities number but first i want to fix a bad plugin rather than to make more fps drops and lag on my server... So here is the .sma:

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

#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <fun>

#define PLUGIN "NekiTamoPlugin"
#define VERSION "1.0b"
#define AUTHOR "Megastorm"

new weapons_ct[][] = 
{
	"weapon_knife",
	"weapon_awp",
	"weapon_m4a1",
	"weapon_deagle",
	"weapon_hegrenade",
	"weapon_flashbang"
}
new weapons_t[][] = 
{
	"weapon_knife",
	"weapon_awp",
	"weapon_ak47",
	"weapon_deagle",
	"weapon_hegrenade",
	"weapon_flashbang"
}

new g_msgStatusIcon
new const w_modeli[][] = 
{
	"",
	"models/w_ak47.mdl",
	"models/w_m4a1.mdl",
	""
}

new cvar_vreme
new const maxAmmo[31]={0, 200, 0, 180, 1, 64, 1, 120, 180, 1, 200, 200, 180, 180, 180, 180, 200, 200, 30, 180, 200, 64, 180, 180, 90, 2, 70, 90, 120, 0, 150}

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_forward(FM_Touch, "EntTouch")
	register_forward(FM_Think, "EntThinks")
	RegisterHam(Ham_Spawn, "player", "PlayerSpawn", 1)
	g_msgStatusIcon = get_user_msgid("StatusIcon")
	register_message(g_msgStatusIcon, "msgStatusIcon")
	register_forward(FM_SetModel, "fw_SetModel")
	register_event("DeathMsg", "death", "a")
	
	cvar_vreme = register_cvar("amx_trajanje_oruzja", "15.0")
	register_event("HLTV", "eNewRound", "a", "1=0", "2=0")
	// Add your code here...
}


public eNewRound()
{
	new iEnt = engfunc(EngFunc_FindEntityByString, -1, "classname", "oruzje")
	while(iEnt > 0)
	{
		if(pev_valid(iEnt))
		engfunc(EngFunc_RemoveEntity, iEnt)
		iEnt = engfunc(EngFunc_FindEntityByString, -1, "classname", "oruzje")
	}
}

public EntThinks(ent)
{
	if(!pev_valid(ent))
		return;
	
	new szCName[32]
	pev(ent, pev_classname, szCName, charsmax(szCName))
	if(equal(szCName, "oruzje"))
	{
		engfunc(EngFunc_RemoveEntity, ent)
	}
}

public EntTouch(ent, id)
{
	if(!pev_valid(ent) || !is_user_alive(id))
		return;
	
	new szCName[32], szModel[32]
	pev(ent, pev_classname, szCName, charsmax(szCName))
	pev(ent, pev_model, szModel, charsmax(szModel))
	
	if(equal(szCName, "oruzje"))
	{
		if(equal(szModel, "models/m4a1.mdl"))
		{
			give_item(id, "weapon_m4a1")
			fm_set_user_bpammo(id, CSW_M4A1, 90)
		}
		else if(equal(szModel, "models/w_ak47.mdl"))
		{
			give_item(id, "weapon_ak47")
			fm_set_user_bpammo(id, CSW_AK47, 90)
		}
		
		engfunc(EngFunc_RemoveEntity, ent)
	}
}

public death()
{
	new victim = read_data(2)
	new team = get_user_team(victim)
	new Float:forigin[3]
	pev(victim, pev_origin, forigin)
	new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	set_pev(ent, pev_classname, "oruzje")
	set_pev(ent, pev_movetype, MOVETYPE_TOSS)
	set_pev(ent, pev_solid, SOLID_TRIGGER)
	set_pev(ent, pev_size, Float:{-16.0,-16.0,0.0},Float:{16.0,16.0,2.0})
	set_pev(ent, pev_origin, forigin)
	engfunc(EngFunc_DropToFloor, ent)
	set_pev(ent, pev_nextthink, get_gametime() + get_pcvar_float(cvar_vreme))
	engfunc(EngFunc_SetModel, ent, w_modeli[team])
}

public PlayerSpawn(id)
{
	set_task(0.1, "ItsShowTime", id)
}

public ItsShowTime(id)
{
	if(!is_user_alive(id))
		return;
	
	new iTeam = get_user_team(id)
	
	strip_user_weapons(id)
	switch(iTeam)
	{
		case 1:
		{
			for(new i = 0; i < sizeof weapons_t; i++)
				give_item(id, weapons_t[i])
		}
		case 2:
		{
			for(new i = 0; i < sizeof weapons_ct; i++)
				give_item(id, weapons_ct[i])
		}
	}
	new weapons[32]
	new weaponsnum
	get_user_weapons(id, weapons, weaponsnum)
	for(new i=0; i<weaponsnum; i++)
		if(maxAmmo[weapons[i]] > 0)
			fm_set_user_bpammo(id, weapons[i], maxAmmo[weapons[i]])
	
}

public msgStatusIcon(msgid, msgdest, id)
{
	static szIcon[8]
	get_msg_arg_string(2, szIcon, charsmax(szIcon))
	
	if(equal(szIcon, "buyzone") && get_msg_arg_int(1))
	{
		set_pdata_int(id, 235, get_pdata_int(id, 235) & ~(1<<0))
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static szClassName[33]
	pev(entity, pev_classname, szClassName, charsmax(szClassName))
	
	if(!equal(szClassName, "weaponbox"))
		return FMRES_IGNORED
	
	if(equal(model, "models/w_awp.mdl"))
	{
		new Float:fOrigin[3]
		pev(entity, pev_origin, fOrigin)
		set_pev(entity, pev_flags, pev(entity, pev_flags)|FL_KILLME)
		
		return FMRES_SUPERCEDE
	}
	return FMRES_IGNORED
}

stock fm_find_ent_by_owner(index, const classname[], owner, jghgtype = 0) {
	new strtype[11] = "classname", ent = index
	switch(jghgtype)
	{
		case 1: strtype = "target"
		case 2: strtype = "targetname"
	}
	
	while ((ent = engfunc(EngFunc_FindEntityByString, ent, strtype, classname)) && pev(ent, pev_owner) != owner) {}
	
	return; ent
}

stock fm_set_user_bpammo(id, weaponid, amnt) 
{
	static offset
	switch(weaponid)
	{
		case CSW_AWP: offset = 377
			case CSW_SCOUT,CSW_AK47,CSW_G3SG1: offset = 378
			case CSW_M249: offset = 379
			case CSW_FAMAS,CSW_M4A1,CSW_AUG,CSW_SG550,CSW_GALI,CSW_SG552: offset = 380
			case CSW_M3,CSW_XM1014: offset = 381
			case CSW_USP,CSW_UMP45,CSW_MAC10: offset = 382
			case CSW_FIVESEVEN,CSW_P90: offset = 383
			case CSW_DEAGLE: offset = 384
			case CSW_P228: offset = 385
			case CSW_GLOCK18,CSW_MP5NAVY,CSW_TMP,CSW_ELITE: offset = 386
			case CSW_FLASHBANG: offset = 387
			case CSW_HEGRENADE: offset = 388
			case CSW_SMOKEGRENADE: offset = 389
			default: return 0
	}
	set_pdata_int(id,offset,amnt,5)
	
	return 1
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
Does anyone have any idea how to fix this?
Thanks.
cile1993 is offline