![]() |
|
LocInt's SF Help & Request Thread - 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: LocInt's SF Help & Request Thread (/thread-627.html) Pages:
1
2
|
RE: LocInt's SF Help & Request Thread - Person8880 - 12-12-2014 (11-12-2014, 11:41 PM)LocInt Wrote:Lua's a language, not a library. There are no "functions like in lua".(11-12-2014, 11:28 PM)_BL4CKH4WK Wrote: Also this isn't lua syntax:Use "~=" instead of "!=". The correct syntax is: The syntax only works because Garry made the stupid decision long ago to add C style operators to GMod, which has ended up in lots of people being very confused about what Lua's actual syntax is and getting lost in other Lua based games/software. As for GMod's functions, to bind every single GMod function would take a long time, and would be pretty unmanageable. There's lots that I call "cheaty" because they would take Starfall from an in-game tool into something that controls the way the game works, which is beyond its scope. Besides, the best work is done under constrained conditions as it forces creative thinking and solutions. RE: LocInt's SF Help & Request Thread - SuperPlayer - 14-05-2015 Hey. I stuck at this function since a while and i need help. The function i have right now just works for An inbound address of 7 chevrons. So my question is can i somehow split the Address so that I only get the first 6 characters? So for the function lets assume Address = "123456@P#" So how can i make that it deletes the last 3 characters? But also so that it would for Address = "123456#"?
I hope you can help me out. RE: LocInt's SF Help & Request Thread - LocInt - 14-05-2015 (14-05-2015, 05:29 PM)SuperPlayer Wrote: Hey. I stuck at this function since a while and i need help. The function i have right now just works for An inbound address of 7 chevrons. So my question is can i somehow split the Address so that I only get the first 6 characters? Like this you can read only the first 6 characters. String=string.sub(WholeString, 1, 6) RE: LocInt's SF Help & Request Thread - Person8880 - 14-05-2015 What LocInt said expanded:
Basically, string.sub takes a string, a starting character index and an ending character index and returns the parts of the string between the two indices. So in the above, we took the characters between the 1st and 6th inclusive out of the Address string.You'll note also the use of the local keyword, otherwise you end up leaking values out into the global scope which is bad practise and will almost certainly lead to problems later. RE: LocInt's SF Help & Request Thread - SuperPlayer - 14-05-2015 Thank you both very much!
RE: LocInt's SF Help & Request Thread - Salira - 16-05-2015 Hey there. I managed to fix most of Link's dialing computer. There is only one thing I don't know how to fix. When you set options in the options menu, they get saved, but the next time you look at the options they reset. Also, when there is an iris/shield on the gate, the toggle button for it is there, but the options for it (Auto-Iris and Safe Mode) don't appear in the options menu. Please get back to me when you fix it (if possible). Thanks. EDIT: Due to the new changes Person made, I can no longer dial at all. It returns "Server instance error: SF tarfall/dialling_computer.txt:426: Type mismatch (Expected string, got Stargate) in function dial." whenever I try to dial any gate, private or not.Code: --@name Dialling Computer
--@author Link320
--@sharedscreen
--@requirecl lib/screen.txt
--@requirecl lib/stargate_specs.txt
--@require lib/string.txt
--@require lib/hugnet.txt
--[[
This is Link320's Starfall Dialling Computer V1.10
Do not redistribute this without the express permission of the author.
Setup:
This is a single starfall screen. Unlike EGP, it runs on its own without another chip controlling it.
Place near to a Stargate you own. That's it. It'll automatically find your gate, and it's iris if it has one. There is no wiring needed.
If you want to wire it to a Stargate, you can, and that will override the automatic search.
Functionality:
This dialling computer has 3 different screens.
STATUS: Shows the gate display, status log and dialling controls.
DIAL - Dials the current address
CLOSE - Closes the gate / Aborts dialling
NEXT - Proceeds to next address in list
PREV - Returns to previous address in list
ADDRESSES: Shows a list of all non-private gates that can be dialled, including those with no name/address.
Non-addressed gates will show, but cannot be dialled.
OPTIONS: Displays the current gate options, and allows you to toggle them.
PRIVATE - Toggle private mode of gate
MODE - Switch between Slow, Fast and Nox (Instant)
LOCAL - Toggle local mode of gate
BLOCKING - Toggle blocking mode of gate
SOUNDS - Toggle inbound alarm
- (Only with iris)
AUTO IRIS - Toggles automatic iris close on inbound
SAFE MODE - Toggles automatic iris during unstable vortex
- (Only on specific gate classes)
RING LIGHT (Pegasus only) - Toggles the ring light
LIGHTS (Movie only) - Toggles chevron lamps (SG1 style)
There is also the utility bar at the bottom of the screen, which allows switching between screens and toggling of the iris.
It also displays the current gate status.
IDC codes are handled internally (No reciever required), and are allocated by chat command. Type /help in chat for a list of chat commands.
This Dialling Computer will also override all other forms of dialling for players that aren't you or an admin. Eg DHDs and Nox hands won't work.
Some useful information is printed straight to the console, rather than chat. This includes what objects come through the gate, and players on the other end.
Thank you for reading this. It helps a lot.
]]--
--[[
BUGS:
None at the moment, yay!
Report any bugs on the forum topic.
]]--
local sound = sounds --This was previously "local sound = loadLibrary("sounds")", so I put this in so I don't have to correct all the sound.something functions.
Hug.debug = false
MessageIDs = {
Gate = 1,
GateNetwork = 2,
Dial = 3,
Close = 4,
Iris = 5,
Options = 6,
Override = 7,
Log = 8,
CLReady = 9
}
if SERVER then -------------------------------------------------------------------- SERVER ------------------------------------------------
local sg = stargate
local file = files
local FILENAME = "idcs.txt"
local SG
local Ring
local Iris
local IrisType
local IDCs = {}
local PLY
local C = {}
local Sounds = {}
Sounds.Unsafe = sounds.create( ents.self(), "common/warning.wav" )
local Gate = {}
local Gates = {}
local Options = {}
local IrisState = false
Options.Mode = 1
Options.Local = false
Options.Private = false
Options.Blocking = false
Options.Sounds = false
Options.Autoclose = true
wire.createInputs({"Stargate"},{"wirelink"})
local OptionFuncs = {
Blocking = function(a)
SG:setBlocked(a)
end,
Local = function(a)
SG:setLocal(a)
end,
Private = function(a)
SG:setPrivate(a)
end,
Sounds = function(a)
if a then
if SG:overloading() then
Sounds.Overload:play()
elseif SG:inbound() then
Sounds.Inbound:play()
end
else
Sounds.Inbound:stop()
end
end,
Autoclose = function(a)
SG_xwl["Disable Autoclose"] = (not a) and 1 or 0
end
}
SGFunc = {}
SGFunc.stargate_atlantis = function()
if Options["Ring Light"] == nil then
Options["Ring Light"] = false
end
OptionFuncs["Ring Light"] = function(a)
SG_xwl["Turn on ring light"] = a and 1 or 0
end
end
SGFunc.stargate_movie = function()
if Options["Lights"] == nil then
Options["Lights"] = false
end
OptionFuncs["Lights"] = function(a)
SG_xwl["Chevron Light"] = a and 1 or 0
end
end
--Apply the selected options to the Stargate
local ApplyOptions = function()
if SG ~= nil then
for i,v in pairs(Options) do
if OptionFuncs[i] ~= nil then
OptionFuncs[i](v)
end
end
end
end
local function SendLog(string)
Hug.send( MessageIDs.Log, {string} )
end
local function playerByID(id)
local p = find.allPlayers()
for i=1, #p do
if p[i]:steamID() == id then
return p[i]
end
end
return
end
local function IsPlayer( Ply )
return Ply:isPlayer() == true
end
local IrisActive = function()
if Iris ~= nil then
return sg.irisActive(Iris)
end
end
local IDC = { Recieved = function() --[[This is a placeholder]] end }
local OnTeleport = function(ply)
if IrisActive() then
if IsPlayer(ply) and not ply:alive() then
local n = SG:target():address()
if n == "" or n == nil then n = "???" end
local s = n.." > "..SG:address()
chat.botSay( s, " " .. ply:nick() .. " went splat on the iris." )
SendLog( ply:nick() .. " hit the iris." )
else
local m = ply:class() .. " hit the iris"
printConsole( m )
SendLog( m )
end
else
if IsPlayer(ply) then
s = ply:nick()
else
s = ply:class()
end
local log = s .. " came through the Stargate"
SendLog( log )
printConsole( log )
end
end
local SendGateData = function() end
--Find the nearest gate that you own
local GetNearestGate = function()
if wire.ports.Stargate then
SG = wire.ports.Stargate:entity()
SG_xwl = wire.ports.Stargate
else
SG = nil
SG_xwl = nil
--Find all gates, and calculate the closest we own
local pos = ents.self():pos()
local G = sg.getAllStargates()
local D = math.huge
for i=1, #G do
d = G[i]:pos():DistToSqr(pos)
if d < D and G[i]:owner() == ents.owner() then
SG = G[i]
D = d
end
end
if SG == nil or not SG:isValid() then
Hug.send( MessageIDs.Gate, { Type = nil } )
return
--error("You don't own any Stargates")
end
SG_xwl = SG:getWirelink()
end
if SG == nil then printConsole("No gates found") return end
if SGFunc[SG:class()] ~= nil then
SGFunc[SG:class()]()
end
--Set it so that only we have access. Muahaha. (All other players access must be through dialling computer)
--SG:accessList({ ents.owner() })
--Get the iris
Iris = SG:iris()
if Iris ~= nil then
model = Iris:model()
if model == "models/cos/stargate/iris.mdl" or model == "models/zup/stargate/iris.mdl" then
IrisType = "IRIS"
elseif model =="models/zup/stargate/sga_shield.mdl" then
IrisType = "ATL"
elseif model == "models/madman07/shields/goauld_iris.mdl" then
IrisType = "GOAULD"
end
end
--Find the one ring to rule them all
Ring = sg.gateRing(SG)
--Set the gate type specific stuff
local type = SG:class()
if type == "stargate_atlantis" then
Sounds.Inbound = sound.create(ents.self(),"alarm/sga_offworld-alarm.wav")
Sounds.Overload = sound.create(ents.self(),"alarm/sga_selfdestruct-alarm.wav")
else
Sounds.Inbound = sound.create(ents.self(),"alarm/sgc_offworld-alarm.wav")
Sounds.Overload = sound.create(ents.self(),"alarm/sga_midway_selfdestruct.wav")
end
ApplyOptions()
if SG_Old ~= SG then
if SG_Old ~= nil and SG_Old:isValid() then
sg.stopCodeListen(IDC.Recieved,SG_Old)
sg.stopTeleListen(OnTeleport,SG_Old)
end
if SG ~= nil and SG:isValid() then
sg.listenForCode(IDC.Recieved,SG)
SG:listenForTeleport(OnTeleport)
end
SG_Old = SG
end
--SendGateData()
end
local function playerScan(gate)
local pos = gate:pos()
local filter = function(e)
if pos:DistToSqr(e:pos()) < 1048576 then--1024^2
return e
end
end
local players = find.allPlayers(filter)
printConsole("\n--##-- Scanning for players: --##--")
for i,v in ipairs(players) do
printConsole(v:nick())
end
printConsole("--##-- End Scan --##--\n")
end
local function findByAddress(addr)
for i=1, #Gates do
if Gates[i]:address():lower() == addr:lower() then
return Gates[i]
end
end
return nil
end
--Find all the gates on the map, and filter out those we can't dial
local UpdateGates = function()
if SG ~= nil then
local g = sg.getAllStargates()
local G = {}
Gates = {}
local group = SG:group()
local localgate = SG:localgate()
G.Addresses = {}
G.Names = {}
for i=1, #g do
gate = g[i]
if gate ~= nil then
if gate ~= SG and not (gate:group() ~= group and (gate:localgate() or localgate)) then
table.insert(Gates,gate)
end
end
end
--Gates = g
for j=1, #Gates do
G.Addresses[j] = Gates[j]:address()
if Gates[j]:group() ~= group then
G.Addresses[j] = G.Addresses[j] .. Gates[j]:group()
end
G.Names[j] = Gates[j]:name():gsub("%.","")
end
local cks = Hug.checksum(G)
if cks ~= C.gatesum then
printConsole("Updating gate network")
C.gatesum = cks
Hug.send( MessageIDs.GateNetwork, G )
end
end
end
local function IsSafe(gate)
if gate==nil then return true end
iris = gate:iris()
if iris==nil then return true end
return not sg.irisActive(iris)
end
SendGateData = function()
local GD = {}
GD.Active = C.Active
GD.Open = C.Open
GD.Inbound = C.Inbound
GD.Chevrons = {}
c = SG:chevrons()
for i=1, 9 do
local n
if i < 4 then
n = i
elseif i < 8 then
n = i+2
else
n = i-4
end
GD.Chevrons[n] = tonumber(c:sub(i,i))
end
GD.Address = SG_xwl["Dialing Address"]
GD.ChevronLocked = SG_xwl["Chevron Locked"] == 1
GD.Chevron = SG:chevron()
GD.Type = SG:class()
GD.IrisActive = IrisActive()
GD.IrisType = IrisType
GD.Ring = Ring
GD.N = C.N
local col = SG:color()
if GD.Type == "stargate_universe" then
GD.Col = Vector(1,1,1)
else
GD.Col = Vector( col.r/255, col.g/255, col.b/255 )
end
GD.Status = " \nIDLE"
if PLY ~= nil then GD.Status = PLY:nick():sub(1,10):upper().."'s\nIDC RECIEVED"
elseif GD.Inbound then
GD.Status = "INCOMING\nWORMHOLE"
if SG:overloading() then
--GD.OvCol = 255-SG:overloadPercent()*2.55
local oTime = SG:overloadTime()
local mins = math.floor(oTime/60)
local secs = math.floor(oTime-mins*60)
if secs < 10 then secs = "0"..secs end
if mins < 10 then mins = "0"..mins end
GD.Status = "OVERLOADING\n"..mins..":"..secs
end
elseif GD.Open then
if IsSafe(SG:target()) then
GD.Status = "CONNECTION\nSAFE"
else
GD.Status = "CONNECTION\nUNSAFE"
end
elseif GD.Active then GD.Status = " \nDIALLING" end
Hug.send( MessageIDs.Gate, GD )
end
local Dial = function(target,mode)
if mode == nil then mode = Options.Mode end
SG:dial(target,mode)
end
local Close = function()
SG:close()
end
local SetIris = function(on)
if IrisActive() ~= on and Iris ~= nil then
sg.irisToggle(Iris)
end
SendGateData()
end
function IDC.Recieved(idc)
id = IDCs[idc]
if id == nil then
local m = "Invalid IDC recieved"
SendLog( m )
print( m )
else
local ply = playerByID(id)
local m = ply:nick().."'s IDC recieved"
SendLog( m )
print( m )
PLY = ply
SetIris(false)
end
end
local IrisWarning = function()
if Iris == nil then return end
local message
local col
if IrisType == "ATL" or IrisType == "GOAULD" then
if IrisActive() then
message = "WARNING: GATE SHIELD RAISED"
col = Vector(255,0,0)
else
message = "GATE SHIELD LOWERED"
col = Vector(0,255,0)
end
elseif IrisType == "IRIS" then
if IrisActive() then
message = "WARNING: IRIS CLOSED"
col = Vector(255,0,0)
else
message = "IRIS OPENED"
col = Vector(0,255,0)
end
end
if message ~= nil then
if SG:target() == nil then return end
local n = SG:target():address()
if n == "" or n == nil then n = "???" end
local s = n.." > "..SG:address()
chat.botSay( s, col, " "..message )
end
end
local function SaveIDCs()
printConsole("--Saving IDCs to file--")
local r = file.write(FILENAME,von.serialize(IDCs))
if r == true then printConsole("--Save successful--")
elseif r==nil then printConsole("--Save unsuccessful--")
else printConsole(r) end
end
local function OpenIDCs()
if file.exists(FILENAME) then
local string = file.read(FILENAME)
printConsole("Loading IDC file")
IDCs = von.deserialize(string)
if type(IDCs)=="table" then printConsole("--Load successful--")
elseif IDCs==nil then printConsole("--Load unsuccessful--")
else printConsole(IDCs) end
else
printConsole("--No IDC file found--")
print("Open this file in the Starfall editor for a useful guide")
end
end
--Constants. Used for the equivalent of changed(x)
local SaveConstants = function()
C.Active = SG:active()
C.Open = SG:open()
C.Chevrons = SG:chevrons()
C.Iris = IrisActive()
C.Safe = IsSafe(SG:target())
C.Inbound = SG:inbound()
C.Chevron = SG:chevron()
C.SG = SG
C.Overloading = SG:overloading()
end
local GateListen = function()
if SG ~= nil then
if SG:active() ~= C.Active or SG:open() ~= C.Open or SG:chevrons() ~= C.Chevrons or SG:chevron() ~= C.Chevron or IrisActive() ~= C.Iris or IsSafe(SG:target()) ~= C.Safe or SG ~= C.SG or SG:overloading() ~= C.Overloading then
--net.setDTVar( ""
--Changed active
if SG:active() ~= C.Active then
--Has activated
if SG:active() then
--Inbound Connection established
if SG:inbound() then
if Options.Sounds then
Sounds.Inbound:play()
end
if Options["Auto-Iris"] then
SetIris(true)
end
else
end
--Has deactivated
else
PLY = nil
Sounds.Inbound:stop()
if IrisActive() then
SetIris(false)
end
end
end
--Changed open (and open, since closing is the same as deactivating)
if SG:open() ~= C.Open and SG:open() then
playerScan(SG:target())
if Options["Auto-Iris"] and SG:inbound() then
IrisWarning()
end
if ( not SG:inbound() or not Options["Auto-Iris"]==true ) and Options["Safe Mode"] then
time.stimer(4,function() SetIris(false) end)
end
end
--Changed iris state
if IrisActive() ~= C.Iris then
if SG:open() and SG:inbound() and Options["Auto-Iris"] then
IrisWarning()
end
local s = "opened"
if IrisActive() then
s = "closed"
end
end
--Changed chevron
if SG:chevrons() ~= C.Chevrons then
if SG:chevron() >= 4 and Options["Safe Mode"] and not SG:open() then
SetIris(true)
end
end
if SG:overloading() ~= C.Overloading then
if Options.Sounds then
if SG:overloading() then
Sounds.Inbound:stop()
Sounds.Overload:play()
else
Sounds.Overload:stop()
end
end
end
SaveConstants()
C.N = nil
local t = SG:target()
for i=1, #Gates do
if Gates[i] == t then
C.N = i
break
end
end
SendGateData()
end
if SG:overloading() then
SendGateData()
end
end
end
-- Chat commands
local function ParseChat(string,ply)
local Args = StringExplode(string:lower()," ")
cmd = Args[1]
if cmd == "/dial" then
local gate = findByAddress(Args[2])
if gate == nil then
print("Invalid address")
else
Dial(gate)
end
elseif cmd == "/close" then
Close()
elseif cmd == "/iris" then
SetIris(not IrisActive())
elseif cmd == "/idc" then
ply = find.playerByName(Args[2])
if ply == nil then
print("Unknown player")
else
if Args[3] == nil then
for i, v in pairs(IDCs) do
if ply:steamID() == v then
table.remove(IDCs,i)
print(ply:nick().."'s IDC revoked")
SaveIDCs()
end
end
end
idc = tonumber(Args[3])
if idc == nil or string.find(Args[3],"0") ~= nil then
print("Invalid idc - must be numerical with no zeros")
else
IDCs[tostring(idc)] = ply:steamID()
print("IDC "..idc.." assigned to "..ply:nick())
SaveIDCs()
end
end
elseif cmd == "/help" then
local t = {
"/dial ADDRESS Dials the given address",
"/close Closes the gate if it's open",
"/idc PLAYER CODE Sets that player's IDC to the given code",
"/iris T"
}
for i = 1, #t do
print(t[i])
end
else
return --Not a command, don't hide
end
return 1
end
local function CheckSelf() --Check yourself before you wreck yourself
if ents.self():class() ~= "starfall_screen" then
error("Not a Starfall Screen")
end
end
local Init = function()
printConsole("Client Initialised")
CheckSelf()
GetNearestGate()
UpdateGates()
OpenIDCs()
timer.create("Update Gates",5,0,UpdateGates)
timer.create("Apply Options",5,0,ApplyOptions)
timer.create("Update Gate",10,0,GetNearestGate)
timer.create("GateListener",0.2,0,GateListen)
chat.listen(ParseChat, ents.owner())
hook("think","WaitForClient",nil)
end
Hug.register( MessageIDs.Dial, function(t)
local i = tonumber(t[1])
Dial(Gates[i])
end)
Hug.register( MessageIDs.Close, Close )
Hug.register( MessageIDs.Iris, function(t)
IrisState = t[1]
SetIris(IrisState)
end)
Hug.register( MessageIDs.Options, function(t)
Options = t
ApplyOptions()
end)
Hug.register( MessageIDs.Override, function(t)
local tar = SG:target()
if tar == nil then return end
local i = tar:iris()
if i == nil then return end
if sg.irisActive(i) then
sg.irisToggle(i)
end
end)
Hug.register( MessageIDs.CLReady, Init )
hook("input","WireInput",GetNearestGate)
else -------------------------------------------------------------------- CLIENT ------------------------------------------------
local X = 356
local Y = 256
local Polys = {}
local logFont = Screen.render.createFont("Trebuchet",11,500,true)
local Log = {"0000 - Initialising"}
Gate = {}
Gate.Active = false
Gate.Open = false
Gate.Inbound = false
Gate.Chevrons = {0,0,0,0,0,0,0,0,0}
Gate.Chevron = 0
Gate.ChevronLocked = false
Gate.Type = "temp"
Gate.Status = "LOADING\nPLEASE WAIT"
Gate.IrisActive = nil
Gate.IrisType = nil
Gate.Address = ""
Gate.L = 0
Gate.Col = Vector(1,1,1)
N = 1
local Gates = {}
Gates.Addresses = {}
Gates.Names = {}
local Options = {}
local ResetOptions = function()
Options = {}
Options.Mode = 1
Options.Local = false
Options.Private = false
Options.Blocking = false
Options.Sounds = false
Options.Autoclose = true
end
local Modes = {}
Modes[0] = "Slow"
Modes[1] = "Fast"
Modes[2] = "Nox"
local C = {}
C.HSize = 0
C.ISize = 90
C.Init = time.curTime()
local n = 1
local logText = ""
local SendOptions = function()
Hug.send( MessageIDs.Options, Options )
end
local SendIris = function(a)
Hug.send( MessageIDs.Iris, {a} )
end
local Dial = function(n)
Hug.send( MessageIDs.Dial, {n..""} )
end
local Close = function()
Hug.send( MessageIDs.Close, {} )
end
local SortLog = function()
local sorted = {}
for i=1, #Log do
local string = ""
local log = Log[i]
local array = StringExplode( log, " " )
local l = 0
for j=1, #array do
local s = array[j]
local W, H = Screen.render.getTextSize( logFont, string .. " " .. s )
if H > 140 then break
elseif W < 156 then
string = string .. " " .. s
else
table.insert( sorted, #sorted +1 - l, string )
l = l+1
string = " " .. s
end
end
table.insert( sorted, #sorted + 1 - l, string)
end
logText = ""
for i=1, 12 do
if sorted[i] == nil then sorted[i] = "" end
logText = sorted[i] .. "\n" .. logText
end
--logText = string
hook("render","SortLog",nil)
end
local WriteLog = function(s)
if time.curTime() > C.Init + 1 then
local t = tostring(math.floor(time.curTime() - C.Init))
t = string.rep("0",4-t:len())..t
table.insert( Log, 1, t.." - "..s)
Log[13] = nil
hook("render","SortLog",SortLog)
end
end
local GlyphOn = function(g)
return 1
end
--Screens
local Screens = {"STATUS","ADDRESSES","OPTIONS"}
local CurScreen = "STATUS"
local SG = GetStargateSpecs(Gate.Type)
local IR = GetIrisSpecs(Gate.IrisType)
SGFunc = {}
SGFunc.stargate_atlantis = function()
Options["Ring Light"] = false
C.RNum = 0
GlyphOn = function(g)
if not Gate.Active then
return (Options["Ring Light"] and 1 or 0)+1
elseif Gate.Inbound then
return ((g<=C.RNum)and 1 or 0)+1
else
for i=1, 9 do
if g == i*4 and Gate.Chevrons[i] == 1 then return 2 end
end
return 1
end
end
IsInbound = function()
if Gate.Inbound ~= C.Inbound then
if Gate.Open then
C.RNum = SG.divs
elseif Gate.Inbound then
timer.create("Inbound Ring",0.16,SG.divs,function() C.RNum = C.RNum+1 end)
else
timer.remove("InboundRing")
C.RNum = 0
end
end
C.Inbound = Gate.Inbound
end
if Gate.Inbound then
C.RNum = SG.divs
C.Inbound = Gate.Inbound
end
hook("think","IsInbound",IsInbound)
end
SGFunc.stargate_movie = function()
Options["Lights"] = false
end
SGFunc.stargate_universe = function()
GlyphOn = function(g)
if Gate.Address:find(SG.glyphs[g]) then
return 2
else
return 1
end
end
end
local SaveConstants = function()
C.Open = Gate.Open
C.Active = Gate.Active
C.IrisActive = Gate.IrisActive
C.Type = Gate.Type
end
--Clientside gate listener - checks for changes
local GateListen = function()
if Gate.Open ~= C.Open or Gate.Active ~= C.Active or Gate.IrisActive ~= C.IrisActive then
if Gate.Active ~= C.Active and Gate.Active ~= nil then
if Gate.Active then
timer.simple(0.1, function()
local add = Gates.Addresses[N]
if add == nil then add = "UNKNOWN" end
if Gate.Inbound then
WriteLog( "Inbound: "..add )
else
WriteLog( "Dialling "..add )
end
end)
else
if C.Open then
WriteLog( "Connection shut down" )
else
if Gate.ChevronLocked then
WriteLog( "Connection failed [Busy]" )
elseif Gate.Chevron < 0 then
WriteLog( "Connection failed [Power]" )
elseif C.Active ~= nil then
WriteLog( "Dialling interrupted" )
end
end
end
end
if Gate.Open ~= C.Open then
if Gate.Open then
WriteLog( "Connection established" )
time.remove("RemoveHorizon")
time.create("CreateHorizon",0.01,10,function()
if C.HSize < 90 then
C.HSize = C.HSize+10
end
end
)
else
time.remove("CreateHorizon")
time.create("RemoveHorizon",0.01,10,function()
if C.HSize > 0 then
C.HSize = C.HSize-10
end
end
)
end
end
if Gate.IrisActive ~= C.IrisActive then
if Gate.IrisType == "IRIS" then
if Gate.IrisActive then
WriteLog( "Iris closed" )
timer.remove("OpenIris")
timer.create("CloseIris",0.05,100,function()
if C.ISize > 0 then
C.ISize = C.ISize-2
end
end
)
elseif Gate.IrisActive ~= nil then
WriteLog( "Iris opened" )
timer.remove("CloseIris")
timer.create("OpenIris",0.05,100,function()
if C.ISize < 90 then
C.ISize = C.ISize+2
end
end
)
end
end
--Now has an iris, give iris options
if C.IrisActive == nil then
Options["Auto-Iris"] = true
Options["Safe Mode"] = true
SendOptions()
elseif Gate.IrisActive == nil then --Lost the iris
Options["Auto-Iris"] = nil
Options["Safe Mode"] = nil
end
end
end
SaveConstants()
end
Screen.drawChevrons = function()
Screen.setColor(SG.col3*Gate.Col)
for i=1, #Polys.Chevrons do
Screen.render.drawPoly(Polys.Chevrons[i])
end
for i=1, 9 do
local On = Gate.Chevrons[i]
Screen.setColor(SG.colChev[On+1]*Gate.Col)
Screen.render.drawPoly(Polys.Lights[i])
end
end
Screen.drawStargate = function(x,y)
Screen.setColor(SG.col1*Gate.Col)
Screen.render.drawFilledCircle(x,y,126)
Screen.setColor(SG.col2*Gate.Col)
Screen.render.drawFilledCircle(x,y,116)
Screen.setColor(SG.col1*Gate.Col)
Screen.render.drawFilledCircle(x,y,98)
local RingAng
if Gate.Ring == nil or not Gate.Ring:isValid() then
RingAng = 0
else
RingAng = Gate.Ring:ang().r
end
for i=1, SG.divs do
ang = (360/SG.divs * (i+0.5) - RingAng) * math.pi/180
x1 = math.cos(ang) * 116
y1 = math.sin(ang) * 116
Screen.render.drawLine(x+x1,y+y1,x-x1,y-y1)
end
for i, v in ipairs(SG.glyphs) do
ang = (360/SG.divs * i - RingAng)-90
rad = ang * math.pi/180
x1 = math.cos(rad) * 106
y1 = math.sin(rad) * 106
Screen.setColor(SG.glyphCol[GlyphOn(i)]*Gate.Col)
Screen.render.drawTextRotated( v, SG.glyphFont, x+x1, y+y1, ang+90 )--Text font x y angle
end
Screen.setColor(BLUE1)
Screen.render.drawFilledCircle(x,y,90)
if Gate.Type == "stargate_universe" then
Polys = CreateChevrons(x,y,Gate.Type,RingAng)
end
Screen.drawChevrons()
end
Screen.drawHorizon = function( x, y )
local c = SG.horizon + WHITE*(90-C.HSize)/90
Screen.render.setColor( c.x, c.y, c.z, C.HSize/90*255 )
Screen.render.drawFilledCircle( x, y, 90 )
Screen.setColor( BLUE1 )
Screen.render.drawFilledCircle( x, y, 90-C.HSize )
end
Screen.drawIris = function(x,y)
Screen.setColor(IR.col)--*Gate.Col)
local size = IR.size
if Gate.IrisType == "ATL" or Gate.IrisType == "GOAULD" then
Screen.render.drawFilledCircle(x,y,size)
elseif Gate.IrisType == "IRIS" then
Screen.render.drawFilledCircle(x,y,size)
if Gate.Open then
Screen.setColor(SG.horizon)
else
Screen.setColor(BLUE1)
end
Screen.render.drawFilledCircle(x,y,C.ISize)
end
end
Screen.drawGateStatus = function()
Screen.setColor( WHITE )
Screen.render.drawText( "Trebuchet22", 256, 450, Gate.Status, 1 )
Screen.createButton( "ADMIN OVERRIDE", 256, 450, 128, 64)
end
Screen.draw = {}
--Status Screen
Screen.draw.STATUS = function()
Screen.drawStargate(X,Y)
Screen.drawHorizon(X,Y)
if Gate.IrisActive == true or C.ISize < 90 then
Screen.drawIris(X,Y)
end
local x = 20
local w1 = 32
local w2 = 90
--Screen Context
Screen.drawDataline(1,x,256+32,w1,w2,"DIAL")
Screen.drawDataline(2,x,256+64,w1,w2,"CLOSE")
Screen.drawDataline(3,x,256+96,w1,w2,"NEXT")
Screen.drawDataline(4,x,256+128,w1,w2,"PREV")
--Log
Screen.setColor(BLUE2)
Screen.render.drawLine(24,80,24,180)
Screen.render.drawLine(24,80,40,64)
Screen.render.drawLine(190,120,190,220)
Screen.render.drawLine(190,220,174,236)
Screen.setColor(WHITE)
local W, H = Screen.render.getTextSize( logFont, logText )
Screen.render.drawText( logFont, 32, 232 - H, logText )
for i=1, Gate.Address:len() do
Screen.render.drawText( SG.font, X + (i-5)*28, 79, Gate.Address:sub(i,i), 1 )
end
Screen.setColor(BLUE2)
for i=1, 10 do
local x = X-14 + (i-5)*28
Screen.render.drawLine( x, 80, x, 100 )
end
end
--Addresses Screen
Screen.draw.ADDRESSES = function()
Screen.setColor(BLUE2)
local top = 64
local bottom = 376
local left = 32
Screen.render.drawRectOutline(left,top,512-left*2,bottom-top)
Screen.render.drawRectOutline(left-5,top-5,522-left*2,bottom-top+10)
--Vertical
Screen.render.drawLine(64,top,64,bottom)
Screen.render.drawLine(224,top,224,bottom)
Screen.render.drawLine(416,top,416,bottom)
--Horizontal
for i=1, 11 do
y = top+26*i
Screen.render.drawLine(left,y,512-left,y)
end
--Headings
Screen.setColor(WHITE)
Screen.render.drawText("Trebuchet22", 144, 66, "ADDRESS", 1)
Screen.render.drawText("Trebuchet22", 320, 66, "NAME", 1)
Screen.render.drawText("Trebuchet22", 448, 66, "DIAL", 1)
for i=n, n+10 do
local y = top+26*(i+1-n) + 5
if i < n+10 then
Screen.render.drawText("Trebuchet16", 48, y, tostring(i), 1)
end
local Address = Gates.Addresses[i]
local Name = Gates.Names[i]
if Address == nil then Address = "-"
elseif Address == "" then Address = "[ - ]" end
if Name == nil then Name = "-"
elseif Name == "" then Name = "[Unnamed]" end
Screen.render.drawText("Trebuchet16", 144, y, Address, 1)
Screen.render.drawText("Trebuchet16", 320, y, Name, 1)
Screen.render.drawText(SG.font, 448, y-3, string.char(64+i), 1)
Screen.createButton(i, 256, y+8, 448, 26)
end
--Arrows
Screen.render.drawPoly({{38,82},{48,70},{58,82}})
Screen.createButton("UP",48,77,32,26)
Screen.render.drawPoly({{38,358},{58,358},{48,370}})
Screen.createButton("DOWN",48,363,32,26)
end
--Options Screen
Screen.draw.OPTIONS = function()
local x = 256
local y = 226
local angles = {30,115,190,300,160,260,70,340,230}
Screen.setColor(BLUE2)
Screen.render.drawFilledCircle(x, y, 90)
local j, n = 0, 0
for a, b in pairs(Options) do
n = n+1
end
for i, v in pairs(Options) do
j = j+1
Screen.setColor(BLUE2)
local ang = -360/n*j + n -- -angles[j]
local p = RotateVert({x,y-115},{x,y},ang)
local col = WHITE
if v == false then
col = GREY
end
local text = i
if type(v) ~= "boolean" then
text = i..": "..Modes[v]
end
Screen.render.drawLine(x,y,p[1],p[2])
Screen.drawDataline(i,p[1],p[2]+16,16,96,text,col,(-180)>ang)
end
Screen.setColor(BLUE1)
Screen.render.drawFilledCircle(x, y, 75)
end
--Draw navigation area
Screen.drawNav = function()
local x = 20
local w1 = 32
local w2 = 90
--Change screen buttons
local c = 0
for i, v in ipairs(Screens) do
--Ignore the current screen's button
if v == CurScreen then
c = -1
else
Screen.drawDataline(v,x,416+32*(i+c),w1,w2,v)
end
end
--Draw the divide beteen the nav menu and the context area
Screen.setColor(BLUE2)
Screen.render.drawLine(12,408,180,408)
Screen.render.drawLine(180,408,212,440)
Screen.render.drawLine(212,440,500,440)
Screen.setColor(WHITE)
local cur = Gates.Names[N]
if cur == nil or cur == "" then cur = Gates.Addresses[N] end
if cur == nil or cur == "" then cur = "-" end
Screen.render.drawText("Trebuchet22",X,413,cur,1)
local ir = ""
if Gate.IrisActive == true then ir = "IRIS CLOSED"
elseif Gate.IrisActive ~= nil then ir = "IRIS OPEN" end
Screen.drawDataline("IRIS",512-x,480,w1,w2,ir,WHITE,1)
end
Screen.Render = function()
Screen.render.clear()
Screen.drawBackground()
Screen.drawBorder("Dialling Computer")
Screen.drawNav()
Screen.drawGateStatus()
Screen.draw[CurScreen]()
Screen.drawCLOpCounter()
end
Screen.NoGate = function()
Screen.render.clear()
Screen.drawBackground()
Screen.drawBorder("Dialling Computer")
Screen.drawNav()
Screen.setColor(BLUE2)
Screen.render.drawFilledCircle(256,310,16,16)
Screen.render.drawFilledCircle(256,210,20,60)
Screen.setColor(WHITE)
Screen.render.drawText("Trebuchet24",256,210,"ERROR: No Stargate",1)
Screen.drawCLOpCounter()
end
--Touch screen
Screen.Use = function(Ply)
if Ply == nil then return end
local X, Y = Screen.render.cursorPos(Ply)
--Button name i, Button v
for i, v in pairs(Screen.buttons) do
if v:pressed(X,Y) then
if type(i) == "number" then
if CurScreen == "STATUS" then
if i==1 then
Dial(N)
elseif i==2 then
Close()
else
local n = 7 - i*2
N = N+n
if N == 0 then N = #Gates.Addresses
elseif N > #Gates.Addresses then N = 1
end
end
return
elseif CurScreen == "ADDRESSES" then
if Gates.Addresses[i] ~= nil and Gates.Addresses[i] ~= "" then
N = i
if X > 416 then
Dial(i)
end
end
return
end
else
--Change Screens
for j=1, #Screens do
if i==Screens[j] then
CurScreen = i
return
end
end
--Iris Button
if i == "IRIS" then
SendIris(not Gate.IrisActive==true)
return
elseif i == "ADMIN OVERRIDE" and Ply == ents.owner() then
Hug.send( MessageIDs.Override, {} )
return
elseif CurScreen == "OPTIONS" then
if i ~= "Mode" then
Options[i] = not Options[i]
if i == "Lights" then
if Options[i] then
SG.colChev[2] = Vector(255,130,0)
else
SG.colChev[2] = Vector(70,70,70)
end
end
else
Options[i] = Options[i] + 1
if Options[i] > 2 then
Options[i] = 0
end
end
SendOptions()
return
elseif CurScreen == "ADDRESSES" then
if i == "UP" and n > 1 then
n = n-1
elseif i == "DOWN" and n <= #Gates.Addresses-10 then
n = n+1
end
end
end
end
end
end
local RT = rendertarget.create( Screen.render.getIsHighRes() )
local NextRender = time.sysTime()
local TargetFrameTime = 1/60
function Screen.setRender(renderfunc)
hook( "render", "UpdateRT", function()
local Time = time.curTime()
if Time < NextRender-0.001 then return end
RT:DrawToTexture( renderfunc )
NextRender = Time + TargetFrameTime
end )
end
Hug.register( MessageIDs.Gate, function(t)
Gate = t
IR = GetIrisSpecs(Gate.IrisType)
if Gate.Type == nil then
Screen.setRender(Screen.NoGate)
elseif Gate.Type ~= C.Type then
Screen.setRender(Screen.Render)
SG = GetStargateSpecs(Gate.Type)
Polys = CreateChevrons(X,Y,Gate.Type)
ResetOptions()
if SGFunc[Gate.Type] ~= nil then
SGFunc[Gate.Type]()
end
end
if Gate.N ~= nil then
N = Gate.N
end
end)
Hug.register( MessageIDs.GateNetwork, function(t)
Gates = t
end)
Hug.register( MessageIDs.Log, function(t)
WriteLog( t[1] )
end)
Polys = CreateChevrons(X,Y,Gate.Type)
hook( "render", "DrawRT", function()
RT:Draw( 0, 0, 512, 512 )
end )
hook( "render", "SortLog", SortLog )
hook( "starfall_used", "Screen Used", Screen.Use )
timer.start( "Gate Listener", 0.1, 0, GateListen )
Hug.send( MessageIDs.CLReady, {} )
end |