Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empowerment & A little bit Optimization #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions scripting/dm_basics.sp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public OnPluginStart()
{
LoadTranslations("cssdm.phrases");

RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say_team", Command_Say);

cssdm_respawn_command = CreateConVar("cssdm_respawn_command", "1", "Sets whether clients can manually respawn");
cssdm_force_mapchanges = CreateConVar("cssdm_force_mapchanges", "0", "Sets whether CS:S DM should force mapchanges");
cssdm_mapchange_file = CreateConVar("cssdm_mapchange_file", "mapcycle.txt", "Sets the mapchange file for CS:S DM");
Expand Down Expand Up @@ -127,11 +124,9 @@ public Event_CheckDepleted(Handle:event, const String:name[], bool:dontBroadcast
{
return;
}

new ammoType = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");


/* Give something reasonable -- the game will chop it off */
DM_GiveClientAmmo(client, ammoType, 200, false);
DM_GiveClientAmmo(client, GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType"), 200, false);
}

public CvarChange_RestartMapTimer(Handle:cvar, const String:oldvalue[], const String:newvalue[])
Expand All @@ -150,8 +145,7 @@ RestartMapTimer()
if (GetConVarInt(cssdm_force_mapchanges))
{
/* Find how much time is left in the map */
new Float:seconds = (GetConVarInt(mp_timelimit) * 60.0) - GetGameTime();
g_ChangeMapTimer = CreateTimer(seconds, Timer_ChangeMap);
g_ChangeMapTimer = CreateTimer((GetConVarInt(mp_timelimit) * 60.0) - GetGameTime(), Timer_ChangeMap);
}
}

Expand Down Expand Up @@ -243,17 +237,15 @@ public Action:DM_OnClientDeath(client)
return Plugin_Continue;
}

