![]() |
|
Release Lift - Printable Version +- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk) +-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html) +--- Forum: Starfall (https://teamscm.co.uk/forum-7.html) +--- Thread: Release Lift (/thread-630.html) Pages:
1
2
|
Lift - LocInt - 12-12-2014 Hello, This is my second release. I'm releasing lift version 1.0. How to setup it? -Just spawn: "models/Cerus/Modbridge/Misc/Elevator/ecb111.mdl" as a base. "models/Cerus/Modbridge/Misc/Elevator/ecm111.mdl" as a shaft(optional). "models/Cerus/Modbridge/Misc/Elevator/ect111.mdl" as a top. Can I have more than 1 shaft? Yes 18 of em + top and base pieces. How to use it? - Spawn setup above and then spawn chip on the ground. - Then just write / floornumber and remember the space or it does not work. Known bugs: - None Changelog: 1.1->1.2 - Holos true / false option gives u a chance to generate floor numbers - Doesnt use applytorque as movement anymore using applyforceoffset instead - Supports more than 20 floors 1.0->1.1 - Supports now 20 floors - Supports now mininum two floors. - Bug fixed: lift can now be duped. - Bug fixed: The lift is not 100% accurate when it stops. There could be 1-4.z difference. - Removed tracer based floor stopper. - Added distance/velocity based stopper. - Lift gains now more speed during long distances. - Lift slows down when its about to stop. - Doesn't require string lib anymore. Upcoming features: - Call command for the lift. - Holobuttons for the lift. - Doors for the lift. - More compatibility with other lift models. For person and blackhawk: -I love loadlibrary -I love != statement. -I love to do stuff wrong. Report any bugs to LocInt. Version 1.2 Code: --@name LocTECH_Lift
--@author LocInt
--@autoupdate
if SERVER then
local Entity = ents.self()
local WantedAng = Angle(0,90,0)
local VSpeed = 0
local Floor=1
local FloorWanted=0
local Sound=false
local Floors = {}
local Errors = {}
local ElevatorUseAccess = 1
local Holos = false
local Data={}
Data.Users = {}
Data.Users.Id = {}
Data.Users.Permission = {}
local function ErrorHandler(Error)
table.insert(Errors, Error)
print( "Oh noes! An error:", Error )
end
local function IsValid( Ent )
return Ent and Ent.isValid and Ent:isValid()
end
local function findFloor(ply)
local Floor=find.inSphere( ply:pos(), 80, function( Ent ) return Ent:class():lower()=="prop_physics" end )
--print(Floor[1])
if(Floor[1]==Base) then
FloorToGo=1
elseif(Floor[1]==Top) then
FloorToGo=Floors
end
return FloorToGo
end
local function move(FloorWanted)
if(IsValid(Lift) and Floor~=FloorWanted and FloorWanted>0 and Floors and Floors>0 and FloorWanted<=Floors and FloorWanted>=0) then
local PhysObj=Lift:getPhysicsObject()
StopFloor=Lift
PhysObj:enableMotion(true)
Lift:unconstrain()
Stop=false
if(FloorWanted>Floor) then
VSpeed=50
Direction="Up"
elseif(FloorWanted<Floor) then
VSpeed=-50
Direction="Down"
else
VSpeed=0
end
if(Sound) then
SoundLiftMove=sounds.create(Lift, "music/hl2_song6.mp3", 100, 100)
SoundLift=sounds.create(Lift, "doors/doormove1.wav", 0, 1)
SoundLift:play()
SoundLiftMove:play()
end
if(VSpeed~=0) then
local StartPos = nil
local BaseZ = nil
local LiftZ = nil
if(Type=="Small") then
StartPos = Base:pos().z
BaseZ = Base:obbSize().z
LiftZ = Lift:pos().z-2.2
elseif(Type=="Large") then
StartPos = Base:pos().z
BaseZ = Base:obbSize().z
LiftZ = Lift:pos().z-2.2
end
if(Direction=="Up") then
if(Top:pos().z<=StartPos+((FloorWanted-1)*BaseZ)+20 and Top:pos().z>=StartPos+((FloorWanted-1)*BaseZ)-20) then
StopFloor=Top
else
for i,v in pairs(ShaftModels) do
if v and IsValid(v) then
if(v:pos().z<=StartPos+((FloorWanted-1)*BaseZ)+20 and v:pos().z>=StartPos+((FloorWanted-1)*BaseZ)-20) then
StopFloor=v
break
end
end
end
end
elseif(Direction=="Down") then
if(Base:pos().z<=StartPos+((FloorWanted-1)*BaseZ)+20 and Base:pos().z>=StartPos+((FloorWanted-1)*BaseZ)-20) then
StopFloor=Base
else
for i,v in pairs(ShaftModels) do
if v and IsValid(v) then
if(v:pos().z<=StartPos+((FloorWanted-1)*BaseZ)+20 and v:pos().z>=StartPos+((FloorWanted-1)*BaseZ)-20) then
StopFloor=v
break
end
end
end
end
end
local StartDis=StopFloor:pos():Distance(Lift:pos())
local DisPos = StopFloor:pos()+Vector(0,0,5.5)
local StartDis = DisPos:Distance(Lift:pos())
timer.create( "goUp", 0.1, 0, function()
local DisPos = StopFloor:pos()+Vector(0,0,5.5)
local Distance = DisPos:Distance(Lift:pos())
local Percent = 0
--print(Distance)
if(Distance<0.5) then
Stop=true
elseif(Distance<5) then
Percent=1.7-(Distance/StartDis)
elseif(Distance<250) then
Percent=1.5-(Distance/StartDis)
elseif(Distance>250) then
if(StartDis<1500) then
Percent=1.4-(Distance/StartDis)
if(Percent>0.7) then
Percent = 0.7
end
else
Percent=1.2-(Distance/StartDis)
if(Percent>0.6) then
Percent = 0.6
end
end
end
PhysObj:enableGravity(false)
PhysObj:setVelocity((StopFloor:pos()+Vector(0,0,5.5)-Lift:pos())*(3*(Percent)^3 - 2*(Percent)^3))
local MaxTorque = 3
local Tq = Base:toWorld(Base:pos()+Lift:vel())-(PhysObj:getAngleVelocity()*10)*PhysObj:getInertia()
local TorqueAmount=Tq:Length()
local NewTorqueAmount = math.clamp( TorqueAmount, 0, MaxTorque )
local Offset
if(NewTorqueAmount == 0)then return end
if(NewTorqueAmount ~= TorqueAmount)then
Tq:Normalize()
Tq:Mul( NewTorqueAmount )
TorqueAmount = NewTorqueAmount
end
if(math.abs(Tq.x)>TorqueAmount*0.1 or math.abs(Tq.z)>TorqueAmount*0.1) then
Offset = Vector(-Tq.z, 0, Tq.x)
else
Offset = Vector(-Tq.y, Tq.x, 0)
end
if(Offset:IsZero()) then return end
Offset = Offset:GetNormal()*TorqueAmount*0.5
local Dir = ( Tq:Cross(Offset) ):GetNormal()
if(Dir:IsZero())then return end
PhysObj:applyForceOffset( Dir, Offset )
PhysObj:applyForceOffset( Dir*-1, Offset*-1 )
Lift:setAng(Base:ang())
if(Stop) then
PhysObj:enableMotion(false)
timer.remove("goUp")
Floor=FloorWanted
Lift:weldTo(Base)
if(Sound and SoundLift) then
SoundLift:stop()
SoundLift=sounds.create(Lift, "doors/default_stop.wav", 100, 100)
SoundLift:play()
SoundLiftMove:stop()
end
end
if(Stop) then
PhysObj:enableMotion(false)
timer.remove("goUp")
Floor=FloorWanted
Lift:weldTo(Base)
if(Sound and SoundLift) then
SoundLift:stop()
SoundLift=sounds.create(Lift, "doors/default_stop.wav", 100, 100)
SoundLift:play()
end
end
end)
end
else
end
end
local function loadModels()
BM1 = find.byModel( "models/Cerus/Modbridge/Misc/Elevator/ecb111.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
BM2 = find.byModel( "models/cerus/modbridge/core/s-331eb.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
BM3 = find.byModel( "models/Cerus/Modbridge/Misc/Elevator/eb111.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
BaseModels=#BM1+#BM2+#BM3
if(BaseModels) then
if(IsValid(BM1[1])) then
Base=BM1[1]
elseif(IsValid(BM2[1])) then
Base=BM2[1]
elseif(IsValid(BM3[1])) then
Base=BM3[1]
end
if(Base) then
ShaftModels = {}
SF1 = find.byModel( "models/Cerus/Modbridge/Misc/Elevator/ecm111.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
SF2 = find.byModel( "models/cerus/modbridge/core/s-331em.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
SF3 = find.byModel( "models/Cerus/Modbridge/Misc/Elevator/etm111g.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
SF4 = find.byModel( "models/Cerus/Modbridge/Misc/Elevator/em111.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
if(SF1) then
for i,v in pairs(SF1) do
if v and IsValid(v) then
table.insert(ShaftModels, v)
end
end
end
if(SF2) then
for i,v in pairs(SF2) do
if v and IsValid(v) then
table.insert(ShaftModels, v)
end
end
end
if(SF3) then
for i,v in pairs(SF3) do
if v and IsValid(v) then
table.insert(ShaftModels, v)
end
end
end
if(SF4) then
for i,v in pairs(SF4) do
if v and IsValid(v) then
table.insert(ShaftModels, v)
end
end
end
TP1 = find.byModel( "models/Cerus/Modbridge/Misc/Elevator/ect111.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
TP2 = find.byModel( "models/cerus/modbridge/core/s-331et.mdl", function( Ent ) return Ent:owner() == ents.owner() end )
TopModels=#TP1+#TP2
if(TopModels) then
if(IsValid(TP1[1])) then
Top=TP1[1]
elseif(IsValid(TP2[1])) then
Top=TP2[1]
end
Floors = BaseModels + #ShaftModels + TopModels
if(Floors>1) then
if(Base:model():lower()=="models/cerus/modbridge/misc/elevator/ecb111.mdl" or Base:model():lower()=="models/cerus/modbridge/misc/elevator/eb111.mdl") then
Type="Small"
elseif(Base:model():lower()=="models/cerus/modbridge/core/s-331eb.mdl") then
Type="Large"
end
if(Type=="Small") then
LiftModel=find.inSphere( Entity:pos(), 1000, function( Ent )
if(IsValid(Ent) and Ent:model() and Ent:model():lower()=="models/cerus/modbridge/misc/elevator/elev_111.mdl") then return true else return false end end )
if(IsValid(LiftModel[1])) then
Lift=LiftModel[1]
else
Lift = props.create("models/Cerus/Modbridge/Misc/Elevator/elev_111.mdl",Base:getPos()+Vector(0,0,7), Base:ang())
end
elseif(Type=="Large") then
Lift = props.create("models/Cerus/Modbridge/Misc/Elevator/elev_111.mdl",Base:getPos(), Base:ang())
end
if(IsValid(Lift) and IsValid(Top) and IsValid(Base)) then
local PhysObj=Lift:getPhysicsObject()
PhysObj:enableMotion(false)
Lift:weldTo(Base)
PhysObj:setMass(50000)
Lift:nocollide(Top)
Lift:nocollide(Base)
if(ShaftModels) then
for i,v in pairs(ShaftModels) do
if v and IsValid(v) then
Lift:nocollide(v)
--print("models/sprops/misc/alphanum/alphanum_"..tostring(i)..".mdl")
if(Holos) then
if(i<=9) then
timer.create( tostring(i), 3*i, 1, function()
local Hol = holograms.create( Base:toWorld(Vector(0,80,v:obbSize().z*i)-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..tostring(i)..".mdl", 1 )
if(i==8) then
Hol:setColor(Color(29,110,125))
Hol:setParent(Base)
end
end)
else
local numString = tostring(i)
local num1 = string.sub(numString, 1, 1)
local num2 = string.sub(numString, 2, 2)
timer.create( numString, 3*i, 1, function()
local Hol = holograms.create( Base:toWorld(Vector(6,80,v:obbSize().z*i)-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..num1..".mdl", 1 )
local Hol2 = holograms.create( Base:toWorld(Vector(-6,80,v:obbSize().z*i)-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..num2..".mdl", 1 )
if(i==15 or i==16 or i==14 or i==13 or i==12 or i==18 or i==11) then
Hol:setColor(Color(29,110,125))
Hol:setParent(Base)
Hol2:setColor(Color(29,110,125))
Hol2:setParent(Base)
end
end)
end
if(i==#ShaftModels) then
local numString2 = tostring(i+1)
timer.create( numString2, 3*(i+1), 1, function()
if(i>9) then
local num1 = string.sub(numString2, 1, 1)
local Hol = holograms.create( Base:toWorld(Vector(6,80,v:obbSize().z*(i+1))-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..num1..".mdl", 1 )
Hol:setParent(Base)
local num2 = string.sub(numString2, 2, 2)
local Hol2 = holograms.create( Base:toWorld(Vector(-6,80,v:obbSize().z*(i+1))-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..num2..".mdl", 1 )
Hol2:setParent(Base)
else
local Hol = holograms.create( Base:toWorld(Vector(6,80,v:obbSize().z*(i+1))-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..numString2..".mdl", 1 )
Hol:setParent(Base)
end
--Hol:setColor(Color(29,110,125))
--Hol2:setColor(Color(29,110,125))
end)
local numString3 = tostring(i+2)
timer.create( numString3, 3*(i+2), 1, function()
if(i>9) then
local num3 = string.sub(numString3, 1, 1)
local Hol = holograms.create( Base:toWorld(Vector(6,80,v:obbSize().z*(i+2))-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..num3..".mdl", 1 )
Hol:setParent(Base)
local num4 = string.sub(numString3, 2, 2)
local Hol2 = holograms.create( Base:toWorld(Vector(-6,80,v:obbSize().z*(i+2))-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..num4..".mdl", 1 )
Hol2:setParent(Base)
else
local Hol = holograms.create( Base:toWorld(Vector(6,80,v:obbSize().z*(i+2))-Vector(0,0,80)), v:angles(), "models/sprops/misc/alphanum/alphanum_"..numString3..".mdl", 1 )
Hol:setParent(Base)
end
--Hol:setColor(Color(29,110,125))
--Hol2:setColor(Color(29,110,125))
end)
end
end
end
end
end
end
end
Sound=true
end
end
end
end
local function runCommand(chatStr, ply)
if(ElevatorUseAccess>0) then
if (chatStr[1]== "/" and chatStr[2]== "floor") then
if(chatStr[3] ~= nil) then
timer.create( "go", 0,1, function()
local WFloor = tonumber(chatStr[3])
if(WFloor~=nil) then
local Result = xpcall(move,ErrorHandler,WFloor)
end
end)
else
timer.create( "find", 0,1, function()
local WFloor = findFloor(ply)
if(WFloor~=nil) then
local Result = xpcall(move,ErrorHandler,WFloor)
end
end)
end
end
end
end
function parseChat( msg, ply )
local chatStr = {}
for i in string.gmatch(msg, "%S+") do
table.insert(chatStr,i)
end
local Result = xpcall(runCommand,ErrorHandler, chatStr, ply)
end
chat.listen( parseChat, ents )
timer.create( "loadModels", 0.1, 1, function()
local Result = xpcall(loadModels,ErrorHandler)
end)
endRE: Lift - TheOneAndOnlyTee - 12-12-2014 Ooh holobuttons, thats got my name written all over it RE: Lift - NightHawk - 01-01-2015 Bro do you even lift? Clearly the answer is yes. Also nice features in that code, very impressive. RE: Lift - LocInt - 01-01-2015 (01-01-2015, 10:59 PM)NightHawk Wrote: Bro do you even lift? Clearly the answer is yes. Also nice features in that code, very impressive. Thank you! )
RE: Lift - warhammer - 25-01-2015 does that mean that lifts work after being duped now? RE: Lift - LocInt - 25-01-2015 (25-01-2015, 10:08 AM)warhammer Wrote: does that mean that lifts work after being duped now? Yes. The newest version of the code can be found from the shared folder. Report here if its not working. RE: Lift - Lucid - 05-02-2015 Very cool Starfall ^^ RE: Lift - LocInt - 24-04-2015 Thank you! added new version to my shared folder with holo numbers on each floor.
RE: Lift - LocInt - 26-04-2015 Due a lot of updates I have decided to stop supporting this release. I might continue if there is enough people who need it. RE: Lift - rorym12345 - 27-04-2015 (26-04-2015, 09:11 PM)LocInt Wrote: Due a lot of updates I have decided to stop supporting this release. I might continue if there is enough people who need it.Shame its a really cool feature and helps alot of people i would continue on it if i were you. |