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

[L4D/2] Replace weapons on map


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gbr161
Member
Join Date: May 2012
Old 08-15-2013 , 10:39   [L4D/2] Replace weapons on map
Reply With Quote #1

Hi all
Im trying to replace some weapons using this code:
Code:
public swapweapons()
{	
	new EntCount = GetEntityCount();
	new String:EdictName[128];
	new Float:position[3];
	new Float:angle[3];
	for (new i = 0; i <= EntCount; i++)
	{
		if (IsValidEntity(i) && IsValidEdict(i))
		{
			GetEdictClassname(i, EdictName, sizeof(EdictName));
			
			if (StrContains(EdictName, "shotgun", false) != -1)
			{
				GetEntPropVector(i, Prop_Send, "m_vecOrigin", position);
				GetEntPropVector(i, Prop_Data, "m_angRotation", angle);
				AcceptEntityInput(i, "Kill");
				new iWeapon = CreateEntityByName("weapon_autoshotgun_spawn");
				if(IsValidEntity(iWeapon))
				{		
					DispatchKeyValue(iWeapon, "count", "8"); 
					DispatchSpawn(iWeapon);
					TeleportEntity(iWeapon, position, angle, NULL_VECTOR);
					
				}
			}
			
		}
	}
}
But server gives segmentation fault when i load the plugin :/ It used to work with l4d1 without any problems but i cant get it working with l4d2.
Please help
gbr161 is offline
Electr000999
Senior Member
Join Date: Aug 2011
Old 08-15-2013 , 11:14   Re: [L4D/2] Replace weapons on map
Reply With Quote #2

gbr161, so it is better to clarify the filter by grade shotguns on line class check, and more on what event you call this function?

may be:
Code:
	
        new EntCount = GetEntityCount();
	
	decl String:EdictName[128], Float:position[3], Float:angle[3];
	for (new i = 0; i <= EntCount; i++)
	{
		if (IsValidEntity(i))
		{
			GetEdictClassname(i, EdictName, sizeof(EdictName));
			
			if (StrContains(EdictName, "shotgun", false) != -1)
			{
				GetEntPropVector(i, Prop_Send, "m_vecOrigin", position);
				GetEntPropVector(i, Prop_Data, "m_angRotation", angle);
				AcceptEntityInput(i, "Kill");
				
				new iWeapon = CreateEntityByName("weapon_autoshotgun_spawn");
				if (iWeapon != -1)
				{
					DispatchKeyValue(iWeapon, "count", "8"); 
					TeleportEntity(iWeapon, position, angle, NULL_VECTOR);
					DispatchSpawn(iWeapon);
				}
			}
		}
	}
I remember bug if before DispatchSpawn (iWeapon) does not specify the location where the weapon will be a server crashes, it was so early as now I do not know.

Last edited by Electr000999; 08-15-2013 at 12:41.
Electr000999 is offline
Send a message via Skype™ to Electr000999
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-15-2013 , 11:27   Re: [L4D/2] Replace weapons on map
Reply With Quote #3

What difference between
AcceptEntityInput(i, "Kill") and RemoveEdict()?
Jоnny is offline
Skyy
AlliedModders Donor
Join Date: Jan 2010
Location: Toronto, Canada
Old 08-15-2013 , 11:33   Re: [L4D/2] Replace weapons on map
Reply With Quote #4

use if (!AcceptEntityInput(i, "Kill")) RemoveEdict(); instead.
Skyy is offline
Electr000999
Senior Member
Join Date: Aug 2011
Old 08-15-2013 , 11:41   Re: [L4D/2] Replace weapons on map
Reply With Quote #5

Jоnny, да по идее это прямой запрос на удаление к пропу, а RemoveEdict внутренняя функция и лишние строчки кода к исполнению ну и кто любит посредников?)

Last edited by Electr000999; 08-15-2013 at 11:42.
Electr000999 is offline
Send a message via Skype™ to Electr000999
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-15-2013 , 11:48   Re: [L4D/2] Replace weapons on map
Reply With Quote #6

Я думал что RemoveEdict и есть самый прямой запрос на удаление
Jоnny is offline
gbr161
Member
Join Date: May 2012
Old 08-15-2013 , 13:50   Re: [L4D/2] Replace weapons on map
Reply With Quote #7

Heres full code:
Code:
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
	name = "L4D2 weapon tier2",
	author = "GBR",
	description = "",
	version = "1.1",
	url = ""
}
public OnPluginStart()
{		
	HookEvent("player_first_spawn", Event_MissionStart);
	swapweapons();
	giveweapons();
}
public Event_MissionStart(Handle:event, const String:name[], bool:Broadcast)
{
	swapweapons();
	giveweapons();
}

