Last active
August 1, 2017 15:18
-
-
Save mkarneim/c94fa9589afadcd9ae345a599a0f31f8 to your computer and use it in GitHub Desktop.
MickKay's Common Spells for the Wizards Of Lua Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- MickKay's Common Spells for the Wizards Of Lua Server | |
| -- ( https://gist.github.com/mkarneim/c94fa9589afadcd9ae345a599a0f31f8 ) | |
| -- gist.c94fa9589afadcd9ae345a599a0f31f8.MickKay-WoL | |
| require "gist.a889319c844d68ca108c50bac53c4f10.basic-lib" | |
| -- https://gist.github.com/mkarneim/6cd6d5801b462fc85e63cd6c308b7f9f | |
| require "gist.6cd6d5801b462fc85e63cd6c308b7f9f.selection" | |
| mickkay = { | |
| author = "MickKay", | |
| version = "1.0", | |
| module = "gist.c94fa9589afadcd9ae345a599a0f31f8.MickKay-WoL" | |
| } | |
| function mickkay.startup() | |
| spell:say("Casting spells from "..mickkay.author.."'s Spell Book at "..mickkay.module.." (version "..mickkay.version..")") | |
| spell:execute("lua mickkay.feather()") | |
| spell:execute("lua mickkay.rocketthrower()") | |
| spell:execute("lua mickkay.grassstick()") | |
| spell:execute("lua mickkay.playerLogger()") | |
| spell:execute("lua mickkay.triggerArmorStands()") | |
| end | |
| function mickkay.feather() | |
| spell:say("Enabling Wand of Feather Light Flight") | |
| local killEvent = 'mickkay.feather.kill' | |
| Events.fire(killEvent) | |
| local q = Events.register('AnimationHandEvent',killEvent) | |
| for e in q.next do | |
| if e.type == killEvent then | |
| return | |
| end | |
| local p = e.player | |
| if p ~= nil and p.mainHand ~= nil then | |
| if p.mainHand.name == "minecraft:feather" and p.mainHand.displayName == "Wand of Feather Light Flight" then | |
| spell:execute("lua mickkay.jump_('%s')", p.name) | |
| end | |
| end | |
| end | |
| end | |
| function mickkay.jump(dist) | |
| jump_(spell.owner.name,dist) | |
| end | |
| function mickkay.jump_(pname,dist) | |
| local p = Players.getByName(pname) | |
| if p == nil then | |
| error("player with name %s not found", pname) | |
| end | |
| dist = dist or 10 | |
| local dir = p.lookVec*3.9 | |
| for i=1,dist do | |
| p.motion = dir*3.9 | |
| sleep(1) | |
| end | |
| end | |
| function mickkay.zombie() | |
| local tag = "hah!" | |
| local x = spell.pos.x | |
| local y = spell.pos.y | |
| local z = spell.pos.z | |
| spell:execute('summon Zombie '..x..' '..y..' '..z..' {Tags:["'..tag..'"],ArmorItems:[{},{},{},{Count:1,id:diamond_helmet}],HandItems:[{Count:1,id:diamond_sword},{Count:1,id:shield}]}') | |
| end | |
| function mickkay.zombiespawner() | |
| local s = spell.pos | |
| while true do v=random.vec3()*10 | |
| moveBy(v.x, 0, v.y) | |
| mickkay.zombie() | |
| sleep(20) | |
| spell.pos = s | |
| end | |
| end | |
| function mickkay.grassstick() | |
| spell:say("Enabling Grass-Stick") | |
| local q = Events.register('AnimationHandEvent') | |
| for e in q.next do | |
| local p = e.player | |
| if p ~= nil and p.mainHand ~= nil then | |
| if p.mainHand.name == "minecraft:stick" and p.mainHand.displayName == "grassstick" then | |
| spell:execute("lua mickkay.shoot_('%s',150, %s, %s)",p.name, "'smoke'", "mickkay.grassland") | |
| end | |
| end | |
| end | |
| end | |
| function mickkay.rocketthrower() | |
| spell:say("Enabling Rocket-Thrower Arrows") | |
| local killEvent = 'mickkay.rocketthrower.kill' | |
| Events.fire(killEvent) | |
| local q = Events.register('AnimationHandEvent',killEvent) | |
| for e in q.next do | |
| if e.type == killEvent then | |
| return | |
| end | |
| local p = e.player | |
| if p ~= nil and p.mainHand ~= nil then | |
| if p.mainHand.name == "minecraft:arrow" and p.mainHand.displayName == "rocketthrower" then | |
| spell:execute("lua mickkay.shoot_('%s',150, %s, %s)",p.name, "'smoke'", "mickkay.explode") | |
| end | |
| end | |
| end | |
| end | |
| function mickkay.grassland(r) | |
| r = r or 10 | |
| local cur = spell.block | |
| local maxsel = 4/3*math.pi*r*r*r | |
| local sel = selection.adjoining( selection.BLOCK.is( cur), selection.POS.isInSphere( r), maxsel); | |
| selection.fill(sel, "grass") | |
| end | |
| function mickkay.explode() | |
| spell:execute("summon PrimedTnt ~ ~ ~ {Fuse:3}") | |
| spell:execute("summon PrimedTnt ~ ~ ~ {Fuse:2}") | |
| spell:execute("summon PrimedTnt ~ ~ ~ {Fuse:1}") | |
| end | |
| function mickkay.shoot_( pname, dist, pt, effect) | |
| local p = Players.getByName(pname) | |
| if p == nil then | |
| error("player is nil") | |
| end | |
| local factor = 2 | |
| local steps = dist * factor | |
| local sleepStep = 4 | |
| local intersectDelay = 4*factor | |
| local velocity = p.lookVec * (1 / factor) | |
| spell.pos = p.pos + vec3(0, p.eyeHeight*0.9, 0) + p.lookVec | |
| for i=1,steps do | |
| spell:execute("particle "..pt.." "..spell.pos.x.." "..spell.pos.y.." "..spell.pos.z.." 0 0 0 0 0 force") | |
| if (i % sleepStep) == 0 then | |
| sleep(1) | |
| end | |
| spell.pos = spell.pos + velocity | |
| local hit = spell.block.material.isSolid | |
| if not hit and i>intersectDelay then | |
| local ids = Entities.intersecting(spell.pos,1) | |
| hit = #ids>1 | |
| end | |
| if hit then | |
| sleep(1) | |
| if effect ~= nil then | |
| effect( p.lookVec) | |
| end | |
| return | |
| end | |
| end | |
| end | |
| function mickkay.shoot( dist, pt) | |
| shoot_( spell.owner.name, dist, pt, mickkay.explode) | |
| end | |
| function mickkay.healthToSign(pname) | |
| pname = pname or spell.owner.name | |
| local p = Players.getByName(pname) | |
| if p==nil then | |
| error("Player with name %s not found", pname) | |
| end | |
| local signal = "mickkay.healthToSign"; | |
| Events.fire(signal, pname) | |
| local queue = Events.register(signal) | |
| while true do | |
| local evt = queue.next(10) | |
| if evt ~= nil and evt.message == pname then | |
| return | |
| end | |
| Blocks.putNbt(spell.pos, { | |
| Text1 = '{"text":"'..p.name..'"}', | |
| Text2 = '{"text":"Health"}', | |
| Text3 = '{"text":"'..p.health..'"}', | |
| }) | |
| end | |
| end | |
| function mickkay.posToSign(pname) | |
| pname = pname or spell.owner.name | |
| local p = Players.getByName(pname) | |
| if p==nil then | |
| error("Player with name %s not found", pname) | |
| end | |
| local signal = "mickkay.posToSign"; | |
| Events.fire(signal, pname) | |
| local queue = Events.register(signal) | |
| while true do | |
| local evt = queue.next(10) | |
| if evt ~= nil and evt.message == pname then | |
| return | |
| end | |
| local x = math.floor(p.pos.x) | |
| local y = math.floor(p.pos.y) | |
| local z = math.floor(p.pos.z) | |
| Blocks.putNbt(spell.pos, { | |
| Text1 = '{"text":"'..x..'"}', | |
| Text2 = '{"text":"'..y..'"}', | |
| Text3 = '{"text":"'..z..'"}' | |
| }) | |
| end | |
| end | |
| function mickkay.throwFire() | |
| local p = spell.owner | |
| spell:execute( "lua mickkay.shoot_('%s',150, %s, %s)", p.name, "'flame'", "mickkay.castFire") | |
| end | |
| function mickkay.castFire( vec) | |
| spell:pushLocation() | |
| local firePos = nil | |
| --if spell.block.material.isSolid then | |
| -- spell:move( "UP") | |
| -- if not spell.block.material.isSolid then | |
| -- firePos = spell.pos | |
| -- end | |
| --else | |
| if not spell.block.material.isSolid then | |
| spell:move( "DOWN") | |
| if spell.block.material.isSolid then | |
| spell:move( "UP") | |
| firePos = spell.pos | |
| end | |
| end | |
| if firePos == nil then | |
| if vec ~= nil then | |
| spell:popLocation() | |
| spell:pushLocation() | |
| if -0.5 < vec.y and vec.y < 0.5 then | |
| vec = vec + vec3(0,-vec.y,0) | |
| end | |
| spell.pos = spell.pos - vec | |
| if not spell.block.material.isSolid then | |
| firePos = spell.pos | |
| else | |
| spell:popLocation() | |
| spell:pushLocation() | |
| if spell.block.material.isSolid then | |
| spell:move( "UP") | |
| if not spell.block.material.isSolid then | |
| firePos = spell.pos | |
| end | |
| end | |
| end | |
| end | |
| end | |
| if firePos ~= nil then | |
| spell.pos = firePos | |
| spell.block = "fire" | |
| end | |
| spell:popLocation() | |
| end | |
| function mickkay.checkpoint() | |
| spell:say("Enabling checkpoint") | |
| local killEvent = 'mickkay.checkpoint.kill' | |
| Events.fire(killEvent) | |
| local q = Events.register('AnimationHandEvent',killEvent) | |
| for e in q.next do | |
| if e.type == killEvent then | |
| return | |
| end | |
| --spell:say("...") | |
| local p = e.player | |
| if p ~= nil and p.mainHand ~= nil then | |
| -- spell:say(p.name, inspect(p.mainHand,{depth=2})) | |
| if p.mainHand.name == "minecraft:dye" and p.mainHand.displayName == "Checkpoint erstellen" then | |
| spell:execute("spawnpoint %s %s",p.name, p.pos + Vec3.from(0,0.5,0)) | |
| spell:whisper(p.name, "Checkpoint erstellt") | |
| end | |
| if p.mainHand.name == "minecraft:dye" and p.mainHand.displayName == "Zum Checkpoint" then | |
| spell:whisper(p.name, "Zurueck zum Checkpoint") | |
| spell:execute("kill %s",p.name) | |
| end | |
| end | |
| end | |
| end | |
| function mickkay.eventlog(type, depth) | |
| if type == nil then | |
| error("type argument must be an event type but was nil!") | |
| end | |
| depth = depth or 1 | |
| spell:say("Logging Events of Type "..type) | |
| local killEvent = 'mickkay.eventlog.'..type..".kill" | |
| Events.fire(killEvent) | |
| local q = Events.register( type, killEvent); | |
| for e in q.next do | |
| if e.type == killEvent then | |
| return | |
| end | |
| spell:say(type, inspect(e,{depth=depth})); | |
| end | |
| end | |
| local OPPOSITE = {NORTH="SOUTH",EAST="WEST",SOUTH="NORTH",WEST="EAST"} | |
| local ROT = {NORTH=0,EAST=4,SOUTH=8,WEST=12} | |
| function mickkay.skull(pname,orientation) | |
| -- setblock <x> <y> <z> <block> [dataValue|state] [oldBlockHandling] [dataTag] | |
| -- setblock ~-2 ~ ~ minecraft:skull 1 replace {SkullType:3,ExtraType:"mickkay",Rot:4} | |
| local pname = pname or spell.owner.name | |
| orientation = orientation or OPPOSITE[spell.owner.orientation] | |
| local rot = ROT[orientation] | |
| spell:execute('/setblock ~ ~ ~ minecraft:skull 1 replace {SkullType:3,ExtraType:"%s",Rot:%s}', pname, rot); | |
| end | |
| function mickkay.playerLogger() | |
| spell:say("Enabling Player Logger") | |
| local killEvent = 'mickkay.playerLogger.kill' | |
| Events.fire(killEvent) | |
| local q = Events.register('PlayerLoggedInEvent','PlayerLoggedOutEvent', killEvent) | |
| for e in q.next do | |
| if e.type == killEvent then | |
| return | |
| end | |
| local p = e.player | |
| if e.type == 'PlayerLoggedInEvent' then | |
| spell:say("Spieler "..p.name.." hat sich am "..Runtime.getRealDateTime("d.M.y").." um "..Runtime.getRealDateTime("H:m:s").." eingeloggt.") | |
| end | |
| if e.type == 'PlayerLoggedOutEvent' then | |
| spell:say("Spieler "..p.name.." hat sich am "..Runtime.getRealDateTime("d.M.y").." um "..Runtime.getRealDateTime("H:m:s").." ausgeloggt.") | |
| end | |
| end | |
| end | |
| -- mickkay.triggerArmorStands(Vec3.from(2659, 91, 1471)) | |
| -- Führt alle Commandblöcke aus, die auf einem Armorstand stehen. | |
| -- Achtung: es werden nur Armorstands gefunden, die sich in geladenen Chunks | |
| -- befinden. | |
| function mickkay.triggerArmorStands(pos) | |
| sleep(1) | |
| if pos ~= nil then | |
| -- Spell an die Position setzen, so dass sicher ist, dass der jeweilige | |
| -- Chunk geladen ist. | |
| -- Vorsicht: ein Spell lädt nur einen einzigen Chunk der Größe 16x16. | |
| spell.pos = pos | |
| sleep(1) | |
| end | |
| -- Suche alle Armorstands in ALLEN geladenen Chunks | |
| local aa = mickkay.findEntities("@e[type=ArmorStand]"); | |
| for i,e in pairs(aa) do | |
| spell.pos = e.pos | |
| spell:move("DOWN") | |
| if spell.block.name == "command_block" then | |
| spell:move("UP") | |
| spell.block = "redstone_block" | |
| sleep(1) | |
| spell.block = "air" | |
| end | |
| end | |
| end | |
| function mickkay.findEntities(selector) | |
| local result = {} | |
| local ids = Entities.find(selector) | |
| for i,id in pairs(ids) do | |
| result[i] = Entities.get(id) | |
| end | |
| return result | |
| end | |
| function mickkay.getDateTime() | |
| return Runtime.getRealDateTime("d.M.y H:m:s") | |
| end | |
| mickkay.items = {} | |
| mickkay.items.head = {} | |
| function mickkay.items.head.give() | |
| -- /give @p skull 1 3 {SkullOwner:"mickkay"} | |
| spell:execute('/give @p skull 1 3 {SkullOwner:"%s"}', p.name); | |
| end | |
| function mickkay.items.head.place() | |
| --/setblock ~-2 ~ ~ minecraft:skull 1 replace {SkullType:3,ExtraType:"mickkay",Rot:4} | |
| spell:execute('/setblock ~ ~ ~ minecraft:skull 1 replace {SkullType:3,ExtraType:"%s",Rot:4}', spell.owner.name); | |
| end | |
| function mickkay.items.head.summon(pname) | |
| local p = Players.getByName(pname) | |
| --/summon Item ~-2 ~ ~ {Item:{id:spawn_egg,Count:1}} | |
| -- /summon skull ~-2 ~ ~ {SkullOwner:"mickkay"} | |
| -- /summon Item ~-2 ~ ~ {Item:{id:skull,Count:1}} | |
| -- /summon Item ~-2 ~ ~ {Item:{id:skull,Count:1,SkullOwner:"mickkay"}} | |
| spell:execute('/summon skull ~-2 ~ ~ {SkullOwner:"%s"}',p.name) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment