]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/slime/data_handling_code.lua
Add in slime prototype
[Crafter.git] / mods / mob / slime / 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 slime.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 slime.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=0}, 1, 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         self.is_mob = true
40         self.object:set_armor_groups({immortal = 1})
41         --self.object:set_yaw(math.pi*math.random(-1,1)*math.random())
42 end
43
44
45 --this is the info on the mob
46 slime.debug_nametag = function(self,dtime)
47         --we add in items we want to see in this list
48         local debug_items = {"hostile_timer","hostile"}
49         local text = ""
50         for _,item in pairs(debug_items) do
51                 if self[item] ~= nil then
52                         text = text..item..": "..tostring(self[item]).."\n"
53                 end
54         end
55         self.child:set_nametag_attributes({
56         color = "white",
57         text = text
58         })
59 end