Senior Member
|
02-11-2020
, 13:18
Lag on the server through the plugin
|
#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;
}
|
|