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

admin2: automatic scripts #259

Closed
wants to merge 2 commits into from
Closed
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
147 changes: 147 additions & 0 deletions [admin]/admin2/client/main/admin_automatic-scripts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* client\main\admin_server.lua
*
* Original File by lil_Toady
*
**************************************]]
addEvent("aOnAutomaticScriptChange", true)
addEvent("aReceiveAutoScripts", true)

local aAutoScripts = {}

aAutoScripts["pingkicker"] = {
state = nil,
timer = nil,
limit = 300,
checkInterval = 3000,
toggle = function(state)
if isElement(aServerTab.PingKickerCheck) then
guiCheckBoxSetSelected(aServerTab.PingKickerCheck, state)
end
if isElement(aServerTab.PingKicker) then
guiSetText(aServerTab.PingKicker, aAutoScripts["pingkicker"].limit)
end
end,
execute = function()
local myPing = getPlayerPing(localPlayer)
if (myPing > aAutoScripts["pingkicker"].limit) then
triggerServerEvent("aAutomaticScriptKick", localPlayer, ("ping exceeded the limit (%i > %i)"):format(myPing, aAutoScripts["pingkicker"].limit))
end
end
}

aAutoScripts["fpskicker"] = {
state = nil,
timer = nil,
limit = 10,
checkInterval = 3000,
toggle = function(state)
if isElement(aServerTab.FPSKickerCheck) then
guiCheckBoxSetSelected(aServerTab.FPSKickerCheck, state)
end
if isElement(aServerTab.FPSKicker) then
guiSetText(aServerTab.FPSKicker, aAutoScripts["fpskicker"].limit)
end
end,
execute = function()
local myFPS = getCurrentFPS(localPlayer)
if (myFPS < aAutoScripts["fpskicker"].limit) then
triggerServerEvent("aAutomaticScriptKick", localPlayer, ("fps below the limit (%i < %i)"):format(myFPS, aAutoScripts["fpskicker"].limit))
end
end
}

aAutoScripts["idlekicker"] = {
state = nil,
timer = nil,
limit = 60,
checkInterval = 3000,
lastAction = getTickCount(),
toggle = function(state)
if isElement(aServerTab.IdleKickerCheck) then
guiCheckBoxSetSelected(aServerTab.IdleKickerCheck, state)
end
if isElement(aServerTab.IdleKicker) then
guiSetText(aServerTab.IdleKicker, aAutoScripts["idlekicker"].limit)
end
end,
execute = function()
local idleTime = (getTickCount() - aAutoScripts["idlekicker"].lastAction)
local max = aAutoScripts["idlekicker"].limit * 60000
if (idleTime > max) then
triggerServerEvent("aAutomaticScriptKick", localPlayer, ("more than %i minutes afk"):format(aAutoScripts["idlekicker"].limit))
end
end
}

function toggleAutomaticScript(scriptName, state)
if (not aAutoScripts[scriptName]) then
return false
end
if (state == aAutoScripts[scriptName].state) then
return false
end
if state then
aAutoScripts[scriptName].timer = setTimer(aAutoScripts[scriptName].execute, aAutoScripts[scriptName].checkInterval, 0)
else
if isTimer(aAutoScripts[scriptName].timer) then
killTimer(aAutoScripts[scriptName].timer)
end
aAutoScripts[scriptName].timer = nil
end
aAutoScripts[scriptName].state = state
end

function getAutomaticScriptInfo(scriptName, info)
return aAutoScripts[scriptName] and aAutoScripts[scriptName][info] or false
end

addEventHandler(
"aOnAutomaticScriptChange",
resourceRoot,
function(scriptName, info)
if (not aAutoScripts[scriptName]) then
return false
end
aAutoScripts[scriptName].limit = info.limit
toggleAutomaticScript(scriptName, info.state)
end
)
addEventHandler(
"aReceiveAutoScripts",
localPlayer,
function(info)
for k, v in pairs(info) do
if aAutoScripts[k] then
aAutoScripts[k].limit = v.limit
toggleAutomaticScript(k, v.state)
end
end
end
)
addEventHandler(
"onClientResourceStart",
resourceRoot,
function()
triggerServerEvent("aRequestAutomaticScripts", resourceRoot)
end
)

