AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   event crash problem (https://forums.alliedmods.net/showthread.php?t=324660)

jugule 05-22-2020 23:53

event crash problem
 
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.

PC Gamer 05-23-2020 00:24

Re: event crash problem
 
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"); 
        }
    }



jugule 05-26-2020 10:36

Re: event crash problem
 
Quote:

Originally Posted by PC Gamer (Post 2701720)
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 :(

Balimbanana 05-26-2020 11:46

Re: event crash problem
 
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.

jugule 05-26-2020 19:59

Re: event crash problem
 
Quote:

Originally Posted by Balimbanana (Post 2702410)
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.

Balimbanana 05-27-2020 21:47

Re: event crash problem
 
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);
                                }
                        }
                }
        }
}


Ilusion9 05-28-2020 05:20

Re: event crash problem
 
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");




All times are GMT -4. The time now is 07:29.

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