incrementaltp: respect physics overrides
[waspsaliva.git] / clientmods / kamikaze / init.lua
blobe4c7a148ef70e90990939091e199891e28ad8ddf
1 kamikaze={}
2 kamikaze.active=false
3 local fnd=false
4 local cpos=vector.new(0,0,0)
5 local hud_wp=nil
6 local zz=vector.new(42,42,42)
7 local badnodes={'mcl_tnt:tnt','mcl_fire:basic_flame','mcl_fire:fire','mcl_banners:hanging_banner','mcl_banners:standing_banner','mcl_fire:fire_charge','mcl_sponges:sponge','mcl_sponges:sponge_wet','mcl_nether:soul_sand','mcl_heads:wither_skeleton'}
8 local badobs={'mcl_end_crystal','arrow_box','mobs_mc_wither.png'}
9 local searchtxt=nil
10 local searchheight=64
11 local tob=nil
13 local function set_kwp(name,pos)
14 if hud_wp then
15 minetest.localplayer:hud_change(hud_wp, 'world_pos', pos)
16 minetest.localplayer:hud_change(hud_wp, 'name', name)
17 else
18 hud_wp = minetest.localplayer:hud_add({
19 hud_elem_type = 'waypoint',
20 name = name,
21 text = 'm',
22 number = 0x00ff00,
23 world_pos = pos
25 end
26 end
27 local nextzz=0
28 local function randomzz()
29 if nextzz > os.clock() then return false end
30 math.randomseed(os.time())
31 zz.x=math.random(-128,129)
32 zz.y=math.random(0,searchheight)
33 zz.z=math.random(-128,128)
34 nextzz=os.clock()+ 30
35 end
36 local function find_ob(txts)
37 local odst=500
38 local rt=nil
39 local obs=minetest.localplayer.get_nearby_objects(500)
40 for k, v in ipairs(obs) do
41 for kk,txt in pairs(txts) do
42 if ( v:get_item_textures():find(txt) ) then
43 local npos=v:get_pos()
44 local dst=vector.distance(npos,minetest.localplayer:get_pos())
45 if odst > dst then
46 searchtxt=v:get_item_textures()
47 cpos=npos
48 set_kwp(searchtxt,v:get_pos())
49 odst=dst
50 fnd=true
51 tob=v
52 rt=v
53 end
54 end
55 end
56 end
57 return rt
58 end
60 local function find_nd(names)
61 local lp=minetest.localplayer:get_pos()
62 local epos=minetest.find_nodes_near(lp,60,names,true)
63 local rt=nil
64 local odst=500
65 if epos then
66 for k,v in pairs(epos) do
67 local node=minetest.get_node_or_nil(v)
68 local lp=minetest.localplayer:get_pos()
69 local dst=vector.distance(lp,v)
70 if odst > dst then
71 odst=dst
72 cpos=vv
73 rt=vv
74 fnd=true
75 end
76 end
77 end
78 return rt
79 end
82 local function find_bad_things()
83 if fnd then return true end
84 local lp=minetest.localplayer:get_pos()
85 local ob=find_ob(badobs)
86 if not ob then ob=find_nd(badnodes) end
87 if not ob then
88 set_kwp('nothing found',zz)
89 randomzz()
90 fnd=false
91 return false
92 end
93 return true
94 end
98 local function flythere()
99 if not minetest.localplayer then return end
100 if not cpos then return end
101 ws.aim(cpos)
102 minetest.settings:set_bool("killaura",false)
103 if incremental_tp.tpactive then return end
104 local lp=minetest.localplayer:get_pos()
105 local dst=vector.distance(lp,cpos)
106 if tob and tob:get_item_textures() == searchtxt then
107 dst=vector.distance(lp,tob:get_pos())
108 cpos=tob:get_pos()
109 set_kwp(searchtxt,cpos)
111 minetest.settings:set_bool("continuous_forward",true)
115 local function stopflight()
116 local lp = minetest.localplayer:get_pos()
117 local dst=vector.distance(lp,cpos)
118 minetest.settings:set_bool("continuous_forward",false)
119 if tob and tob:get_item_textures():find(searchtxt) then
120 if searchtxt == 'mcl_end_crystal.png' then
121 minetest.dig_node(cpos)
122 tob:punch()
123 minetest.interact('start_digging')
124 searchtxt=""
125 tob=nil
126 else
127 minetest.settings:set_bool("killaura",true)
130 fnd=false
131 tob=nil
136 ws.rg('Kamikaze','Bots','kamikaze', function()
137 local lp = minetest.localplayer:get_pos()
138 local dst=vector.distance(lp,cpos)
140 if not find_bad_things() then
141 if vector.distance(lp,zz) < 1 then
142 stopflight()
143 else
144 cpos=zz
145 flythere()
147 elseif dst < 1 then
148 stopflight()
149 else
150 flythere()
153 -- ws.dignodes(minetest.find_nodes_near(minetest.localplayer:get_pos(),5,badnodes,true))
154 if cpos then
155 minetest.dig_node(cpos)
156 --minetest.interact('start_digging')
160 end,function()
161 core.set_keypress("special1", true)
162 kamikaze.active=true
163 end, function()
164 kamikaze.active=false
165 core.set_keypress("special1", false)
166 fnd=false
167 if hud_wp then
168 minetest.localplayer:hud_remove(hud_wp)
169 hud_wp=nil
171 end,{"noclip","pitch_move","dighead","digbadnodes"})
175 minetest.register_on_death(function()
176 if not minetest.settings:get_bool("kamikaze") then return end
177 tob=nil
178 -- incremental_tp.tpactive=false
179 minetest.after("5.0",function()
180 fnd=false
181 end)
182 end)
184 ws.on_connect(function()
185 minetest.settings:set_bool("kamikaze",false)
186 --if minetest.localplayer and minetest.localplayer:get_name():find("kamikaze") then
187 -- minetest.settings:set_bool("kamikaze",true)
188 --else minetest.settings:set_bool("kamikaze",false)
189 --end
190 end)
192 minetest.register_cheat('KamiCrystals','Bots','kamikaze_crystals')