local fps = 0

function getCurrentFPS()
return fps
end

addEventHandler("onClientPreRender", root, function(delta)
fps = (1 / delta) * 1000
end)

local function detectAction()
aAutoScripts["idlekicker"].lastAction = getTickCount()
end
addEventHandler("onClientKey", root, detectAction)
addEventHandler("onClientCursorMove", root, detectAction)
57 changes: 42 additions & 15 deletions [admin]/admin2/client/main/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,19 @@ function aServerTab.Create(tab)

guiCreateHeader(0.02, 0.755, 0.30, 0.035, "Automatic scripts:", true, tab)
aServerTab.PingKickerCheck =
guiCreateCheckBox(0.03, 0.800, 0.30, 0.04, "Ping Kicker", false, true, tab, "setpingkicker")
aServerTab.PingKicker = guiCreateEdit(0.35, 0.800, 0.135, 0.04, "300", true, tab)
aServerTab.PingKickerSet = guiCreateButton(0.50, 0.800, 0.10, 0.04, "Set", true, tab, "setpingkicker")
guiSetEnabled(aServerTab.PingKicker, false)
guiSetEnabled(aServerTab.PingKickerSet, false)
guiCreateCheckBox(0.03, 0.780, 0.30, 0.04, "Ping Kicker (maximum)", getAutomaticScriptInfo('pingkicker', 'state'), true, tab, "setpingkicker")
aServerTab.PingKicker = guiCreateEdit(0.35, 0.780, 0.135, 0.04, getAutomaticScriptInfo('pingkicker', 'limit'), true, tab)
aServerTab.PingKickerSet = guiCreateButton(0.50, 0.780, 0.10, 0.04, "Set", true, tab, "setpingkicker")

aServerTab.FPSKickerCheck =
guiCreateCheckBox(0.03, 0.845, 0.30, 0.04, "FPS Kicker", false, true, tab, "setfpskicker")
aServerTab.FPSKicker = guiCreateEdit(0.35, 0.845, 0.135, 0.04, "5", true, tab)
aServerTab.FPSKickerSet = guiCreateButton(0.50, 0.845, 0.10, 0.04, "Set", true, tab, "setfpskicker")
guiSetEnabled(aServerTab.FPSKicker, false)
guiSetEnabled(aServerTab.FPSKickerSet, false)
guiCreateCheckBox(0.03, 0.825, 0.30, 0.04, "FPS Kicker (minimum)", getAutomaticScriptInfo('fpskicker', 'state'), true, tab, "setfpskicker")
aServerTab.FPSKicker = guiCreateEdit(0.35, 0.825, 0.135, 0.04, getAutomaticScriptInfo('fpskicker', 'limit'), true, tab)
aServerTab.FPSKickerSet = guiCreateButton(0.50, 0.825, 0.10, 0.04, "Set", true, tab, "setfpskicker")

aServerTab.IdleKickerCheck =
guiCreateCheckBox(0.03, 0.890, 0.30, 0.04, "Idle Kicker", false, true, tab, "setidlekicker")
aServerTab.IdleKicker = guiCreateEdit(0.35, 0.890, 0.135, 0.04, "10", true, tab)
aServerTab.IdleKickerSet = guiCreateButton(0.50, 0.890, 0.10, 0.04, "Set", true, tab, "setidlekicker")
guiSetEnabled(aServerTab.IdleKicker, false)
guiSetEnabled(aServerTab.IdleKickerSet, false)
guiCreateCheckBox(0.03, 0.870, 0.30, 0.04, "Idle Kicker (minutes)", getAutomaticScriptInfo('idlekicker', 'state'), true, tab, "setidlekicker")
aServerTab.IdleKicker = guiCreateEdit(0.35, 0.870, 0.135, 0.04, getAutomaticScriptInfo('idlekicker', 'limit'), true, tab)
aServerTab.IdleKickerSet = guiCreateButton(0.50, 0.870, 0.10, 0.04, "Set", true, tab, "setidlekicker")

