If you find yourself writing the same code repeatedly, extract a method out of it... find the things that change, make them variables, then move the code to a method that takes those variables. For instance:
PHP Code:
/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
name = "New Plugin",
author = "Unknown",
description = "<- Description ->",
version = "1.0",
url = "<- URL ->"
}
public OnPluginStart()
{
RegAdminCmd("sm_bm_on", Command_One, ADMFLAG_SLAY, "");
RegAdminCmd("sm_bm_off", Command_Two, ADMFLAG_SLAY, "");
RegAdminCmd("sm_rm_on", Command_Three, ADMFLAG_SLAY, "");
RegAdminCmd("sm_rm_off", Command_Four, ADMFLAG_SLAY, "");
}
public Action:Command_One(client, args)
{
SetValue("bsm", 1);
return Plugin_Handled;
}
public Action:Command_Two(client, args)
{
SetValue("bsm", 0);
return Plugin_Handled;
}
public Action:Command_Three(client, args)
{
SetValue("rsm", 1);
return Plugin_Handled;
}
public Action:Command_Four(client, args)
{
SetValue("rsm", 0);
return Plugin_Handled;
}
SetValue(const String:name[], value)
{
new entity = -1;
while ((entity = FindEntityByClassname(entity, "logic_branch"))!=INVALID_ENT_REFERENCE)
{
new String:entName[MAX_NAME_LENGTH];
GetEntPropString(entity, Prop_Data, "m_iName", entName, sizeof(entName));
if(StrEqual(entName, name))
{
SetVariantInt(value);
AcceptEntityInput(entity, "SetValueTest");
break;
}
}
}
Note: I left it as SetVariantInt and the type as a number, because I wasn't sure if should be a bool or not.
I also included Tylerst's fix as noted in the previous post.
__________________