rangedweapons/skills.lua

159 lines
5.6 KiB
Lua
Raw Normal View History

2024-07-22 14:48:47 +03:00
local S = minetest.get_translator("rangedweapons")
2024-07-22 13:41:50 +03:00
minetest.register_on_joinplayer(function(player)
local meta = player:get_meta()
if meta:get_int("handgun_skill") == 0
then
meta:set_int("handgun_skill",100)
end
if meta:get_int("mp_skill") == 0
then
meta:set_int("mp_skill",100)
end
if meta:get_int("smg_skill") == 0
then
meta:set_int("smg_skill",100)
end
if meta:get_int("shotgun_skill") == 0
then
meta:set_int("shotgun_skill",100)
end
if meta:get_int("heavy_skill") == 0
then
meta:set_int("heavy_skill",100)
end
if meta:get_int("arifle_skill") == 0
then
meta:set_int("arifle_skill",100)
end
if meta:get_int("revolver_skill") == 0
then
meta:set_int("revolver_skill",100)
end
if meta:get_int("rifle_skill") == 0
then
meta:set_int("rifle_skill",100)
end
if meta:get_int("throw_skill") == 0
then
meta:set_int("throw_skill",100)
end
end)
minetest.register_chatcommand("gunskills", {
func = function(name, param)
for _, player in pairs(minetest.get_connected_players()) do
local meta = player:get_meta()
local handguns = meta:get_int("handgun_skill")
local mps = meta:get_int("mp_skill")
local smgs = meta:get_int("smg_skill")
local shotguns = meta:get_int("shotgun_skill")
local heavy = meta:get_int("heavy_skill")
local arifle = meta:get_int("arifle_skill")
local revolver = meta:get_int("revolver_skill")
local rifle = meta:get_int("rifle_skill")
local throw = meta:get_int("throw_skill")
minetest.show_formspec(name, "rangedweapons:gunskills_form",
"size[11,7]"..
2024-07-22 14:48:47 +03:00
"label[0,0;"..S("Gun efficiency: increases damage, accuracy and crit chance.").."]"..
2024-07-22 13:41:50 +03:00
"image[0,1;1,1;rangedweapons_handgun_img.png]"..
2024-07-22 14:48:47 +03:00
"label[1,1.2;"..S("Handgun efficiency:").. " " .. handguns .. "%]"..
2024-07-22 13:41:50 +03:00
"image[0,2;1,1;rangedweapons_machinepistol_img.png]"..
2024-07-22 14:48:47 +03:00
"label[1,2.2;"..S("M.Pistol efficiency:") .. " " .. mps .. "%]"..
2024-07-22 13:41:50 +03:00
"image[0,3;1,1;rangedweapons_smg_img.png]"..
2024-07-22 14:48:47 +03:00
"label[1,3.2;"..S("S.M.G efficiency:") .. " " .. smgs .. "%]"..
2024-07-22 13:41:50 +03:00
"image[0,4;1,1;rangedweapons_shotgun_img.png]"..
2024-07-22 14:48:47 +03:00
"label[1,4.2;"..S("Shotgun efficiency:") .. " " .. shotguns .. "%]"..
2024-07-22 13:41:50 +03:00
"image[0,5;1,1;rangedweapons_heavy_img.png]"..
2024-07-22 14:48:47 +03:00
"label[1,5.2;"..S("Heavy.MG efficiency:") .. " " .. heavy .. "%]"..
2024-07-22 13:41:50 +03:00
"image[0,6;1,1;rangedweapons_arifle_img.png]"..
2024-07-22 14:48:47 +03:00
"label[1,6.2;"..S("A.rifle efficiency:") .. " " .. arifle .. "%]"..
2024-07-22 13:41:50 +03:00
"image[5,1;1,1;rangedweapons_revolver_img.png]"..
2024-07-22 14:48:47 +03:00
"label[6,1.2;"..S("Revl./mgn. efficiency:") .. " " .. revolver .. "%]"..
2024-07-22 13:41:50 +03:00
"image[5,2;1,1;rangedweapons_rifle_img.png]"..
2024-07-22 14:48:47 +03:00
"label[6,2.2;"..S("Rifle efficiency:") .. " " .. rifle .. "%]"..
2024-07-22 13:41:50 +03:00
"image[5,3;1,1;rangedweapons_yeetable_img.png]"..
2024-07-22 14:48:47 +03:00
"label[6,3.2;"..S("Throwing efficiency:") .. " " .. throw .. "%]"..
2024-07-22 13:41:50 +03:00
"button_exit[9,0;2,1;exit;Done]")
end
end
})
local min_gun_efficiency = tonumber(minetest.settings:get("rangedweapons_min_gun_efficiency")) or 40
local timer = 0
minetest.register_globalstep(function(dtime, player)
timer = timer + dtime;
if timer >= 60.0 then
for _, player in pairs(minetest.get_connected_players()) do
local meta = player:get_meta()
local handguns = meta:get_int("handgun_skill")
local mps = meta:get_int("mp_skill")
local smgs = meta:get_int("smg_skill")
local shotguns = meta:get_int("shotgun_skill")
local heavy = meta:get_int("heavy_skill")
local arifle = meta:get_int("arifle_skill")
local revolver = meta:get_int("revolver_skill")
local rifle = meta:get_int("rifle_skill")
local throw = meta:get_int("throw_skill")
if math.random(1, 40) == 1 then
if handguns > min_gun_efficiency then
meta:set_int("handgun_skill", handguns - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Handgun skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if mps > min_gun_efficiency then
meta:set_int("mp_skill", mps - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Machine Pistol skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if smgs > min_gun_efficiency then
meta:set_int("smg_skill", smgs - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("S.M.G skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if shotguns > min_gun_efficiency then
meta:set_int("shotgun_skill", shotguns - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Shotgun skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if heavy > min_gun_efficiency then
meta:set_int("heavy_skill", heavy - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Heavy.MG skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if arifle > min_gun_efficiency then
meta:set_int("arifle_skill", arifle - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("A.Rifle skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if revolver > min_gun_efficiency then
meta:set_int("revolver_skill", revolver - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Revolver/magnum skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if rifle > min_gun_efficiency then
meta:set_int("rifle_skill", rifle - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Rifle skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
if math.random(1, 40) == 1 then
if throw > min_gun_efficiency then
meta:set_int("throw_skill", throw - 1)
2024-07-22 14:48:47 +03:00
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000",S("Throwing skill degraded!")))
2024-07-22 13:41:50 +03:00
end
end
timer = 0
end
end
end)