guiCreateHeader(0.65, 0.015, 0.30, 0.035, "Allowed glitches:", true, tab)
local i = 1
Expand Down Expand Up @@ -266,6 +260,39 @@ function aServerTab.onClientClick(button)
triggerServerEvent("aServer", getLocalPlayer(), "setfpslimit", 36) -- 36 is default
guiSetText(aServerTab.FPS, 36)
end
elseif (source == aServerTab.PingKickerSet) then
local pinglimit = tonumber(guiGetText(aServerTab.PingKicker))
if pinglimit then
triggerServerEvent("aServer", getLocalPlayer(), "setpingkicker", pinglimit)
else
triggerServerEvent("aServer", getLocalPlayer(), "setpingkicker", 300) -- 300 is default
guiSetText(aServerTab.PingKicker, 300)
end
elseif (source == aServerTab.PingKickerCheck) then
local state = guiCheckBoxGetSelected(aServerTab.PingKickerCheck)
triggerServerEvent("aServer", getLocalPlayer(), "togglepingkicker", state)
elseif (source == aServerTab.FPSKickerSet) then
local fpslimit = tonumber(guiGetText(aServerTab.FPSKicker))
if fpslimit then
triggerServerEvent("aServer", getLocalPlayer(), "setfpskicker", fpslimit)
else
triggerServerEvent("aServer", getLocalPlayer(), "setfpskicker", 10) -- 10 is default
guiSetText(aServerTab.FPSKicker, 10)
end
elseif (source == aServerTab.FPSKickerCheck) then
local state = guiCheckBoxGetSelected(aServerTab.FPSKickerCheck)
triggerServerEvent("aServer", getLocalPlayer(), "togglefpskicker", state)
elseif (source == aServerTab.IdleKickerSet) then
local idlelimit = tonumber(guiGetText(aServerTab.IdleKicker))
if idlelimit then
triggerServerEvent("aServer", getLocalPlayer(), "setidlekicker", idlelimit)
else
triggerServerEvent("aServer", getLocalPlayer(), "setidlekicker", 60) -- 60 is default
guiSetText(aServerTab.IdleKicker, 60)
end
elseif (source == aServerTab.IdleKickerCheck) then
local state = guiCheckBoxGetSelected(aServerTab.IdleKickerCheck)
triggerServerEvent("aServer", getLocalPlayer(), "toggleidlekicker", state)
elseif (source == aServerTab.QuickReload) then
triggerServerEvent(
"aServer",
Expand Down
34 changes: 27 additions & 7 deletions [admin]/admin2/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<script src="server/admin_ip2c.lua" type="server" />
<script src="server/admin_ACL.lua" type="server" />
<script src="server/admin_bans.lua" type="server" />
<script src="server/admin_automatic-scripts.lua" type="server" />
<script src="server/admin_network.lua" type="server" />
<script src="server/admin_messagebox.lua" type="server" />
<script src="server/admin_screenshot.lua" type="server" />
Expand All @@ -57,6 +58,7 @@
<script src="client/main/admin_network.lua" type="client" />
<script src="client/main/admin_options.lua" type="client" />
<script src="client/main/admin_acl.lua" type="client" />
<script src="client/main/admin_automatic-scripts.lua" type="client" />
<script src="client/main/admin_map.lua" type="client" />
<script src="client/widgets/admin_messagebox.lua" type="client" />
<script src="client/widgets/admin_inputbox.lua" type="client" />
Expand Down Expand Up @@ -250,23 +252,41 @@
<file src="client/images/flags/za.png" />

<settings>
<setting name="#pingkicker" value="0"
<setting name="#pingkicker" value="[300]"
group="Automatic scripts"
friendlyname="Ping kicker"
accept="0-1000"
desc="Max ping allowed (0 - off)"
desc="Max ping allowed (0 - 300)"
/>
<setting name="#fpskicker" value="0"
<setting name="#pingkicker_state" value="[false]"
group="Automatic scripts"
friendlyname="Ping kicker enabled?"
accept="[true], [false]"
desc="The ping kicker current state."
/>
<setting name="#fpskicker" value="10"
group="Automatic scripts"
friendlyname="FPS kicker"
accept="0-100"
desc="Lowest fps allowed: 25-75 (0 - off)"
desc="Lowest fps allowed (0 - 100)"
/>
<setting name="#fpskicker_state" value="[false]"
group="Automatic scripts"
friendlyname="FPS kicker enabled?"
accept="[true], [false]"
desc="The fps kicker current state."
/>
<setting name="#idlekicker" value="0"
<setting name="#idlekicker" value="60"
group="Automatic scripts"
friendlyname="Idle Kicker"
accept="0-100"
desc="Maximum time a player can stay idle (minutes, 0 - off)."
accept="1-1000"
desc="Maximum time a player can stay idle (in minutes)."
/>
<setting name="#idlekicker_state" value="[false]"
group="Automatic scripts"
friendlyname="Idle kicker enabled?"
accept="[true], [false]"
desc="The idle kicker current state."
/>
<setting name="#consolecommands" value="[true]"
group="General"
Expand Down
100 changes: 100 additions & 0 deletions [admin]/admin2/server/admin_automatic-scripts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* server/admin_automatic-scripts.lua
*
* Original File by lil_Toady
*
**************************************]]

