User Tools

Site Tools


dev:core:funref:is_creative

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dev:core:funref:is_creative [2019-10-02 16:29]
82.67.173.193 created
dev:core:funref:is_creative [2020-01-22 10:53] (current)
admin ↷ Page moved from reference:advtrains:is_creative to dev:core:funref:is_creative
Line 6: Line 6:
 ===== Syntax ===== ===== Syntax =====
 <code lua> <code lua>
-advtrains.is_creative(playername)+advtrains.is_creative(name)
 </code> </code>
  
 ===== Parameters ===== ===== Parameters =====
-  * ''playername'' //(string)//: the player name. It does not need to be logged in, but it *needs* to exist in the ''auth.txt'' file.+  * ''name'' //(string)//: the player name. It does not need to be logged in, but it *needs* to exist in the ''auth.txt'' file
 + 
 +===== Returns ===== 
 +True if the creative mode is enabled for the player, false otherwise.
  
 ===== Errors and warnings ===== ===== Errors and warnings =====
-It gives an error if the ''playername'' parameter is nil:+It gives an error if the ''name'' parameter is nil:
  
 > 2019-01-01 15:00:00: Error[Server]:  advtrains.is_creative() called without name parameter! > 2019-01-01 15:00:00: Error[Server]:  advtrains.is_creative() called without name parameter!
Line 19: Line 22:
 ===== How it works internally ===== ===== How it works internally =====
 This Lua function checks whether the designated player has the ''creative'' privilege. If not, it checks whether the global **Creative Mode** option has been enabled in the main menu. If either condition is true, Advtrains considers that creative mode is enabled. This Lua function checks whether the designated player has the ''creative'' privilege. If not, it checks whether the global **Creative Mode** option has been enabled in the main menu. If either condition is true, Advtrains considers that creative mode is enabled.
 +
 +===== Examples =====
 +Consider that you are running a Minetest server and:
 +  * Two players, ''alice'' and ''bob'' are connected to the server
 +  * ''alice'' has the ''creative'' privilege while ''bob'' has no privileges
 +
 +<code lua>
 +advtrains.is_creative("alice") -- returns true in all cases
 +advtrains.is_creative("bob") -- returns true only when Creative Mode is enabled
 +advtrains.is_creative("unknown") -- returns true only when Creative Mode is enabled
 +</code>
  
 ===== In source code ===== ===== In source code =====
Line 25: Line 39:
 <file lua is_creative.lua> <file lua is_creative.lua>
 function advtrains.is_creative(name) function advtrains.is_creative(name)
-        if not name then +    if not name then 
-                error("advtrains.is_creative() called without name parameter!"+        error("advtrains.is_creative() called without name parameter!"
-        end +    end 
-        if minetest.check_player_privs(name, {creative=true}) then +    if minetest.check_player_privs(name, {creative=true}) then 
-                return true +        return true 
-        end +    end 
-        return minetest.settings:get_bool("creative_mode")+    return minetest.settings:get_bool("creative_mode")
 end end
 </file> </file>
dev/core/funref/is_creative.1570026573.txt.gz · Last modified: 2019-10-02 16:29 by 82.67.173.193