forked from UNLOZE/sm-plugins
PropSpawner: Added a menu option and cmd to choose your prop's color
This commit is contained in:
@@ -17,6 +17,7 @@ Menu g_RotationMenu = null;
|
|||||||
Menu g_PhysicMenu = null;
|
Menu g_PhysicMenu = null;
|
||||||
Menu g_DynamicMenu = null;
|
Menu g_DynamicMenu = null;
|
||||||
Menu g_NpcMenu = null;
|
Menu g_NpcMenu = null;
|
||||||
|
Menu g_ColorMenu = null;
|
||||||
|
|
||||||
KeyValues g_Models;
|
KeyValues g_Models;
|
||||||
|
|
||||||
@@ -26,12 +27,52 @@ ConVar g_cvNotifyTimer;
|
|||||||
ArrayList g_aSpawnedProps; // Tracks entity indices of props spawned by this plugin so we can unhook them
|
ArrayList g_aSpawnedProps; // Tracks entity indices of props spawned by this plugin so we can unhook them
|
||||||
ArrayList g_aNotifyList;
|
ArrayList g_aNotifyList;
|
||||||
|
|
||||||
|
int g_aPlayerPropColor[MAXPLAYERS + 1][3];
|
||||||
|
|
||||||
enum struct NotifyListData
|
enum struct NotifyListData
|
||||||
{
|
{
|
||||||
int client;
|
int client;
|
||||||
Handle timer;
|
Handle timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PropColors_Default,
|
||||||
|
PropColors_Black,
|
||||||
|
PropColors_Red,
|
||||||
|
PropColors_Purple,
|
||||||
|
PropColors_Blue,
|
||||||
|
PropColors_Green,
|
||||||
|
PropColors_Yellow,
|
||||||
|
PropColors_Orange,
|
||||||
|
PropColors_Rainbow,
|
||||||
|
PropColors_Count
|
||||||
|
}
|
||||||
|
|
||||||
|
char ColorToString[PropColors_Count][] = {
|
||||||
|
"Default",
|
||||||
|
"Black",
|
||||||
|
"Red",
|
||||||
|
"Purple",
|
||||||
|
"Blue",
|
||||||
|
"Green",
|
||||||
|
"Yellow",
|
||||||
|
"Orange",
|
||||||
|
"Rainbow"
|
||||||
|
};
|
||||||
|
|
||||||
|
int ColorToRGB[PropColors_Count][3] = {
|
||||||
|
{255, 255, 255},
|
||||||
|
{0, 0, 0},
|
||||||
|
{255, 0, 0},
|
||||||
|
{128, 0, 128},
|
||||||
|
{0, 0, 255},
|
||||||
|
{0, 255, 0},
|
||||||
|
{255, 255, 0},
|
||||||
|
{255, 165, 0},
|
||||||
|
{256, 256, 256}
|
||||||
|
};
|
||||||
|
|
||||||
public void OnPluginStart()
|
public void OnPluginStart()
|
||||||
{
|
{
|
||||||
LoadTranslations("common.phrases");
|
LoadTranslations("common.phrases");
|
||||||
@@ -54,6 +95,7 @@ public void OnPluginStart()
|
|||||||
g_Models.Rewind(); // Go back to the root node
|
g_Models.Rewind(); // Go back to the root node
|
||||||
|
|
||||||
RegAdminCmd("sm_propspawner", Command_MainMenu, ADMFLAG_CHANGEMAP); //g
|
RegAdminCmd("sm_propspawner", Command_MainMenu, ADMFLAG_CHANGEMAP); //g
|
||||||
|
RegAdminCmd("sm_setpropcolor", Command_SetPropColor, ADMFLAG_CHANGEMAP, "Set PropSpawner color by RGB value, or \"rainbow\" for that.");
|
||||||
|
|
||||||
g_cvNotifyShot = CreateConVar("sm_propspawner_notify_shot", "0", "If set to 1, announces in chat when a plugin-spawned prop is shot.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
|
g_cvNotifyShot = CreateConVar("sm_propspawner_notify_shot", "0", "If set to 1, announces in chat when a plugin-spawned prop is shot.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
|
||||||
g_cvNotifyTimer = CreateConVar("sm_propspawner_notify_shot_timer", "0.5", "How long a player stays in the \"shooting couch\" list.");
|
g_cvNotifyTimer = CreateConVar("sm_propspawner_notify_shot_timer", "0.5", "How long a player stays in the \"shooting couch\" list.");
|
||||||
@@ -109,6 +151,7 @@ public void OnMapStart()
|
|||||||
g_PhysicMenu = BuildModelsMenu("physic");
|
g_PhysicMenu = BuildModelsMenu("physic");
|
||||||
g_DynamicMenu = BuildModelsMenu("dynamic");
|
g_DynamicMenu = BuildModelsMenu("dynamic");
|
||||||
g_NpcMenu = BuildModelsMenu("npc");
|
g_NpcMenu = BuildModelsMenu("npc");
|
||||||
|
g_ColorMenu = BuildColorMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMapEnd()
|
public void OnMapEnd()
|
||||||
@@ -152,6 +195,7 @@ Menu BuildMainMenu(){
|
|||||||
menu.AddItem("menu_prop_dynamic", "Dynamic/Static Props");
|
menu.AddItem("menu_prop_dynamic", "Dynamic/Static Props");
|
||||||
menu.AddItem("menu_prop_physic", "Physic Props");
|
menu.AddItem("menu_prop_physic", "Physic Props");
|
||||||
menu.AddItem("menu_prop_npc", "NPCs");
|
menu.AddItem("menu_prop_npc", "NPCs");
|
||||||
|
menu.AddItem("menu_prop_color", "Choose Color");
|
||||||
menu.ExitButton = true;
|
menu.ExitButton = true;
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
@@ -202,6 +246,20 @@ Menu BuildModelsMenu(char[] modelType){
|
|||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Menu BuildColorMenu()
|
||||||
|
{
|
||||||
|
Menu menu = new Menu(ColorHandler);
|
||||||
|
SetMenuTitle(menu, "Choose Prop Color");
|
||||||
|
for (int i = 0; i < PropColors_Count; i++)
|
||||||
|
{
|
||||||
|
menu.AddItem(ColorToString[i], ColorToString[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.ExitBackButton = true;
|
||||||
|
menu.ExitButton = true;
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------- */
|
/* ----------------------------------- */
|
||||||
|
|
||||||
public Action Command_MainMenu(int client, int args)
|
public Action Command_MainMenu(int client, int args)
|
||||||
@@ -210,6 +268,35 @@ public Action Command_MainMenu(int client, int args)
|
|||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action Command_SetPropColor(int client, int args)
|
||||||
|
{
|
||||||
|
if (args < 3)
|
||||||
|
{
|
||||||
|
if (args != 0)
|
||||||
|
{
|
||||||
|
char buf[32];
|
||||||
|
GetCmdArg(1, buf, sizeof(buf));
|
||||||
|
if (StrEqual(buf, "rainbow", false))
|
||||||
|
{
|
||||||
|
g_aPlayerPropColor[client][0] = 256;
|
||||||
|
ReplyToCommand(client, "\x01[SM] Changed color to \x04Rainbow\x01.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "Usage: sm_setpropcolor <r> <g> <b>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
int r = g_aPlayerPropColor[client][0] = GetCmdArgInt(1) % 256;
|
||||||
|
int g = g_aPlayerPropColor[client][1] = GetCmdArgInt(2) % 256;
|
||||||
|
int b = g_aPlayerPropColor[client][2] = GetCmdArgInt(3) % 256;
|
||||||
|
ReplyToCommand(client, "\x01[SM] Changed color to \x07%02x%02x%02x%d %d %d\x01.", r, g, b, r, g, b);
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
public int MainMenuHandler(Menu menu, MenuAction action, int client, int param2)
|
public int MainMenuHandler(Menu menu, MenuAction action, int client, int param2)
|
||||||
{
|
{
|
||||||
char info[32];
|
char info[32];
|
||||||
@@ -233,6 +320,9 @@ public int MainMenuHandler(Menu menu, MenuAction action, int client, int param2)
|
|||||||
else if(StrEqual(info, "menu_prop_npc")){
|
else if(StrEqual(info, "menu_prop_npc")){
|
||||||
g_NpcMenu.Display(client, MENU_TIME_FOREVER);
|
g_NpcMenu.Display(client, MENU_TIME_FOREVER);
|
||||||
}
|
}
|
||||||
|
else if(StrEqual(info, "menu_prop_color")){
|
||||||
|
g_ColorMenu.Display(client, MENU_TIME_FOREVER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -361,6 +451,37 @@ public NpcHandler(Menu menu, MenuAction action, int client, int param2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ColorHandler(Menu menu, MenuAction action, int client, int param2)
|
||||||
|
{
|
||||||
|
char info[32];
|
||||||
|
menu.GetItem(param2, info, sizeof(info));
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case MenuAction_Select:
|
||||||
|
{
|
||||||
|
int colorIdx = -1;
|
||||||
|
for (int i = 0; i < PropColors_Count; i++)
|
||||||
|
{
|
||||||
|
if (StrEqual(ColorToString[i], info))
|
||||||
|
{
|
||||||
|
colorIdx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colorIdx != -1)
|
||||||
|
{
|
||||||
|
g_aPlayerPropColor[client] = ColorToRGB[colorIdx];
|
||||||
|
ReplyToCommand(client, "\x01[SM] Changed color to \x04%s\x01.", info);
|
||||||
|
g_MainMenu.Display(client, MENU_TIME_FOREVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case MenuAction_Cancel:
|
||||||
|
if (param2 == MenuCancel_ExitBack)
|
||||||
|
g_MainMenu.Display(client, MENU_TIME_FOREVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool isAProp(char[] classname){
|
bool isAProp(char[] classname){
|
||||||
if(StrEqual(classname, "prop_physics") || StrEqual(classname, "prop_physics_override") || StrEqual(classname, "prop_dynamic") || StrEqual(classname, "prop_dynamic_override") || StrEqual(classname, "prop_physics_multiplayer") || StrEqual(classname, "prop_dynamic_ornament") || StrEqual(classname, "prop_static")){
|
if(StrEqual(classname, "prop_physics") || StrEqual(classname, "prop_physics_override") || StrEqual(classname, "prop_dynamic") || StrEqual(classname, "prop_dynamic_override") || StrEqual(classname, "prop_physics_multiplayer") || StrEqual(classname, "prop_dynamic_ornament") || StrEqual(classname, "prop_static")){
|
||||||
@@ -548,7 +669,7 @@ void prop_any_create(int client)
|
|||||||
TeleportEntity(prop, VecOrigin, normal, NULL_VECTOR);
|
TeleportEntity(prop, VecOrigin, normal, NULL_VECTOR);
|
||||||
AcceptEntityInput(prop, "TurnOn", prop, prop, 0);
|
AcceptEntityInput(prop, "TurnOn", prop, prop, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchSpawn(prop);
|
DispatchSpawn(prop);
|
||||||
AcceptEntityInput(prop, "TurnOn", prop, prop, 0);
|
AcceptEntityInput(prop, "TurnOn", prop, prop, 0);
|
||||||
AcceptEntityInput(prop, "EnableCollision");
|
AcceptEntityInput(prop, "EnableCollision");
|
||||||
@@ -560,6 +681,17 @@ void prop_any_create(int client)
|
|||||||
SDKHook(prop, SDKHook_OnTakeDamage, OnPropTakeDamage);
|
SDKHook(prop, SDKHook_OnTakeDamage, OnPropTakeDamage);
|
||||||
g_aSpawnedProps.Push(prop);
|
g_aSpawnedProps.Push(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetEntityRenderMode(prop, RENDER_TRANSCOLOR);
|
||||||
|
if (g_aPlayerPropColor[client][0] == 256) // Rainbow
|
||||||
|
{
|
||||||
|
CreateTimer(0.2, OnRainbowTimer, EntIndexToEntRef(prop), TIMER_REPEAT);
|
||||||
|
ApplyRainbow(prop, 1.0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetEntityRenderColor(prop, g_aPlayerPropColor[client][0], g_aPlayerPropColor[client][1], g_aPlayerPropColor[client][2], 255);
|
||||||
|
}
|
||||||
|
|
||||||
ShowActivity2(client, "\x01[SM] \x04", "\x01Spawned \x04%s\x01.", sModelName);
|
ShowActivity2(client, "\x01[SM] \x04", "\x01Spawned \x04%s\x01.", sModelName);
|
||||||
LogAction(client, -1, "\"%L\" Spawned \"%s\".", client, sModelName);
|
LogAction(client, -1, "\"%L\" Spawned \"%s\".", client, sModelName);
|
||||||
@@ -657,3 +789,32 @@ int FindInNotifyList(int client)
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnClientPutInServer(int client)
|
||||||
|
{
|
||||||
|
g_aPlayerPropColor[client] = {255, 255, 255};
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnRainbowTimer(Handle timer, any data)
|
||||||
|
{
|
||||||
|
int prop = EntRefToEntIndex(view_as<int>(data));
|
||||||
|
if (prop == -1)
|
||||||
|
{
|
||||||
|
KillTimer(timer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyRainbow(prop, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from GlowColors
|
||||||
|
void ApplyRainbow(int ent, float Frequency)
|
||||||
|
{
|
||||||
|
float i = GetGameTime();
|
||||||
|
|
||||||
|
int Red = RoundFloat(Sine(Frequency * i + 0.0) * 127.0 + 128.0);
|
||||||
|
int Green = RoundFloat(Sine(Frequency * i + 2.0943951) * 127.0 + 128.0);
|
||||||
|
int Blue = RoundFloat(Sine(Frequency * i + 4.1887902) * 127.0 + 128.0);
|
||||||
|
|
||||||
|
SetEntityRenderColor(ent, Red, Green, Blue, 255);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user