public giveweapons()
{
	new ent;
	decl String:wpn[64];
	for(new x=1;x<=MaxClients;x++) 
	{
		if(IsClientConnected(x) && IsClientInGame(x) && IsPlayerAlive(x) && GetClientTeam(x)==2) 
		{
			if((ent = GetPlayerWeaponSlot(x, 0))!=-1) 
			{
				GetEdictClassname(ent, wpn, sizeof(wpn));
				if(StrContains("weapon_autoshotgun|weapon_shotgun_spas|weapon_rifle|weapon_rifle_ak47|weapon_rifle_desert|weapon_rifle_sg552|weapon_hunting_rifle|weapon_sniper_awp|weapon_sniper_military|weapon_sniper_scout",wpn, false) == -1)
				{
					new weaponIndex;
					while((weaponIndex = GetPlayerWeaponSlot(x, 0))!=-1) 
					{
						RemovePlayerItem(x, weaponIndex);
						RemoveEdict(weaponIndex);
					}
					GiveWeapon(x);
				}
			}else
			{
				GiveWeapon(x);
			}
		}
	}
}
stock GiveWeapon(client)
{
	switch(GetRandomInt(0,9))
	{
		case 0: BypassAndExecuteCommand(client, "give", "autoshotgun");
		case 1: BypassAndExecuteCommand(client, "give", "shotgun_spas");
		case 2: BypassAndExecuteCommand(client, "give", "rifle");
		case 3: BypassAndExecuteCommand(client, "give", "rifle_ak47");
		case 4: BypassAndExecuteCommand(client, "give", "rifle_desert");
		case 5: BypassAndExecuteCommand(client, "give", "rifle_sg552");
		case 6: BypassAndExecuteCommand(client, "give", "hunting_rifle");
		case 7: BypassAndExecuteCommand(client, "give", "sniper_awp");
		case 8: BypassAndExecuteCommand(client, "give", "sniper_military");
		case 9: BypassAndExecuteCommand(client, "give", "sniper_scout");
		
	}	
	BypassAndExecuteCommand(client, "give", "ammo");
}
stock BypassAndExecuteCommand(client, String: strCommand[], String: strParam1[])
{
	new flags = GetCommandFlags(strCommand);
	SetCommandFlags(strCommand, flags & ~FCVAR_CHEAT);
	FakeClientCommand(client, "%s %s", strCommand, strParam1);
	SetCommandFlags(strCommand, flags);
}
public swapweapons()
{	
	new EntCount = GetEntityCount();
	new String:EdictName[128];
	new Float:position[3];
	new Float:angle[3];
	for (new i = 0; i <= EntCount; i++)
	{
		if(IsValidEdict(i))
		{
			GetEdictClassname(i, EdictName, sizeof(EdictName));
			
			if ((StrContains(EdictName, "weapon_pumpshotgun_spawn", false) != -1)||(StrContains(EdictName, "weapon_shotgun_chrome_spawn", false) != -1))
			{
				GetEntPropVector(i, Prop_Send, "m_vecOrigin", position);
				GetEntPropVector(i, Prop_Data, "m_angRotation", angle);
				if (!AcceptEntityInput(i, "Kill")){RemoveEdict(i);}
				new iWeapon = CreateEntityByName("weapon_autoshotgun_spawn");
				if(IsValidEntity(iWeapon))
				{		
					DispatchKeyValue(iWeapon, "count", "8"); 
					DispatchSpawn(iWeapon);
					TeleportEntity(iWeapon, position, angle, NULL_VECTOR);
					
				}
			}
			
		}
	}
}

Last edited by gbr161; 08-15-2013 at 13:50.
gbr161 is offline
Electr000999
Senior Member
Join Date: Aug 2011
Old 08-15-2013 , 13:56   Re: [L4D/2] Replace weapons on map
Reply With Quote #8

gbr161, hm i no have crash.., what map, gamemode?
Electr000999 is offline
Send a message via Skype™ to Electr000999
gbr161
Member
Join Date: May 2012
Old 08-15-2013 , 14:00   Re: [L4D/2] Replace weapons on map
Reply With Quote #9

But does it relace weapons? Now i have no crash too because i changed part that Skyy proposed. Gamemode coop and any map.
gbr161 is offline
Electr000999
Senior Member
Join Date: Aug 2011
Old 08-15-2013 , 14:48   Re: [L4D/2] Replace weapons on map
Reply With Quote #10

gbr161, no, this not problem on if (!AcceptEntityInput(i, "Kill")){RemoveEdict(i);}, i replace to AcceptEntityInput(i, "Kill"), and no have crash), after i copy func from fist post and CRASH

some checks helped
Code:
if ((StrContains(EdictName, "weapon_pumpshotgun_spawn", false) != -1)||(StrContains(EdictName, "weapon_shotgun_chrome_spawn", false) != -1))
if post TeleportEntity(iWeapon, position, angle, NULL_VECTOR); after DispatchKeyValue(iWeapon, "count", "8"); - no crash but have lags,
good end)

and you need optimization:

you call swapweapons(); after every player_first_spawn, reasonable to do so after round_start c with a timer for a couple of seconds.

Last edited by Electr000999; 08-15-2013 at 15:03.
Electr000999 is offline
Send a message via Skype™ to Electr000999
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 04:55.


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