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

Custom float #261

Merged
merged 3 commits into from
May 23, 2023
Merged
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
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/weapons/globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Handle g_FloatTimer[MAXPLAYERS+1] = { INVALID_HANDLE, ... };

bool g_bWaitingForNametag[MAXPLAYERS+1] = { false, ... };
bool g_bWaitingForSeed[MAXPLAYERS+1] = { false, ... };
bool g_bWaitingForFloat[MAXPLAYERS+1] = { false, ... };
int g_iSeedRandom[MAXPLAYERS+1][sizeof(g_WeaponClasses)];

int g_iKnife[MAXPLAYERS+1] = { 0, ... };
Expand Down
40 changes: 40 additions & 0 deletions addons/sourcemod/scripting/weapons/hooks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,46 @@ public Action ChatListener(int client, const char[] command, int args)

return Plugin_Handled;
}
else if (g_bWaitingForFloat[client] && IsValidClient(client) && g_iIndex[client] > -1 && !IsChatTrigger())
{
g_bWaitingForFloat[client] = false;

float customFloat;
if (StrEqual(msg, "!cancel") || StrEqual(msg, "!iptal") || StrEqual(msg, ""))
{
PrintToChat(client, " %s \x02%t", g_ChatPrefix, "CustomFloatCancelled");
return Plugin_Handled;
}
else if ((customFloat = StringToFloat(msg)) < 0 || customFloat >= 1)
{
PrintToChat(client, " %s \x02%t", g_ChatPrefix, "CustomFloatFailed");
return Plugin_Handled;
}
g_fFloatValue[client][g_iIndex[client]] = customFloat;
if(g_fFloatValue[client][g_iIndex[client]] < 0.0)
{
g_fFloatValue[client][g_iIndex[client]] = 0.0;
}
if(g_FloatTimer[client] != INVALID_HANDLE)
{
KillTimer(g_FloatTimer[client]);
g_FloatTimer[client] = INVALID_HANDLE;
}

DataPack pack;
g_FloatTimer[client] = CreateDataTimer(1.0, FloatTimer, pack);
pack.WriteCell(GetClientUserId(client));
pack.WriteCell(g_iIndex[client]);
int menuTime;
if((menuTime = GetRemainingGracePeriodSeconds(client)) >= 0)
{
CreateFloatMenu(client).Display(client, menuTime);
}

PrintToChat(client, " %s \x04%t: \x01%f", g_ChatPrefix, "CustomFloatSuccess", customFloat);

return Plugin_Handled;
}

return Plugin_Continue;
}
Expand Down
8 changes: 8 additions & 0 deletions addons/sourcemod/scripting/weapons/menus.sp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ Menu CreateFloatMenu(int client)
Format(buffer, sizeof(buffer), "%T", "Decrease", client, g_iFloatIncrementPercentage);
menu.AddItem("decrease", buffer, wear == 0 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);

Format(buffer, sizeof(buffer), "%T", "CustomFloat", client);
menu.AddItem("custom", buffer, ITEMDRAW_DEFAULT);

menu.ExitBackButton = true;

return menu;
Expand Down Expand Up @@ -261,6 +264,11 @@ public int FloatMenuHandler(Menu menu, MenuAction action, int client, int select
CreateFloatMenu(client).Display(client, menuTime);
}
}
else if(StrEqual(buffer, "custom"))
{
g_bWaitingForFloat[client] = true;
PrintToChat(client, " %s \x04%t", g_ChatPrefix, "CustomFloatInstruction");
}
}
}
case MenuAction_Cancel:
Expand Down
20 changes: 20 additions & 0 deletions addons/sourcemod/translations/chi/weapons.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
{
"chi" "减少 %d%%"
}
"CustomFloat"
{
"chi" "输入指定磨损"
}
"CustomFloatInstruction"
{
"chi" "请将你希望设置的磨损输入至聊天框。如需取消,请输入 !cancel 。"
}
"CustomFloatCancelled"
{
"chi" "输入磨损已取消。"
}
"CustomFloatFailed"
{
"chi" "无效的磨损 (0-1)。"
}
"CustomFloatSuccess"
{
"chi" "指定磨损已设置"
}
"NameTagColor"
{
"chi" "设置名称标签颜色"
Expand Down
20 changes: 20 additions & 0 deletions addons/sourcemod/translations/weapons.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
{
"en" "Decrease by %d%%"
}
"CustomFloat"
{
"en" "Input a custom float"
}
"CustomFloatInstruction"
{
"en" "Write your desired float into chat. To abort, type !cancel."
}
"CustomFloatCancelled"
{
"en" "Custom float operation aborted."
}
"CustomFloatFailed"
{
"en" "Invalid float (0-1)."
}
"CustomFloatSuccess"
{
"en" "Custom float successfully applied"
}
"NameTagInfo"
{
"en" "Use !nametag <tag> to choose a name tag for your current weapon!"
Expand Down