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

event crash problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jugule
AlliedModders Donor
Join Date: Apr 2020
Old 05-22-2020 , 23:53   event crash problem
Reply With Quote #1

Hi, I also have a problem that I can't deal with.
If the function is as follows:
PHP Code:
public Action Event_RoundEnd(Event eventchar[] namebool dontBroadcast
{
for(
int x 1<= MaxClientsx++)
        {
            if(
IsValidClient(x))
            {
                
RemoveAllWeapons(x); // removing all players weapons
             
}   
            
        }

and if I remove this function from 'RoundEnd', the server crashes when the player_spawn function is called.

playerspawn:
PHP Code:

public Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)  
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
int weapon

    if (!
client)
    {
        return;
    }
    
    if(
IsClientInGame(client)) 
    {
        
RemoveAllWeapons(client);
        if(
GetClientTeam(client) == 2)
        {
            
            
            
weapon GivePlayerItem(client"weapon_knife"); 
            
EquipPlayerWeapon(clientweapon);
    
        }
        else if(
GetClientTeam(client) == 3)
        {
            
            
            
weapon GivePlayerItem(client"weapon_m9_bayonet"); 
            
EquipPlayerWeapon(clientweapon);
            
        }
    }

What would be the problem?
I specify that if no player has weapons at the end of the round in hand, the server does not fall. But if he has a knife, the server falls.

Last edited by jugule; 05-22-2020 at 23:55.
jugule is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 05-23-2020 , 00:24   Re: event crash problem
Reply With Quote #2

I'm wondering if it works if you try this... (not tested)

PHP Code:
public Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)  
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));

    if (!
client)
    {
        return;
    }
    
    if(
IsClientInGame(client)) 
    {
        
RemoveAllWeapons(client);
        
        if(
GetClientTeam(client) == 2)
        {
            
GivePlayerItem(client"weapon_knife"); 
        }
        
        else if(
GetClientTeam(client) == 3)
        {
            
GivePlayerItem(client"weapon_m9_bayonet"); 
        }
    }

PC Gamer is offline
jugule
AlliedModders Donor
Join Date: Apr 2020
Old 05-26-2020 , 10:36   Re: event crash problem
Reply With Quote #3

Quote:
Originally Posted by PC Gamer View Post
I'm wondering if it works if you try this... (not tested)

PHP Code:
public Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)  
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));

    if (!
client)
    {
        return;
    }
    
    if(
IsClientInGame(client)) 
    {
        
RemoveAllWeapons(client);
        
        if(
GetClientTeam(client) == 2)
        {
            
GivePlayerItem(client"weapon_knife"); 
        }
        
        else if(
GetClientTeam(client) == 3)
        {
            
GivePlayerItem(client"weapon_m9_bayonet"); 
        }
    }

not working
jugule is offline
Balimbanana
Member
Join Date: Jan 2017
Old 05-26-2020 , 11:46   Re: event crash problem
Reply With Quote #4

Try RegConsoleCmd of a test command of each piece individually.
I have seen some games/mods that don't handle EquipPlayerWeapon correctly and crash most of the time. Then in some cases, RemovePlayerItem can also crash. I am not sure what is in RemoveAllWeapons(int client) but if that is what is causing the crash, you could try the m_hMyWeapons offs with something like this:
Code:
void RemoveAllWeapons(int client)
{
	if ((!IsValidEntity(client)) || (client == 0)) return;
	//Separated check or may cause errors if any above are passed
	if (!IsPlayerAlive(client)) return;
	int WeapList = FindSendPropInfo("CBasePlayer", "m_hMyWeapons");
	if (WeapList != -1)
	{
		if (HasEntProp(client,Prop_Data,"m_hViewModel"))
		{
			int viewmdl = GetEntPropEnt(client,Prop_Data,"m_hViewModel");
			if (viewmdl != -1)
			{
				SetEntProp(viewmdl,Prop_Send,"m_fEffects",32);
			}
		}
		for (int j; j<104; j += 4)
		{
			int itmp = GetEntDataEnt2(client,WeapList + j);
			if (itmp != -1)
			{
				if (IsValidEntity(itmp))
				{
					AcceptEntityInput(itmp,"kill");
				}
			}
		}
	}
	return;
}
If it is the EquipPlayerWeapon that is crashing, then depending on the game, you could try a
ClientCommand("use %s",weaponclass);
If ClientCommand is blocked in the game, then you could try setting all the properties required to force equip an item through m_hActiveWeapon on client, m_hWeapon on m_hViewModel from client. Then check the m_fFlags, m_fEffects on each to match an equipped weapon.
Balimbanana is offline
jugule
AlliedModders Donor
Join Date: Apr 2020
Old 05-26-2020 , 19:59   Re: event crash problem
Reply With Quote #5

