From 31c40de1109f7f3f77065024d7efb85539cb662f Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Tue, 21 Jul 2015 18:12:38 +0200 Subject: [PATCH] Avoid crash when commandblocks are forced to be used (forceload) --- mods/mesecons/mesecons_commandblock/init.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mods/mesecons/mesecons_commandblock/init.lua b/mods/mesecons/mesecons_commandblock/init.lua index 8fd23f6a..62efd359 100755 --- a/mods/mesecons/mesecons_commandblock/init.lua +++ b/mods/mesecons/mesecons_commandblock/init.lua @@ -107,11 +107,16 @@ local function resolve_commands(commands, pos) farthest = player:get_player_name() end end - local random = players[math.random(#players)]:get_player_name() - commands = commands:gsub("@nearest", nearest) - commands = commands:gsub("@farthest", farthest) - commands = commands:gsub("@random", random) - return commands + local randomp = players[math.random(#players)] + if randomp then + local random = randomp:get_player_name() + commands = commands:gsub("@nearest", nearest) + commands = commands:gsub("@farthest", farthest) + commands = commands:gsub("@random", random) + return commands + else + return "" + end end local function commandblock_action_on(pos, node)