addEvent("aRequestAutomaticScripts", true)
addEvent("aAutomaticScriptKick", true)

local aAllScripts = {"pingkicker", "fpskicker", "idlekicker"}

local aAutoScripts = {}

for k, v in pairs(aAllScripts) do
aAutoScripts[v] = {
toggle = function(state, onStart)
if (state == get(("#%s_state"):format(v))) then
return false
end
if set(("#%s_state"):format(v), state) then
if (not onStart) then
triggerClientEvent(root, "aOnAutomaticScriptChange", resourceRoot, v, {
state = get(("#%s_state"):format(v)),
limit = get(("#%s"):format(v)),
})
end
return true
end
return false
end,
changeValue = function(newValue)
if (newValue == get(("#%s"):format(v))) then
return false
end
triggerClientEvent(root, "aOnAutomaticScriptChange", resourceRoot, v, {
state = get(("#%s_state"):format(v)),
limit = get(("#%s"):format(v)),
})
end
}
end

function toggleAutomaticScript(scriptName, state, onStart)
if (not aAutoScripts[scriptName]) or (not aAutoScripts[scriptName].toggle) then
return false
end
return aAutoScripts[scriptName].toggle(state, onStart)
end

function changeAutomaticScriptValue(scriptName, newValue)
if set(("#%s"):format(scriptName), newValue) then
triggerClientEvent(root, "aOnAutomaticScriptChange", resourceRoot, scriptName, {
state = get(("#%s_state"):format(scriptName)),
limit = newValue,
})
return true
end
return false
end

addEventHandler(
"aAutomaticScriptKick",
root,
function(reason)
if isElement(client) then
kickPlayer(client, reason)
end
end
)

addEventHandler(
"onResourceStart",
resourceRoot,
function()
for scriptName in pairs(aAutoScripts) do
if get(("%s_state"):format(scriptName)) then
toggleAutomaticScript(scriptName, true, true)
end
end
end
)

addEventHandler(
"aRequestAutomaticScripts",
resourceRoot,
function()
local infos = {}
for k, v in pairs(aAllScripts) do
infos[v] = {
state = get(("#%s_state"):format(v)),
limit = get(("#%s"):format(v)),
}
end
triggerClientEvent(client, "aReceiveAutoScripts", client, infos)
end
)
Loading