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

Solved [L4d] Script is lagging the chat


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 06-22-2021 , 13:01   [L4d] Script is lagging the chat
Reply With Quote #1

Hi there,

I have a script that should check player positions on 2 maps to fix some bypasses.

Actually it should play a sound, slay the player bc I am mean and make a whitty quote.

It prevents jumping down from the DA Crane level on common heads at car alarm for example.

If you jump down, it slays you.

All working as expected. Except the cpu load seems to slow down chat messages.

I guess it is bc I used OnGameFrame() and then several if statements.

Is there any other way with less cpu load to check the playerpostions?

Thx in advance.
Attached Files
File Type: sp Get Plugin or Get Source (l4d_nojumpbypass.sp - 81 views - 3.3 KB)
__________________

Last edited by finishlast; 06-25-2021 at 11:29.
finishlast is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 06-22-2021 , 13:51   Re: [L4d] Script is lagging the chat
Reply With Quote #2

For starters you should cache the map name in OnMapStart() and set a value to an int and check that instead of constantly retrieving the map and checking the string. You could use an enum

PHP Code:
enum
{
    
MAP_DA_1 1,
    
MAP_DA_2,
    
MAP_DA_3
    etc

You could also switch to a 0.1 or 0.2 timer, it doesn't need to be so precise as OnGameFrame, just increase the Distance variable to 100 more.

It might be better to use "EmitSoundToAll()" instead of looping clients and running "ClientCommand playgamesound".

Also change the if statements, currently it's checking all even if killing that person, use if else statements.

You also have a mistake in the client loop. It should be "Client <= MaxClients" not "Client < MaxClients"

You don't need to do "#include <sdktools_sound>" this is covered by "#include <sdktools>" which is the only one you should include, not any "sdktools_other_file_names", otherwise if you don't have "#include <sdktools>" and nothing else is using sdktools the extension will not load.
__________________

Last edited by Silvers; 06-22-2021 at 13:55.
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 06-22-2021 , 16:55   Re: [L4d] Script is lagging the chat
Reply With Quote #3

You can decrease CPU loading down to 0% by using triggers and hooking touch outputs, e.g., see: [Any] Dev Zones

Try never use OnGameFrame() at all unless a real reason.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 06-23-2021 , 11:46   Re: [L4d] Script is lagging the chat
Reply With Quote #4

Thanks for the input!

I will try with a timer next and take a look into this dev zones thing too.

Thanks again!

****
Tried a timer with 0.2 and a bit bigger distance.
That seems to work, doing the suggested enum and if else next.

The lag is already gone.

Going to check out the dev zone thing too.
__________________

Last edited by finishlast; 06-25-2021 at 11:31.
finishlast is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 06-23-2021 , 15:18   Re: [L4d] Script is lagging the chat
Reply With Quote #5

My example:

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <devzones>

#pragma newdecls required

public Plugin myinfo =
{
    
name "Zones Teleporter",
    
author "Dragokas",
    
description "",
    
version "1.0",
    
url ""
};

bool g_bActivated;

public 
void OnMapStart()
{
    static 
char sMap[64];
    
GetCurrentMap(sMapsizeof sMap);
    
    
g_bActivated false;
    
    if (
strcmp(sMap"l4d_airport02_offices") == 0)
    {
        
g_bActivated true;
    }
}

public 
int Zone_OnClientEntry(int clientchar[] zone)
{
    if (!
g_bActivated)
        return;

    
float pos[3];
    if (
strcmp(zone"Zone 1") == 0)
    {
        
GetClientAbsOrigin(clientpos);
        
pos[0] -= 100.0;
        
TeleportEntity(clientposNULL_VECTORNULL_VECTOR);
    }
    else if (
strcmp(zone"Zone 2") == 0)
    {
        
GetClientAbsOrigin(clientpos);
        
pos[0] += 100.0;
        
TeleportEntity(clientposNULL_VECTORNULL_VECTOR);
    }

configs/dev_zones/l4d_airport02_offices.zones.txt

Code:
"Zones"
{
	"0"
	{
		"Name"		"Zone 1"
		"cordinate_a"		"4426.947266 834.294373 16.031248"
		"cordinate_b"		"4438.528809 1663.458740 250.000000"
		"vis"		"0"
		"team"		"0"
	}
	"1"
	{
		"Name"		"Zone 2"
		"cordinate_a"		"4402.264160 880.324707 16.031252"
		"cordinate_b"		"4384.531250 1606.159668 250.000000"
		"vis"		"0"
		"team"		"0"
	}
}
See description in Dev Zones topic to get zones creation commands.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 06-25-2021 , 11:29   Re: [L4d] Script is lagging the chat
Reply With Quote #6

Oh, thank you Dragokas for the example.

That seems to be very helpfull for a lot of different stuff! Very nice.
__________________
finishlast is offline
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 17:24.


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