Changes to login.lua to switch characters at a pylon.
This commit is contained in:
@@ -4,6 +4,32 @@ makeclass('probe')
|
||||
makeclass('invoke')
|
||||
makeclass('cube')
|
||||
makeclass('sphere')
|
||||
makeclass('pylon')
|
||||
makeclass('roster')
|
||||
|
||||
function pretty(t, indent, seen)
|
||||
indent = indent or 0
|
||||
seen = seen or {}
|
||||
|
||||
if type(t) ~= "table" then return tostring(t) end
|
||||
if seen[t] then return "<cycle>" end
|
||||
seen[t] = true
|
||||
|
||||
local spacing = string.rep(" ", indent)
|
||||
local out = "{\n"
|
||||
|
||||
for k, v in pairs(t) do
|
||||
out = out .. spacing .. " [" .. tostring(k) .. "] = "
|
||||
out = out .. pretty(v, indent + 1, seen) .. ",\n"
|
||||
end
|
||||
|
||||
return out .. spacing .. "}"
|
||||
end
|
||||
|
||||
-- tangible.redirect(actor1,actor2)
|
||||
-- tangible.forcedisconnect(actor)
|
||||
-- tangible.keepactor(actor) -- Do not autodelete upon disconnect
|
||||
-- tangible.delete(actor) -- If actor is a connected player it will disconnect
|
||||
|
||||
-- This gets called on every login except the admin user.
|
||||
function login.init()
|
||||
@@ -12,18 +38,63 @@ function login.init()
|
||||
dprint("login.init initializing player ", player)
|
||||
actor.player = player
|
||||
tangible.keepactor(actor) -- do not delete this login when the client disconnects
|
||||
actor.color={0,0,0,0,0,0,0,0,0,0,0,0}
|
||||
actor.kills=0
|
||||
actor.killed=0
|
||||
tangible.animinit{tan=actor, anim={bp="character", mesh="manny", plane="earth", xyz={player * 100, 0, 90}}}
|
||||
dprint("About to start scanning")
|
||||
actor.startscanning()
|
||||
end
|
||||
|
||||
function login.startscanning()
|
||||
while true do
|
||||
login.onescan()
|
||||
wait(1)
|
||||
end
|
||||
end
|
||||
|
||||
function login.onescan()
|
||||
local nearby=tangible.find{plane=tangible.animfinal(actor).plane,center=tangible.animfinal(actor).xyz,radius=1000,shape="cylinder"}
|
||||
for k,v in pairs(nearby) do
|
||||
if classname(v)=="pylon" then actor.color[v.color]=time()+30 end
|
||||
if classname(v)=="player" then
|
||||
if actor.team==v.team then
|
||||
for ck,cv in v.color do actor.color[ck]=math.max(actor.color[ck],cv) end
|
||||
else
|
||||
local score1=0
|
||||
local score2=0
|
||||
for ck,cv in actor.color do if time()-cv<0 then score1=score1+1 end end
|
||||
for ck,cv in v.color do if time()-cv<0 then score2=score2+1 end end
|
||||
if score1-score2>0 then
|
||||
|
||||
-- kill player 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- This gets called on the admin user. You can call login.init in here if you want.
|
||||
function world.init()
|
||||
dprint("world.init")
|
||||
global.set("nextplayer", 0)
|
||||
tangible.build{class=roster, anim={plane="earth", xyz={2000,0,0} } }
|
||||
tangible.build{class=cube, anim={plane="earth", xyz={500,-100,0}, mat_color={1,0,0}}}
|
||||
tangible.build{class=sphere, anim={plane="earth", xyz={500,100,0}, mat_color={0,0,1}}}
|
||||
login.init()
|
||||
end
|
||||
|
||||
|
||||
function roster.init(self,config)
|
||||
self.character={}
|
||||
end
|
||||
|
||||
function world.buildpylon()
|
||||
dprint("Building pylon")
|
||||
local radius=1000
|
||||
tangible.build{class=pylon,plane="earth",xyz={math.random(-radius,radius),math.random(-radius,radius),0}}.color=math.random(1,12)
|
||||
end
|
||||
|
||||
function invoke.move(action, xyz, facing)
|
||||
-- todo: sanity check the parameters.
|
||||
tangible.animate{tan=actor, anim={action=action, interactive=true, xyz=xyz, facing=facing}}
|
||||
@@ -38,6 +109,41 @@ function login.lookmenu(add)
|
||||
add("Redirect", function() tangible.redirect(actor, place) end)
|
||||
end
|
||||
|
||||
-- Four cases: Unnamed to new, Unnamed to existing, Named to new, Named to Existing
|
||||
function playas(who)
|
||||
dprintf("Playas %lP",place)
|
||||
if not actor.name and not place.character[who] then -- Unnamed to new
|
||||
dprintf("Case 1: Naming this character "..who)
|
||||
actor.name=who
|
||||
tangible.keepactor(actor)
|
||||
place.character[who]=actor
|
||||
elseif actor.name and not place.character[who] then -- Named to new (Hard one)
|
||||
dprintf("Case 2: Creating new character "..who)
|
||||
dprintf("Case 2.0")
|
||||
local nc=tangible.build{class=login, anim={plane="earth", xyz={0,0,0} } }
|
||||
dprintf("Case 2.1")
|
||||
nc.name=who
|
||||
dprintf("Case 2.2")
|
||||
tangible.keepactor(nc)
|
||||
dprintf("Case 2.3")
|
||||
place.character[who]=nc
|
||||
dprintf("Case 2.4: ...Place is now "..place)
|
||||
tangible.redirect(actor,nc)
|
||||
elseif not actor.name and place.character[who] then
|
||||
dprintf("Case 3: Logging in from unnamed to existing character "..who)
|
||||
tangible.redirect(actor,place.character[who])
|
||||
elseif actor.name and place.character[who] then
|
||||
dprintf("Case 4: Logging in from "..actor.name.." to existing character "..who)
|
||||
tangible.redirect(actor,place.character[who])
|
||||
end
|
||||
end
|
||||
|
||||
function roster.lookmenu(add)
|
||||
for _,name in ipairs { "Albert", "Betty", "Cornelius" } do
|
||||
add("Play as "..name..(place.character[name] and "" or "*"), function() playas(name) end)
|
||||
end
|
||||
end
|
||||
|
||||
function cube.lookmenu(add)
|
||||
add("Cube A", function () dprint("Doing Cube A") end)
|
||||
add("Cube B", function () dprint("Doing Cube B") end)
|
||||
@@ -48,12 +154,18 @@ function cube.lookmenu(add)
|
||||
add("Cube Z", function () dprint("Doing Cube Z") end)
|
||||
end
|
||||
|
||||
|
||||
function sphere.lookhotkeys(add)
|
||||
add("FaceL", "Sphere Hi", function () dprint("Doing Sphere Hi") end)
|
||||
add("FaceM", "Sphere Bye", function () dprint("Doing Sphere Bye") end)
|
||||
add("FaceR", "Sphere Yo", function () dprint("Doing Sphere Yo") end)
|
||||
end
|
||||
|
||||
function sphere.tick(foo)
|
||||
dprint("Tick")
|
||||
end
|
||||
|
||||
|
||||
function probe.getlookat()
|
||||
local class = tangible.getclass(place)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user