From 012d54843e3865657d65db5c475598998c6f9f0d Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 15 Feb 2021 23:41:56 +0100 Subject: [PATCH] kamikaze stuff --- builtin/client/wasplib.lua | 94 ++++++++++++++----- clientmods/kamikaze/init.lua | 169 +++++++++++++++++++++++------------ clientmods/scaffold/init.lua | 33 +++---- 3 files changed, 198 insertions(+), 98 deletions(-) diff --git a/builtin/client/wasplib.lua b/builtin/client/wasplib.lua index 53aba9e8c..c338ffaef 100644 --- a/builtin/client/wasplib.lua +++ b/builtin/client/wasplib.lua @@ -28,6 +28,24 @@ function ws.set_bool_bulk(settings,value) return true end +function ws.shuffle(tbl) + for i = #tbl, 2, -1 do + local j = math.random(i) + tbl[i], tbl[j] = tbl[j], tbl[i] + end + return tbl +end + +function ws.in_list(val, list) + if type(list) ~= "table" then return false end + for i, v in ipairs(list) do + if v == val then + return true + end + end + return false +end + function ws.globalhacktemplate(setting,func,funcstart,funcstop,daughters) funcstart = funcstart or function() end funcstop = funcstop or function() end @@ -78,10 +96,11 @@ minetest.register_globalstep(ws.step_globalhacks) function ws.get_reachable_positions(range) range=range or 2 local rt={} + local lp=minetest.localplayer:get_pos() for x = -range,range,1 do for y = -range,range,1 do for z = -range,range,1 do - table.insert(rt,vector.new(x,y,z)) + table.insert(rt,vector.add(lp,vector.new(x,y,z))) end end end @@ -149,6 +168,21 @@ function ws.on_connect(func) if func then func() end end +function ws.find_item(items,rnd) + if type(items) == 'string' then + return minetest.find_item(items) + end + if type(nodename) ~= 'table' then return end + if rnd then items=ws.shuffle(items) end + for i, v in pairs(items) do + local n = minetest.find_item(v) + if n then + return n + end + end + return false +end + local function find_named(inv, name) if not inv then return -1 end for i, v in ipairs(inv) do @@ -315,28 +349,42 @@ function ws.dircoord(f, y, r) return ws.relcoord(0, 0, 0) end -function ws.shuffle(tbl) - for i = #tbl, 2, -1 do - local j = math.random(i) - tbl[i], tbl[j] = tbl[j], tbl[i] - end - return tbl +function ws.aim(tpos) + local ppos=minetest.localplayer:get_pos() + local dir=vector.direction(ppos,tpos) + local yyaw=0; + local pitch=0; + if dir.x < 0 then + yyaw = math.atan2(-dir.x, dir.z) + (math.pi * 2) + else + yyaw = math.atan2(-dir.x, dir.z) + end + yyaw = ws.round2(math.deg(yyaw),2) + pitch = ws.round2(math.deg(math.asin(-dir.y) * 1),2); + minetest.localplayer:set_yaw(yyaw) + minetest.localplayer:set_pitch(pitch) end -function ws.find_item(items,rnd) - if type(items) == 'string' then - return minetest.find_item(items) - --return minetest.localplayer:set_wield_index(minetest.find_item(items)) +function ws.gaim(tpos,v,g) + local v = v or 40 + local g = g or 9.81 + local ppos=minetest.localplayer:get_pos() + local dir=vector.direction(ppos,tpos) + local yyaw=0; + local pitch=0; + if dir.x < 0 then + yyaw = math.atan2(-dir.x, dir.z) + (math.pi * 2) + else + yyaw = math.atan2(-dir.x, dir.z) end - if type(nodename) ~= 'table' then return end - items=ws.shuffle(items) - for i, v in ipairs(items) do - local n = minetest.find_item(v) - if n then - return n - end - end - return false + yyaw = ws.round2(math.deg(yyaw),2) + local y = dir.y + dir.y = 0 + local x = vector.length(dir) + pitch=math.atan(math.pow(v, 2) / (g * x) + math.sqrt(math.pow(v, 4)/(math.pow(g, 2) * math.pow(x, 2)) - 2 * math.pow(v, 2) * y/(g * math.pow(x, 2)) - 1)) + --pitch = ws.round2(math.deg(math.asin(-dir.y) * 1),2); + minetest.localplayer:set_yaw(yyaw) + minetest.localplayer:set_pitch(math.deg(pitch)) end function ws.place(pos,nodename) @@ -352,3 +400,9 @@ function ws.dig(pos) minetest.dig_node(pos) end end + +function ws.dignodes(poss) + for k,v in pairs(poss) do + ws.dig(v) + end +end diff --git a/clientmods/kamikaze/init.lua b/clientmods/kamikaze/init.lua index d38e3bf3d..985b4673b 100644 --- a/clientmods/kamikaze/init.lua +++ b/clientmods/kamikaze/init.lua @@ -1,10 +1,12 @@ local fnd=false -local cpos={x=0,y=0,z=0} -local crange=500 +local cpos=vector.new(0,0,0) local hud_wp=nil -local zz={x=0,y=64,z=0} -local badnodes={'mcl_tnt:tnt','mcl_fire:basic_flame','mcl_fire:eternal_fire','mcl_fire:fire','mcl_fire:fire_charge','mcl_sponges:sponge','mcl_sponges:sponge_wet','mcl_banners:hanging_banner','mcl_banners:standing_banner'} +local zz=vector.new(42,42,42) +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'} +local badobs={'mcl_end_crystal','arrow_box','mobs_mc_wither.png'} +local searchtxt=nil local searchheight=64 +local tob=nil local function set_kwp(name,pos) if hud_wp then @@ -24,91 +26,137 @@ local nextzz=0 local function randomzz() if nextzz > os.clock() then return false end math.randomseed(os.time()) - zz.x=math.random(-128,128) - zz.y=math.random(64,searchheight) + zz.x=math.random(-128,129) + zz.y=math.random(0,searchheight) zz.z=math.random(-128,128) - nextzz=os.clock()+ 15 + nextzz=os.clock()+ 30 +end +local function find_ob(txts) + local odst=500 + local rt=nil + local obs=minetest.localplayer.get_nearby_objects(500) + for k, v in ipairs(obs) do + for kk,txt in pairs(txts) do + if ( v:get_item_textures():find(txt) ) then + local npos=v:get_pos() + local dst=vector.distance(npos,minetest.localplayer:get_pos()) + if odst > dst then + searchtxt=v:get_item_textures() + cpos=npos + set_kwp(searchtxt,v:get_pos()) + odst=dst + fnd=true + tob=v + rt=v + end + end + end + end + return rt +end +local function find_nd(names) + local lp=minetest.localplayer:get_pos() + local epos=minetest.find_nodes_near(lp,60,names,true) + local rt=nil + local odst=500 + if epos then + for k,v in pairs(epos) do + local node=minetest.get_node_or_nil(v) + local lp=minetest.localplayer:get_pos() + local dst=vector.distance(lp,v) + if odst > dst then + odst=dst + cpos=vv + rt=vv + fnd=true + end + end + end + return rt end local function find_bad_things() if fnd then return true end - local obs=minetest.localplayer.get_nearby_objects(crange) local lp=minetest.localplayer:get_pos() - local odst=500; - for k, v in ipairs(obs) do -- look for crystals first - if false and ( v:get_item_textures():find("mcl_end_crystal") ) then - local npos=v:get_pos() - local dst=vector.distance(npos,minetest.localplayer:get_pos()) - if odst > dst then cpos=npos - set_kwp(v:get_item_textures(),v:get_pos()) - fnd=true - return true - end - end + local ob=find_ob(badobs) + if not ob then ob=find_nd(badnodes) end + if not ob then + set_kwp('nothing found',zz) + randomzz() + fnd=false + return false end - odst=500 - for k, v in ipairs(obs) do - if false and ( v:get_item_textures():find("arrow_box") ) then - local npos=v:get_pos() - local dst=vector.distance(npos,minetest.localplayer:get_pos()) - if odst > dst then cpos=npos - set_kwp(v:get_item_textures(),v:get_pos()) - fnd=true - return true - end - end - end - odst=500 - 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) - if epos then - for k,v in pairs(epos) do for kk,vv in pairs(v) do - local lp=minetest.localplayer:get_pos() - local dst=vector.distance(lp,vv) - if odst > dst then odst=dst cpos=vv fnd=true end - end end - if fnd then set_kwp('badnode',cpos) return true end - end - - set_kwp('nothing found',zz) - randomzz() - fnd=false - return false + return true end local function flythere() + if not minetest.localplayer then return end + if not cpos then return end + ws.aim(cpos) + if incremental_tp.tpactive then return end + local lp=minetest.localplayer:get_pos() + local dst=vector.distance(lp,cpos) + if tob and tob:get_item_textures() == searchtxt then + dst=vector.distance(lp,tob:get_pos()) + cpos=tob:get_pos() + set_kwp(searchtxt,cpos) + end minetest.settings:set_bool("continuous_forward",true) - autofly.aim(cpos) + if dst < 2 then + minetest.settings:set_bool("continuous_forward",false) + end + --incremental_tp.tp(cpos,1) +end +local nextthrow=0 +local function throwegg() + if nextthrow > os.clock() then return false end + nextthrow=os.clock() + 0.5 + if not ws.switch_inv_or_echest('mcl_throwing:snowball',1) then + ws.switch_inv_or_echest('mcl_throwing:egg',1) + end + ws.aim(cpos) + minetest.interact('use') end local function stopflight() + local lp = minetest.localplayer:get_pos() + local dst=vector.distance(lp,cpos) minetest.settings:set_bool("continuous_forward",false) - minetest.after("0",function() - minetest.interact("start_digging") - minetest.dig_node(cpos) - fnd=false - end) + if tob and tob:get_item_textures():find(searchtxt) then + if tob and searchtxt == 'mcl_end_crystal.png' and dst < 5 then + throwegg() + searchtxt="" + end + end + fnd=false + tob=nil end ---minetest.register_globalstep(function()end) ws.rg('Kamikaze','Bots','kamikaze', function() local lp = minetest.localplayer:get_pos() + local dst=vector.distance(lp,cpos) if not find_bad_things() then - if vector.distance(lp,zz) < 1 then + if vector.distance(lp,zz) < 4 then stopflight() - return else cpos=zz end - elseif vector.distance(lp,cpos) < 1 then + elseif dst < 4 then stopflight() - return + else end flythere() + ws.dignodes(minetest.find_nodes_near(minetest.localplayer:get_pos(),5,badnodes,true)) + if cpos then + -- minetest.dig_node(cpos) + -- minetest.interact('start_digging') + minetest.settings:set_bool("killaura",true) + end end,function() core.set_keypress("special1", true) @@ -119,12 +167,14 @@ end, function() minetest.localplayer:hud_remove(hud_wp) hud_wp=nil end -end,{"noclip","pitch_move"}) +end,{"noclip","pitch_move","dighead"}) minetest.register_on_death(function() if not minetest.settings:get_bool("kamikaze") then return end + tob=nil +-- incremental_tp.tpactive=false minetest.after("5.0",function() fnd=false end) @@ -133,5 +183,8 @@ end) ws.on_connect(function() if minetest.localplayer and minetest.localplayer:get_name():find("kamikaze") then minetest.settings:set_bool("kamikaze",true) + else minetest.settings:set_bool("kamikaze",false) end end) + +minetest.register_cheat('KamiCrystals','Bots','kamikaze_crystals') diff --git a/clientmods/scaffold/init.lua b/clientmods/scaffold/init.lua index 0209fbb14..a2c23c4e6 100644 --- a/clientmods/scaffold/init.lua +++ b/clientmods/scaffold/init.lua @@ -177,7 +177,6 @@ end function scaffold.place_if_able(pos) if not pos then return end if not inside_constraints(pos) then return end - if minetest.settings:get_bool('scaffold.locky') and math.round(pos.y) ~= math.round(scaffold.locky) then return end if scaffold.can_place_wielded_at(pos) then minetest.place_node(pos) end @@ -218,15 +217,9 @@ ws.rg('DigHead','Player','dighead',function() ws.dig(ws.dircoord(0,1,0)) end) ws.rg('SnapYaw','Bots','snapyaw',function() ws.setdir(snapdir) end,function() snapdir=ws.getdir() end) -scaffold.register_template_scaffold("Constrain", "scaffold_constrain", function(pos) +scaffold.register_template_scaffold("Constrain", "scaffold_constrain", function()end,false,function() scaffold.reset() end) -end,false,function() scaffold.reset() end) - -scaffold.register_template_scaffold("LockYaw", "scaffold_lockyaw", function(pos) - if not scaffold.wason.scaffold_lockyaw then - minetest.settings:set_bool('afly_snap',true) - end -end, false, function() minetest.settings:set_bool('afly_snap',false) end) +ws.rg("LockYaw","Scaffold", "scaffold_lockyaw", function(pos) end, function() minetest.settings:set_bool('afly_snap',true) end, function() minetest.settings:set_bool('afly_snap',false) end) scaffold.register_template_scaffold("CheckScaffold", "scaffold_check", function(pos) @@ -245,13 +238,14 @@ scaffold.register_template_scaffold("WaterScaffold", "scaffold_water", function( }, pos) end end) -scaffold.register_template_scaffold("WaterSpam", "scaffold_spamwater", function(pos) - --if (pos.x % 2 + pos.z % 2) == 0 then - scaffold.place_if_needed({ - "mcl_buckets:bucket_water", - "mcl_core:water_source" - }, pos) - --end +scaffold.register_template_scaffold("WaterSpam", "scaffold_spamwater", function() + ws.do_area(3,function(pos) + scaffold.place_if_needed({ + "mcl_buckets:bucket_water", + "mcl_core:water_source" + }, pos) + end,true) + end) local function checknode(pos) local node = minetest.get_node_or_nil(pos) @@ -297,13 +291,12 @@ scaffold.register_template_scaffold("TallTBM", "scaffold_ttbm", function(pos) ws.dircoord(1,1,0), ws.dircoord(1,0,0) } - for k,v in pairs(pos) do - scaffold.dig(v) - end + ws.dignodes(pos) + minetest.settings:set_bool('continuous_forward',true) for k,v in pairs(pos) do local n=minetest.get_node_or_nil(v) - if n and n.name ~= "air" then + if not n or n.name ~= "air" then minetest.settings:set_bool('continuous_forward',false) end end