]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/exploder/data_handling_code.lua
Add in exploder prototype 2
[Crafter.git] / mods / mob / exploder / data_handling_code.lua
1 --this controls how the mob saves and loads it's internal data
2
3 --save (happens when the mob despawns/server/singleplayer game shuts down)
4 exploder.get_staticdata = function(self)
5         return minetest.serialize({
6                 --range = self.range,
7                 hp = self.hp,
8                 hunger = self.hunger,
9                 hostile = self.hostile,
10                 hostile_timer = self.hostile_timer,
11                 death_animation_timer = self.death_animation_timer,
12                 dead = self.dead
13         })
14 end
15
16 --load the mob's data when brough back into the world
17 exploder.on_activate = function(self, staticdata, dtime_s)
18         self.object:set_armor_groups({immortal = 1})
19         --self.object:set_velocity({x = math.random(-5,5), y = 5, z = math.random(-5,5)})
20         self.object:set_acceleration({x = 0, y = -9.81, z = 0})
21         if string.sub(staticdata, 1, string.len("return")) == "return" then
22                 local data = minetest.deserialize(staticdata)
23                 if data and type(data) == "table" then
24                         --self.range = data.range
25                         self.hp = data.hp
26                         self.hunger = data.hunger
27                         self.hostile = data.hostile
28                         self.hostile_timer = data.hostile_timer
29                         self.death_animation_timer = data.death_animation_timer
30                         self.dead = data.dead
31                 end
32         end
33         
34         --set up mob
35         self.object:set_animation({x=0,y=5}, 30, 0, true)
36         self.object:set_hp(self.hp)
37         self.direction = vector.new(math.random()*math.random(-1,1),0,math.random()*math.random(-1,1))
38         
39         --[[
40         --set the head up
41         local head = minetest.add_entity(self.object:get_pos(), "mob:head")
42         if head then
43                 self.child = head
44                 self.child:get_luaentity().parent = self.object
45                 self.child:set_attach(self.object, "", self.head_mount, vector.new(0,0,0))
46                 self.head_rotation = vector.new(0,0,0)
47                 self.child:set_animation({x=90,y=90}, 15, 0, true)
48         end
49         ]]--
50         self.is_mob = true
51         self.object:set_armor_groups({immortal = 1})
52         --self.object:set_yaw(math.pi*math.random(-1,1)*math.random())
53 end
54
55
56 --this is the info on the mob
57 exploder.debug_nametag = function(self,dtime)
58         --we're doing this to the child because the nametage breaks the
59         --animation on the mob's body
60         if self.child then
61                 --we add in items we want to see in this list
62                 local debug_items = {"hostile_timer","hostile"}
63                 local text = ""
64                 for _,item in pairs(debug_items) do
65                         if self[item] ~= nil then
66                                 text = text..item..": "..tostring(self[item]).."\n"
67                         end
68                 end
69                 self.child:set_nametag_attributes({
70                 color = "white",
71                 text = text
72                 })
73         end
74 end