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

Lag on the server through the plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
szogun
Senior Member
Join Date: Apr 2016
Old 02-11-2020 , 13:18   Lag on the server through the plugin
Reply With Quote #1

Hey, I have high var and sv on the server via the medic plugin to csgo.

Unfortunately, I am not able to improve it myself, or I can count on help

HTML Code:
/* put the line below after all of the includes!
#pragma newdecls required
*/

//garrett's simple medic....

//Includes:
#include <sourcemod>
#include <sdktools>

//well... semicolon is good
#pragma semicolon 1

#define PLUGIN_VERSION "1.0.1"

static bool PrethinkBuffer[MAXPLAYERS + 1];
static float clientposition[MAXPLAYERS + 1][3];
static float targetposition[MAXPLAYERS + 1][3];
static targetent[MAXPLAYERS + 1];
static targethp[MAXPLAYERS + 1];
static bool isinhealing[MAXPLAYERS + 1];

int MaxPlayers;

//Effects
int g_BeamSprite;
int g_HaloSprite;
int greenColor[4] = {0, 200, 0, 255};
int blueColor[4] = {0, 0, 255, 255};

public Plugin myinfo = 
{
	name = "Garrett's medic plugin",
	author = "javalia",
	description = "Initiates healing when a player presses his use key on another",
	version = PLUGIN_VERSION,
	url = "http://forums.alliedmods.net/showthread.php?p=829970"
};

public void OnPluginStart()
{
	CreateConVar("sm_medic_version", PLUGIN_VERSION, "Version of the Medic plugin", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
}

public void OnMapStart()
{
	MaxPlayers = GetMaxClients();
	
	g_BeamSprite = PrecacheModel("materials/sprites/laser.vmt", true); 
	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt", true);
	
	for (int i = 1; i <= MaxPlayers; i++)
	{
		targetent[i] = -1;
	}
}

public void OnGameFrame()
{
	//Loop:
	for (int Client = 1; Client <= MaxPlayers; Client++)
	{
		//Connected and alive:
		if (IsClientInGame(Client) && IsPlayerAlive(Client))
		{
			//Use Key:
			if (GetClientButtons(Client) & IN_USE)
			{
				//Overflow:
				if (!PrethinkBuffer[Client])
				{
					//Action:
					CommandUse(Client);
					
					//UnHook:
					PrethinkBuffer[Client] = true;
				}
			}
			else
				PrethinkBuffer[Client] = false;
		}
	}
}

void CommandUse(int Client)
{
	//Initialize:
	int target = GetClientAimTarget(Client);
	
	if (target < 1)
		return;
	
	//Spamming the use key causes this to show up if the target is out of range  =/
	if (targetent[Client] > 0)
	{
		if (target != targetent[Client])
			PrintToChat(Client, "\x02Możesz leczyć tylko jedną osobę na raz.");
		else
			PrintToChat(Client, "\x02Już leczysz %N.", target);
		
		return;
	}
	
	if (GetClientTeam(Client) == GetClientTeam(target))
	{
		targetent[Client] = target;
		CreateTimer(0.5, Commandmedic, Client, TIMER_FLAG_NO_MAPCHANGE);
	}
}

public Action Commandmedic(Handle Timer, any Client)
{
	if (!IsClientInGame(Client) || !IsClientInGame(targetent[Client]) || !IsPlayerAlive(Client) || !IsPlayerAlive(targetent[Client]))
	{
		isinhealing[Client] = false;
		targetent[Client] = -1;
		return Plugin_Handled;
	}
	
	GetClientAbsOrigin(Client, clientposition[Client]);
	GetClientAbsOrigin(targetent[Client], targetposition[targetent[Client]]);
	float distance = GetVectorDistance(clientposition[Client], targetposition[targetent[Client]]);
	
	//Initial
	if (!isinhealing[Client])
	{
		if (distance < 200.0)
		{
			targethp[targetent[Client]] = GetClientHealth(targetent[Client]);
			
			if (targethp[targetent[Client]] < 100)
			{
				PrintToChat(Client, "\x02 %N Musi być bliżej ciebia aby móc go leczyć", targetent[Client], targetent[Client]);
				SetEntityHealth(targetent[Client], targethp[targetent[Client]] + 2);
				clientposition[Client][2] += 10.0;
				TE_SetupBeamRingPoint(clientposition[Client], 10.0, 400.0, g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greenColor, 10, 0);
				TE_SendToAll();
				targetposition[targetent[Client]][2] += 10.0;
	  			TE_SetupBeamRingPoint(targetposition[targetent[Client]], 400.0, 10.0, g_BeamSprite, g_HaloSprite, 0, 10, 0.5, 10.0, 0.5, blueColor, 10, 0);
				TE_SendToAll();
				//PrintToChat(Client, "\x02 %N zdrowie: %d", targetent[Client], targethp[targetent[Client]]);
				isinhealing[Client] = true;
				CreateTimer(0.5, Commandmedic, Client, TIMER_FLAG_NO_MAPCHANGE);
			}
			else
			{
				if (targethp[targetent[Client]] > 100)
					SetEntityHealth(targetent[Client], 100);
				
				isinhealing[Client] = false;
				PrintToChat(Client, "\x02 %N Ma pełne zdrowie.", targetent[Client]);
				targetent[Client] = -1;
			}
		}
		else
			targetent[Client] = -1;
	}
	else	//Subsequent
	{
		if (distance < 200.0)
		{
			targethp[targetent[Client]] = GetClientHealth(targetent[Client]);
			
			if (targethp[targetent[Client]] < 100)
			{
				SetEntityHealth(targetent[Client], targethp[targetent[Client]] + 2);
				clientposition[Client][2] += 10.0;
				TE_SetupBeamRingPoint(clientposition[Client], 10.0, 400.0, g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greenColor, 10, 0);
				TE_SendToAll();
				targetposition[targetent[Client]][2] += 10.0;
	  			TE_SetupBeamRingPoint(targetposition[targetent[Client]], 400.0, 10.0, g_BeamSprite, g_HaloSprite, 0, 10, 0.5, 10.0, 0.5, blueColor, 10, 0);
				TE_SendToAll();
				//PrintToChat(Client, "[Garrett] %N's health: %d", targetent[Client], targethp[targetent[Client]]);
				CreateTimer(0.5, Commandmedic, Client, TIMER_FLAG_NO_MAPCHANGE);
			}
			else
			{
				if (targethp[targetent[Client]] > 100)
					SetEntityHealth(targetent[Client], 100);
				
				isinhealing[Client] = false;
				//PrintToChat(Client, "[Garrett] %N has full health.", targetent[Client]);
				targetent[Client] = -1;
			}
		}
		else
		{
			isinhealing[Client] = false;
			//PrintToChat(Client, "[Garrett] %N is out of range, healing stopped.", targetent[Client]);
			targetent[Client] = -1;
		}
	}
	return Plugin_Handled;
}
szogun is offline
Cruze
Veteran Member
Join Date: May 2017
Old 02-11-2020 , 14:13   Re: Lag on the server through the plugin
Reply With Quote #2

Use OnPlayerRunCmd instead of OnGameFrame
__________________
Taking paid private requests! Contact me
Cruze is offline
szogun
Senior Member
Join Date: Apr 2016
Old 02-11-2020 , 15:33   Re: Lag on the server through the plugin
Reply With Quote #3

Quote:
//// medic.sp
//
// medic.sp(5 : error 180: function return type differs from prototype. expect
ed 'Action', but got 'int'
//
// 1 Error.
//
// Compilation Time: 0,31 sec
// ----------------------------------------
szogun 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 02:18.


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