mobtalker/creeper.lua

65 lines
1.5 KiB
Lua
Raw Permalink Normal View History

2015-05-11 00:25:21 +09:00
-- Local
local mobname = "creeper"
local route = {}
local pself = {}
local count = {}
--local day = {}
2015-05-09 05:36:02 +09:00
2015-05-06 19:52:24 +09:00
-- intllib
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(s) return s end
end
2015-05-11 00:25:21 +09:00
-- Form func
2015-05-11 16:23:18 +09:00
local function form(text,type,def)
return xform(mobname,text,type,def)
2015-05-06 19:52:24 +09:00
end
2015-05-09 06:05:15 +09:00
2015-05-11 00:25:21 +09:00
-- Return Form
local function creeper_form(player,love,route)
if love == 0 and route == 0 and count[player] == 0 then
2015-05-11 16:23:18 +09:00
return form(S("Hey."))
2015-05-11 00:25:21 +09:00
elseif love == 1 and route == 0 and count[player] == 0 then
2015-05-11 16:23:18 +09:00
return form(S("Hey."))
2015-05-09 05:36:02 +09:00
else
2015-05-11 16:23:18 +09:00
return form(S("Exception handling error"))
2015-05-09 05:36:02 +09:00
end
end
2015-05-11 00:25:21 +09:00
-- Global
2015-05-09 05:36:02 +09:00
function mobtalker_creeper(self,clicker)
creeper_talk[self] = true
2015-05-11 00:25:21 +09:00
pself[clicker] = self
self.object:setvelocity({x=0,y=0,z=0})
minetest.show_formspec(clicker:get_player_name(),mobname..":form",creeper_form(clicker,creeper_love[self],route[clicker]))
2015-05-09 05:36:02 +09:00
end
2015-05-06 19:52:24 +09:00
-- Event
minetest.register_on_player_receive_fields(function(player, formname, fields)
2015-05-11 00:25:21 +09:00
local entity = pself[player]
if formname == mobname..":form" then
2015-05-11 16:23:18 +09:00
if fields.creeper_proceed then
2015-05-11 00:25:21 +09:00
creeper_talk[entity] = false
if creeper_love[entity] == 0 then
creeper_love[entity] = 1
end
elseif fields["quit"] == "true" then
creeper_talk[entity] = false
end
2015-05-06 19:52:24 +09:00
end
end)
minetest.register_on_joinplayer(function(player)
2015-05-11 00:25:21 +09:00
count[player] = 0
route[player] = 0
--mobtalker_load(mobname,creeper_love)
end)
minetest.register_on_shutdown(function(player)
local entity = pself[player]
--print(creeper_love[entity])
--mobtalker_save(mobname,creeper_love)
2015-05-06 19:52:24 +09:00
end)