public Action:Command_Say(client, args)
public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
{
if (!DM_IsRunning() || !GetConVarInt(cssdm_respawn_command))
{
return Plugin_Continue;
}

decl String:command[32];
GetCmdArg(1, command, sizeof(command));

if (strcmp(command, "respawn") == 0)
if (strcmp(sArgs, "respawn") == 0)
{
if (!IsClientInGame(client))
{
Expand Down
36 changes: 20 additions & 16 deletions scripting/dm_equipment.sp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@

/** Plugin Stuff */
new Handle:cssdm_enable_equipment; /** cssdm_enable_equipment cvar */
new Handle:cssdm_addictional_menu_cmds; /** cssdm_addictional_menu_cmds cvar */
new Handle:g_SpawnTimers[MAXPLAYERS+1]; /* Post-spawn timers */
new Handle:g_hPrimaryMenu = INVALID_HANDLE; /* Priamry menu Handle */
new Handle:g_hSecondaryMenu = INVALID_HANDLE; /* Secondary menu Handle */
new Handle:g_hEquipMenu = INVALID_HANDLE; /* Main equipment menu */
new bool:g_IsEnabled = false; /* Whether the plugin should work */
new bool:g_IsAddictionalMenuCmdsEnabled = false; /* Should the menu open for additional commands */
new g_PrimaryChoices[MAXPLAYERS+1]; /* Primary weapon selections */
new g_SecondaryChoices[MAXPLAYERS+1]; /* Secondary weapon selections */
new bool:g_GunMenuEnabled[MAXPLAYERS+1]; /* Whether the gun menu is enabled */
Expand Down Expand Up @@ -96,21 +98,17 @@ public Plugin:myinfo =

public OnPluginStart()
{
new String:game[64];
GetGameFolderName(game, sizeof(game));
if (StrEqual(game, "csgo", false))
{
g_bIsGo = true;
}
g_bIsGo = GetEngineVersion() == Engine_CSGO;

LoadTranslations("cssdm.phrases");

RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say_team", Command_Say);

cssdm_enable_equipment = CreateConVar("cssdm_enable_equipment", "1", "Sets whether the equipment plugin is enabled");
HookConVarChange(cssdm_enable_equipment, OnEquipmentEnableChange);

cssdm_addictional_menu_cmds = CreateConVar("cssdm_addictional_menu_cmds", "0", "Opens menu on autobuy, rebuy, etc. cmds");
HookConVarChange(cssdm_addictional_menu_cmds, OnEquipmentAddictionalMenuCmdsChange);


g_hEquipMenu = CreateMenu(Menu_EquipHandler, MenuAction_DrawItem|MenuAction_DisplayItem);
SetMenuTitle(g_hEquipMenu, "Weapon Options:");
SetMenuExitButton(g_hEquipMenu, false);
Expand All @@ -126,6 +124,11 @@ public OnEquipmentEnableChange(Handle:convar, const String:oldValue[], const Str
g_IsEnabled = StringToInt(newValue) ? true : false;
}

public OnEquipmentAddictionalMenuCmdsChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
g_IsAddictionalMenuCmdsEnabled = StringToInt(newValue) ? true : false;
}

public OnConfigsExecuted()
{
LoadDefaults();
Expand All @@ -146,7 +149,7 @@ public OnConfigsExecuted()
decl String:map[64];
decl String:path[255];
GetCurrentMap(map, sizeof(map));
Format(path, sizeof(path), "cfg/cssdm/maps/%s.equip.txt", map);
FormatEx(path, sizeof(path), "cfg/cssdm/maps/%s.equip.txt", map);

if (FileExists(path))
{
Expand Down Expand Up @@ -354,17 +357,14 @@ public Action:PlayerPostSpawn(Handle:timer, any:client)
return Plugin_Stop;
}

public Action:Command_Say(client, args)
public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
{
if (!ShouldRun())
{
return Plugin_Continue;
}

new String:text[192];
GetCmdArg(1, text, sizeof(text));

if (strcmp(text, "guns") == 0)
if (strcmp(sArgs, "guns") == 0)
{
if (!g_AllowGunCommand)
{
Expand Down Expand Up @@ -414,6 +414,10 @@ public Action:OnClientCommand(client, args)
|| StrEqual(cmd, "buyequip")
|| StrEqual(cmd, "buymenu"))
{
if(g_IsAddictionalMenuCmdsEnabled)
{
OnClientSayCommand(client, "", "guns");
}
return Plugin_Handled;
}

Expand Down Expand Up @@ -505,7 +509,7 @@ public Menu_PrimaryHandler(Handle:menu, MenuAction:action, param1, param2)
new Handle:hPanel = Handle:param2;
decl String:title[128];

Format(title, sizeof(title), "%T:", "Primary weapon", param1);
FormatEx(title, sizeof(title), "%T:", "Primary weapon", param1);

SetPanelTitle(hPanel, title);
}
Expand Down
30 changes: 18 additions & 12 deletions scripting/dm_spawn_protection.sp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ new Handle:g_ProtTimeVar;
new g_NormColor[4] = {255, 255, 255, 255};
new g_TColor[4] = {255, 0, 0, 128};
new g_CTColor[4] = {0, 0, 255, 128};
new g_HealthOffset;
new g_RenderModeOffset;
new g_RenderClrOffset;

/* Player stuff */
new Handle:g_PlayerTimers[MAXPLAYERS+1];
new g_PlayerHealth[MAXPLAYERS+1];

/** PUBLIC INFO */
public Plugin:myinfo =
Expand All @@ -65,7 +63,6 @@ public OnPluginStart()
HookConVarChange(g_CTColorVar, OnColorChange);
HookConVarChange(g_TColorVar, OnColorChange);

g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
g_RenderModeOffset = FindSendPropOffs("CCSPlayer", "m_nRenderMode");
g_RenderClrOffset = FindSendPropOffs("CCSPlayer", "m_clrRender");
}
Expand Down Expand Up @@ -113,7 +110,7 @@ public Action:StopProtection(Handle:timer, any:client)
{
g_PlayerTimers[client] = INVALID_HANDLE;

SetEntData(client, g_HealthOffset, g_PlayerHealth[client]);
SetGodMode(client, false);
UTIL_Render(client, g_NormColor);

return Plugin_Stop;
Expand All @@ -130,17 +127,21 @@ public DM_OnClientPostSpawned(client)

g_PlayerTimers[client] = CreateTimer(GetConVarFloat(g_ProtTimeVar), StopProtection, client);

/* Start protection */
g_PlayerHealth[client] = GetEntData(client, g_HealthOffset);
SetEntData(client, g_HealthOffset, 1012); /* This overflows to show "500" */
SetGodMode(client, true);

new team = GetClientTeam(client);
if (team == CSSDM_TEAM_T)
switch(GetClientTeam(client))
{
UTIL_Render(client, g_TColor);
} else if (team == CSSDM_TEAM_CT) {
UTIL_Render(client, g_CTColor);
case CSSDM_TEAM_T:
{
UTIL_Render(client, g_TColor);
}

case CSSDM_TEAM_CT:
{
UTIL_Render(client, g_CTColor);
}
}

}

UTIL_Render(client, const color[4])
Expand All @@ -151,3 +152,8 @@ UTIL_Render(client, const color[4])
SetEntDataArray(client, g_RenderClrOffset, color, 4, 1);
ChangeEdictState(client);
}

SetGodMode(client, bool:godmode)
{
SetEntProp(client, Prop_Data, "m_takedamage", godmode ? 2 : 0, 1);
}