fix formatting, remove test code from main file
This commit is contained in:
parent
43e7250352
commit
6a4ab435ba
62
init.lua
62
init.lua
@ -32,7 +32,7 @@ local function show_hud_waypoint(player, point_pos, name, icon_name)
|
||||
size, alignment, ARROW_FORMAT, ICON_COLOR, ARROW_QUADS_STEPS,
|
||||
do_auto_update)
|
||||
hud:show(player)
|
||||
|
||||
|
||||
return hud
|
||||
end
|
||||
|
||||
@ -85,7 +85,7 @@ local function post_announcement(announcement)
|
||||
minetest.log("error","[MOD] waypoint_announce: nil required fields " .. minetest.serialize(announcement))
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
for i, object in pairs(minetest.get_objects_inside_radius(announcer_pos, announcement.radius)) do
|
||||
if object:is_player() then
|
||||
local player = object
|
||||
@ -94,7 +94,7 @@ local function post_announcement(announcement)
|
||||
announcement.players_hud[player_name] = hud
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local rounded_pos = vector.round(pointed_pos)
|
||||
local chat_message = "[ANNOUNCE] (" ..
|
||||
announcer_name ..
|
||||
@ -102,7 +102,7 @@ local function post_announcement(announcement)
|
||||
announcement.message .. " " ..
|
||||
minetest.pos_to_string(rounded_pos)
|
||||
minetest.chat_send_all(minetest.colorize(CHAT_MESSAGE_COLOR, chat_message))
|
||||
|
||||
|
||||
announcement.timeout_job = minetest.after(announcement.timeout, remove_announcement, announcement)
|
||||
|
||||
for modname,func in pairs(waypoint_announce.post_announcement_hooks) do
|
||||
@ -121,7 +121,7 @@ local function get_pointed_and_post_announcement(announcer, announcement)
|
||||
-- player is pointing into the void, use him as target
|
||||
pointed_pos = announcer_pos
|
||||
end
|
||||
|
||||
|
||||
announcement.point = pointed_pos
|
||||
|
||||
post_announcement(announcement)
|
||||
@ -152,10 +152,11 @@ end
|
||||
|
||||
minetest.register_globalstep(check_click_for_prepared_players)
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand(ANNOUNCE_PREPARE_COMMAND_NAME, {
|
||||
params = "<message>",
|
||||
description = "Type your message, then point to somewhere and press <punch> button. This will send your message to chat and place a waypoint where you pointed. Waypoint will be visible to people around you.", privs = {
|
||||
description = "Type your message, then point to somewhere and press <punch> button. This will send your message to chat and place a waypoint where you pointed. Waypoint will be visible to people around you.",
|
||||
privs = {
|
||||
shout = true,
|
||||
},
|
||||
func = function(name, param)
|
||||
@ -192,39 +193,6 @@ minetest.register_chatcommand(ANNOUNCE_COMMAND_NAME, {
|
||||
})
|
||||
|
||||
|
||||
local test_time = 0
|
||||
local test_registered = false
|
||||
local test_enabled = false
|
||||
|
||||
local function step_test_spam_look(player_name)
|
||||
return function(dtime)
|
||||
if not test_enabled then
|
||||
return
|
||||
end
|
||||
test_time = test_time + dtime
|
||||
if test_time < 0.2 then
|
||||
return
|
||||
else
|
||||
test_time = 0
|
||||
end
|
||||
player_name = player_name or "singleplayer"
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then -- player is online
|
||||
local player_name = player:get_player_name()
|
||||
local param = ""
|
||||
local announcement = Announcement:new(player_name, ANNOUNCE_RADIUS, param, ANNOUNCE_ICON, ANNOUNCE_TIMEOUT)
|
||||
get_pointed_and_post_announcement(player, announcement)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function announce_waypoint_test_spam_look(player_name)
|
||||
if not test_registered then
|
||||
minetest.register_globalstep(step_test_spam_look(player_name))
|
||||
end
|
||||
test_enabled = not test_enabled
|
||||
end
|
||||
|
||||
local flag_dialog_context = {}
|
||||
local function show_flag_config_dialog(itemstack, player)
|
||||
@ -256,10 +224,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
local meta = flag_item:get_meta()
|
||||
|
||||
|
||||
local message = fields.message
|
||||
meta:set_string("message", message)
|
||||
|
||||
|
||||
local success = player:set_wielded_item(flag_item)
|
||||
if not success then
|
||||
-- no idea why this can happen
|
||||
@ -289,10 +257,10 @@ local function flag_use_callback(itemstack, user, pointed_thing)
|
||||
if not minetest.check_player_privs(user, "shout") then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local player_name = user:get_player_name()
|
||||
|
||||
|
||||
|
||||
|
||||
local meta = itemstack:get_meta()
|
||||
local pointed_pos = nil
|
||||
if pointed_thing.type == "nothing" then
|
||||
@ -300,7 +268,7 @@ local function flag_use_callback(itemstack, user, pointed_thing)
|
||||
else
|
||||
pointed_pos = pointed_thing.above
|
||||
end
|
||||
|
||||
|
||||
if not pointed_pos then
|
||||
return
|
||||
end
|
||||
@ -357,5 +325,3 @@ waypoint_announce = {
|
||||
|
||||
|
||||
return waypoint_announce
|
||||
|
||||
|
||||
|
35
test/test_spam_look.lua
Normal file
35
test/test_spam_look.lua
Normal file
@ -0,0 +1,35 @@
|
||||
-- Functions that were used to test cooldown
|
||||
|
||||
local test_time = 0
|
||||
local test_registered = false
|
||||
local test_enabled = false
|
||||
|
||||
local function step_test_spam_look(player_name)
|
||||
return function(dtime)
|
||||
if not test_enabled then
|
||||
return
|
||||
end
|
||||
test_time = test_time + dtime
|
||||
if test_time < 0.2 then
|
||||
return
|
||||
else
|
||||
test_time = 0
|
||||
end
|
||||
player_name = player_name or "singleplayer"
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then -- player is online
|
||||
local player_name = player:get_player_name()
|
||||
local param = ""
|
||||
local announcement = Announcement:new(player_name, ANNOUNCE_RADIUS, param, ANNOUNCE_ICON, ANNOUNCE_TIMEOUT)
|
||||
get_pointed_and_post_announcement(player, announcement)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function announce_waypoint_test_spam_look(player_name)
|
||||
if not test_registered then
|
||||
minetest.register_globalstep(step_test_spam_look(player_name))
|
||||
end
|
||||
test_enabled = not test_enabled
|
||||
end
|
Loading…
Reference in New Issue
Block a user