forked from minetest/minetest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8547b7e
commit 8af7937
Showing
11 changed files
with
177 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dofile(minetest.get_modpath("testentities").."/visuals.lua") | ||
dofile(minetest.get_modpath("testentities").."/observers.lua") | ||
dofile(minetest.get_modpath("testentities").."/selectionbox.lua") | ||
dofile(minetest.get_modpath("testentities").."/armor.lua") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local function player_names_excluding(exclude_player_name) | ||
local player_names = {} | ||
for _, player in ipairs(minetest.get_connected_players()) do | ||
player_names[player:get_player_name()] = true | ||
end | ||
player_names[exclude_player_name] = nil | ||
return player_names | ||
end | ||
|
||
minetest.register_entity("testentities:observable", { | ||
initial_properties = { | ||
visual = "sprite", | ||
textures = { "testentities_sprite.png" }, | ||
static_save = false, | ||
infotext = "Punch to set observers to anyone but you" | ||
}, | ||
on_activate = function(self) | ||
self.object:set_armor_groups({punch_operable = 1}) | ||
assert(self.object:get_observers() == nil) | ||
-- Using a value of `false` in the table should error. | ||
assert(not pcall(self.object, self.object.set_observers, self.object, {test = false})) | ||
end, | ||
on_punch = function(self, puncher) | ||
local puncher_name = puncher:get_player_name() | ||
local observers = player_names_excluding(puncher_name) | ||
self.object:set_observers(observers) | ||
local got_observers = self.object:get_observers() | ||
for name in pairs(observers) do | ||
assert(got_observers[name]) | ||
end | ||
for name in pairs(got_observers) do | ||
assert(observers[name]) | ||
end | ||
self.object:set_properties({infotext = "Excluding " .. puncher_name}) | ||
return true | ||
end | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters