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

[CS:GO] What makes this function lag the server?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 02-01-2021 , 12:54   [CS:GO] What makes this function lag the server?
Reply With Quote #1

When using this function in OnPlayerRunCmd it makes the server fps drop to 10 in some maps, what could be the cause of it?

Also these functions are SDKCalls:
  • LookupBone -> CBaseAnimating::LookupBone
  • GetBonePosition -> CBaseAnimating::GetBonePosition
  • BotIsVisible -> CCSBot::IsVisible

PHP Code:
float[] SelectBestTargetPos(int clientint &iBestEnemy)
{
    
float fMyPos[3];
    
GetClientAbsOrigin(clientfMyPos);
    
    
float fTargetPos[3];
    
float fClosestDistance 999999999999999.0;
    
    
int iActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    
int iDefIndex;
    if (
iActiveWeapon != -1)
    {
        
iDefIndex GetEntProp(iActiveWeaponProp_Send"m_iItemDefinitionIndex");
    }
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
== client)
            continue;
        
        if (!
IsClientInGame(i))
            continue;
        
        if (!
IsPlayerAlive(i))
            continue;
        
        if (
GetEntProp(iProp_Send"m_bGunGameImmunity"))
            continue;
        
        if (
GetClientTeam(i) == GetClientTeam(client))
            continue;
        
        if (!
IsTargetInSightRange(clienti))
            continue;
        
        
int iBone LookupBone(i"head_0");
        if (
iBone 0)
            continue;
        
        
float fHead[3], fBad[3];
        
GetBonePosition(iiBonefHeadfBad);
        
        
fHead[2] += 2.0;
        
        if (
BotIsVisible(clientfHeadfalse, -1))
        {
            
g_bIsHeadVisible[client] = true;
        }
        else
        {
            
bool bVisibleOther false;
            
            
//Head wasn't visible, check other bones.
            
for (int b 0<= sizeof(g_szBoneNames) - 1b++)
            {
                
iBone LookupBone(ig_szBoneNames[b]);
                if (
iBone 0)
                    continue;
                
                
GetBonePosition(iiBonefHeadfBad);
                
                if (
BotIsVisible(clientfHeadfalse, -1))
                {
                    
g_bIsHeadVisible[client] = false;
                    
bVisibleOther true;
                    break;
                }
            }
            
            if (!
bVisibleOther)
                continue;
        }
        
        
float fEnemyPos[3];
        
GetClientAbsOrigin(ifEnemyPos);
        
        
float fDistance GetVectorDistance(fEnemyPosfMyPostrue);
        if (
fDistance fClosestDistance)
        {
            
fClosestDistance fDistance;
            
fTargetPos fHead;
            
            
iBestEnemy i;
            
            if (
iDefIndex == || iDefIndex == 11 || iDefIndex == 38 || iDefIndex == 40)
            {
                
g_bCanAttack[client] = true;
            }
            else
            {
                
CreateTimer(0.18Timer_AttackGetClientUserId(client));
            }
        }
    }
    
    return 
fTargetPos;

__________________
manicogaming is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 02-01-2021 , 13:14   Re: [CS:GO] What makes this function lag the server?
Reply With Quote #2

I would guess that is the CreateTimer part.

You are creating a timer every tick, that could run between 3~10 times per second if the logic enters in the CreateTimer all the timer.

You can try adding a comment // to it and check if it stops lagging.

PS: I didn't debug the whole code.
Also, there are some other "micro-optimizations" that could be done, but probably they aren't the real cause.
__________________

Last edited by Marttt; 02-01-2021 at 13:15.
Marttt is offline
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 02-01-2021 , 13:42   Re: [CS:GO] What makes this function lag the server?
Reply With Quote #3

Nope, it still lags
__________________
manicogaming is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-01-2021 , 15:46   Re: [CS:GO] What makes this function lag the server?
Reply With Quote #4

Quote:
Originally Posted by manicogaming View Post
When using this function in OnPlayerRunCmd
This
Bacardi is offline
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 02-01-2021 , 16:00   Re: [CS:GO] What makes this function lag the server?
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
This
Hmm I figured that would be the case so I tested a repeat 0.1 timer and it lagged less, I simplified the function and it no longer lags.
__________________
manicogaming is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 02-07-2021 , 12:33   Re: [CS:GO] What makes this function lag the server?
Reply With Quote #6

float fClosestDistance = 999999999999999.0;
ur creating this every tick, plus other stuff can make these lags.
farawayf 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 05:25.


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