Quote:
Originally Posted by Balimbanana View Post
Try RegConsoleCmd of a test command of each piece individually.
I have seen some games/mods that don't handle EquipPlayerWeapon correctly and crash most of the time. Then in some cases, RemovePlayerItem can also crash. I am not sure what is in RemoveAllWeapons(int client) but if that is what is causing the crash, you could try the m_hMyWeapons offs with something like this:
Code:
void RemoveAllWeapons(int client)
{
	if ((!IsValidEntity(client)) || (client == 0)) return;
	//Separated check or may cause errors if any above are passed
	if (!IsPlayerAlive(client)) return;
	int WeapList = FindSendPropInfo("CBasePlayer", "m_hMyWeapons");
	if (WeapList != -1)
	{
		if (HasEntProp(client,Prop_Data,"m_hViewModel"))
		{
			int viewmdl = GetEntPropEnt(client,Prop_Data,"m_hViewModel");
			if (viewmdl != -1)
			{
				SetEntProp(viewmdl,Prop_Send,"m_fEffects",32);
			}
		}
		for (int j; j<104; j += 4)
		{
			int itmp = GetEntDataEnt2(client,WeapList + j);
			if (itmp != -1)
			{
				if (IsValidEntity(itmp))
				{
					AcceptEntityInput(itmp,"kill");
				}
			}
		}
	}
	return;
}
If it is the EquipPlayerWeapon that is crashing, then depending on the game, you could try a
ClientCommand("use %s",weaponclass);
If ClientCommand is blocked in the game, then you could try setting all the properties required to force equip an item through m_hActiveWeapon on client, m_hWeapon on m_hViewModel from client. Then check the m_fFlags, m_fEffects on each to match an equipped weapon.
It works, but in spawn players have to press Q to have the knife in their hand.
jugule is offline
Balimbanana
Member
Join Date: Jan 2017
Old 05-27-2020 , 21:47   Re: event crash problem
Reply With Quote #6

It is possible that either the EquipPlayerWeapon or ClientCommand is too soon for the weapon to properly initialize. If you make a 0.1 timer, it should fix that.
It could be something like this:
Code:
After GivePlayerItem

Handle dp = CreateDataPack();
WritePackCell(dp, client);
WritePackString(dp, "weaponname");
CreateTimer(0.1, EquipWeapon, dp, TIMER_FLAG_NO_MAPCHANGE);

For the callback:
public Action EquipWeapon(Handle timer, Handle dp)
{
	if (dp != INVALID_HANDLE)
	{
		ResetPack(dp);
		int client = ReadPackCell(dp);
		char weaponcls[64];
		ReadPackString(dp, weaponcls, sizeof(weaponcls));
		CloseHandle(dp);
		if (IsValidEntity(client))
		{
			if (IsClientInGame(client))
			{
				if (IsPlayerAlive(client))
				{
					ClientCommand(client, "use %s", weaponcls);
				}
			}
		}
	}
}
If you are going to use the weapon index for EquipPlayerWeapon, then you could adjust it a little to include the index:
Code:
Handle dp = CreateDataPack();
WritePackCell(dp, client);
WritePackCell(dp, weapon);
CreateTimer(0.1, EquipWeapon, dp, TIMER_FLAG_NO_MAPCHANGE);

For the callback:
public Action EquipWeapon(Handle timer, Handle dp)
{
	if (dp != INVALID_HANDLE)
	{
		ResetPack(dp);
		int client = ReadPackCell(dp);
		int weapon = ReadPackCell(dp);
		CloseHandle(dp);
		if ((IsValidEntity(client)) && (IsValidEntity(weapon)))
		{
			if (IsClientInGame(client))
			{
				if (IsPlayerAlive(client))
				{
					EquipPlayerWeapon(client, weapon);
				}
			}
		}
	}
}
Balimbanana is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-28-2020 , 05:20   Re: event crash problem
Reply With Quote #7

PHP Code:

void RemoveClientWeapons
(int client)
{
    
int entity CreateEntityByName("game_player_equip");
    if (
entity == -1)
    {
        
LogError("Unable to create \"game_player_equip\" entity.");
        return;
    }
    
    
DispatchKeyValue(entity"spawnflags""3");
    
AcceptEntityInput(entity"Use"client);
    
AcceptEntityInput(entity"Kill");

__________________

Last edited by Ilusion9; 05-28-2020 at 05:20.
Ilusion9 is offline
Reply


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 23:05.


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