From 2292bb64f3fc9931eb54b6e11d3d29030ea0c85a Mon Sep 17 00:00:00 2001 From: samyyc <3356207189@qq.com> Date: Thu, 19 Jan 2023 14:49:01 +0800 Subject: [PATCH 1/3] feat: Custom float. --- addons/sourcemod/scripting/weapons.sp | 11 +++++ addons/sourcemod/scripting/weapons/globals.sp | 1 + addons/sourcemod/scripting/weapons/hooks.sp | 40 +++++++++++++++++++ addons/sourcemod/scripting/weapons/menus.sp | 8 ++++ .../translations/chi/weapons.phrases.txt | 20 ++++++++++ .../translations/weapons.phrases.txt | 24 +++++++++-- 6 files changed, 100 insertions(+), 4 deletions(-) diff --git a/addons/sourcemod/scripting/weapons.sp b/addons/sourcemod/scripting/weapons.sp index 0697c0ac..a864542d 100644 --- a/addons/sourcemod/scripting/weapons.sp +++ b/addons/sourcemod/scripting/weapons.sp @@ -302,6 +302,17 @@ public Action CommandNameTag(int client, int args) return Plugin_Handled; } +public Action CommandCustomFloat(int client, int args) +{ + if(!g_bEnableFloat) + { + ReplyToCommand(client, " %s \x02%T", g_ChatPrefix, "FloatDisabled", client); + return Plugin_Handled; + } + ReplyToCommand(client, " %s \x04%T", g_ChatPrefix, "FloatExplanation", client); + return Plugin_Handled; +} + void SetWeaponProps(int client, int entity) { int index = GetWeaponIndex(entity); diff --git a/addons/sourcemod/scripting/weapons/globals.sp b/addons/sourcemod/scripting/weapons/globals.sp index 684f83d6..c8b300c1 100644 --- a/addons/sourcemod/scripting/weapons/globals.sp +++ b/addons/sourcemod/scripting/weapons/globals.sp @@ -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, ... }; diff --git a/addons/sourcemod/scripting/weapons/hooks.sp b/addons/sourcemod/scripting/weapons/hooks.sp index b494c7e8..b2925d3d 100644 --- a/addons/sourcemod/scripting/weapons/hooks.sp +++ b/addons/sourcemod/scripting/weapons/hooks.sp @@ -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; } diff --git a/addons/sourcemod/scripting/weapons/menus.sp b/addons/sourcemod/scripting/weapons/menus.sp index aff712b0..f7908551 100644 --- a/addons/sourcemod/scripting/weapons/menus.sp +++ b/addons/sourcemod/scripting/weapons/menus.sp @@ -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; @@ -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: diff --git a/addons/sourcemod/translations/chi/weapons.phrases.txt b/addons/sourcemod/translations/chi/weapons.phrases.txt index 229c2946..d5b54f45 100644 --- a/addons/sourcemod/translations/chi/weapons.phrases.txt +++ b/addons/sourcemod/translations/chi/weapons.phrases.txt @@ -28,6 +28,26 @@ { "chi" "减少 %d%%" } + "CustomFloat" + { + "chi" "输入指定磨损" + } + "CustomFloatInstruction" + { + "chi" "请将你希望设置的磨损输入至聊天框。如需取消,请输入 !cancel 。" + } + "CustomFloatCancelled" + { + "chi" "输入磨损已取消。" + } + "CustomFloatFailed" + { + "chi" "无效的磨损 (0-1)。" + } + "CustomFloatSuccess" + { + "chi" "指定磨损已设置" + } "NameTagColor" { "chi" "设置名称标签颜色" diff --git a/addons/sourcemod/translations/weapons.phrases.txt b/addons/sourcemod/translations/weapons.phrases.txt index 1595c746..0cc425fb 100644 --- a/addons/sourcemod/translations/weapons.phrases.txt +++ b/addons/sourcemod/translations/weapons.phrases.txt @@ -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 to choose a name tag for your current weapon!" @@ -96,10 +116,6 @@ { "en" "★ Your own knife" } - "RandomKnife" - { - "en" "★ Random knife" - } "SetSkin" { "en" "Choose Skin" From d12c9f85babe83f509cf15859d48bd643e7e832c Mon Sep 17 00:00:00 2001 From: samyyc0508 <3356207189@qq.com> Date: Thu, 19 Jan 2023 15:01:29 +0800 Subject: [PATCH 2/3] fix: accidently delete a translation. --- addons/sourcemod/translations/weapons.phrases.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/sourcemod/translations/weapons.phrases.txt b/addons/sourcemod/translations/weapons.phrases.txt index 0cc425fb..db22bf93 100644 --- a/addons/sourcemod/translations/weapons.phrases.txt +++ b/addons/sourcemod/translations/weapons.phrases.txt @@ -116,6 +116,10 @@ { "en" "★ Your own knife" } + "RandomKnife" + { + "en" "★ Random knife" + } "SetSkin" { "en" "Choose Skin" From bd21fabf0634d88443a44f8728ca7a8596aaaa23 Mon Sep 17 00:00:00 2001 From: samyyc0508 <3356207189@qq.com> Date: Thu, 19 Jan 2023 15:09:49 +0800 Subject: [PATCH 3/3] remove unused code. --- addons/sourcemod/scripting/weapons.sp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/addons/sourcemod/scripting/weapons.sp b/addons/sourcemod/scripting/weapons.sp index a864542d..0697c0ac 100644 --- a/addons/sourcemod/scripting/weapons.sp +++ b/addons/sourcemod/scripting/weapons.sp @@ -302,17 +302,6 @@ public Action CommandNameTag(int client, int args) return Plugin_Handled; } -public Action CommandCustomFloat(int client, int args) -{ - if(!g_bEnableFloat) - { - ReplyToCommand(client, " %s \x02%T", g_ChatPrefix, "FloatDisabled", client); - return Plugin_Handled; - } - ReplyToCommand(client, " %s \x04%T", g_ChatPrefix, "FloatExplanation", client); - return Plugin_Handled; -} - void SetWeaponProps(int client, int entity) { int index = GetWeaponIndex(entity);