scaffol: add headTri
[waspsaliva.git] / clientmods / kamikaze / init.lua
blob921ecfcf9dfdf9ece0a9f642e9b6d34be73da35a
1 local fnd=false
2 local cpos={x=0,y=0,z=0}
3 local crange=500
4 local hud_wp=nil
5 local zz={x=0,y=64,z=0}
6 local badnodes={'mcl_tnt:tnt','mcl_fire:basic_flame','mcl_fire:eternal_fire','mcl_fire:fire','mcl_fire:fire_charge'}
7 --'mcl_sponges:sponge','mcl_sponges:sponge_wet'
8 local searchheight=64
10 local function set_kwp(name,pos)
11 if hud_wp then
12 minetest.localplayer:hud_change(hud_wp, 'world_pos', pos)
13 minetest.localplayer:hud_change(hud_wp, 'name', name)
14 else
15 hud_wp = minetest.localplayer:hud_add({
16 hud_elem_type = 'waypoint',
17 name = name,
18 text = 'm',
19 number = 0x00ff00,
20 world_pos = pos
22 end
23 end
24 local nextzz=0
25 local function randomzz()
26 if nextzz > os.clock() then return false end
27 math.randomseed(os.time())
28 zz.x=math.random(-128,128)
29 zz.y=math.random(64,searchheight)
30 zz.z=math.random(-128,128)
31 nextzz=os.clock()+ 15
32 end
34 local function find_bad_things()
35 if fnd then return true end
36 local obs=minetest.localplayer.get_nearby_objects(crange)
37 local lp=minetest.localplayer:get_pos()
39 for k, v in ipairs(obs) do -- look for crystals first
40 if ( v:get_item_textures():find("mcl_end_crystal") ) then
41 cpos=v:get_pos()
42 set_kwp(v:get_item_textures(),v:get_pos())
43 fnd=true
44 return true
45 end
46 end
48 for k, v in ipairs(obs) do
49 if ( v:get_item_textures():find("arrow_box") ) then
50 cpos=v:get_pos()
51 set_kwp(v:get_item_textures(),v:get_pos())
52 fnd=true
53 return true
54 end
55 end
57 local epos=minetest.find_nodes_in_area(vector.add(lp,{x=79,y=79,z=79}), vector.add(lp,{x=-79,y=-79,z=-79}), badnodes, true)
58 local odst=500
59 if epos then
60 for k,v in pairs(epos) do for kk,vv in pairs(v) do
61 lp=minetest.localplayer:get_pos()
62 local dst=vector.distance(lp,vv)
63 if odst > dst then odst=dst cpos=vv fnd=true end
64 end end
65 if fnd then set_kwp('badnode',cpos) return true end
66 end
68 set_kwp('nothing found',zz)
69 randomzz()
70 fnd=false
71 return false
72 end
76 local function flythere()
77 minetest.settings:set_bool('noclip',true)
78 minetest.settings:set_bool("pitch_move",true)
79 minetest.settings:set_bool("continuous_forward",true)
80 autofly.aim(cpos)
81 core.set_keypress("special1", true)
82 end
84 local function stopflight()
85 minetest.settings:set_bool("continuous_forward",false)
86 minetest.settings:set_bool("noclip",false)
87 minetest.settings:set_bool("pitch_move",false)
88 core.set_keypress("special1", false)
89 minetest.after("0",function()
90 minetest.interact("start_digging")
91 minetest.dig_node(cpos)
92 fnd=false
93 end)
94 end
96 minetest.register_globalstep(function()
97 if not minetest.settings:get_bool("kamikaze") and not minetest.localplayer:get_name():find("kamikaze") then
98 if hud_wp then
99 minetest.localplayer:hud_remove(hud_wp) hud_wp=nil
100 minetest.settings:set_bool("continuous_forward",false)
101 minetest.settings:set_bool("noclip",false)
102 minetest.settings:set_bool("pitch_move",false)
103 core.set_keypress("special1", false)
104 fnd=false
106 return
109 local lp = minetest.localplayer:get_pos()
110 if not find_bad_things() then
111 if vector.distance(lp,zz) < 1 then
112 stopflight()
113 return
114 else
115 cpos=zz
117 elseif vector.distance(lp,cpos) < 1 then
118 stopflight()
119 return
121 flythere()
122 end)
124 minetest.register_on_death(function()
125 if not minetest.settings:get_bool("kamikaze") then return end
126 fnd=false
127 end)
129 minetest.register_cheat("Kamikaze", "Combat", "kamikaze")