Chat Warp (Chat Driven Warp Chip) - Avorius - 17-11-2021
Hello all,
I made this Starfall chip donkey's years ago for myself mainly under the purpose of not having to go to a warp screen, or having a mainframe on board (Could be a Drive Core/Gyroscope shuttle or something similar) and to instead do it all from my chatbox.
After a while I decided to update the chip with what I call my Modular Chat System (Or M.C.S. for short), improve some functions around the place and fix a bunch of general bugs.
I've pasted the code below, enjoy and happy warping!
-George
P.S. I've also uploaded this to my Starfall Shared folder under: George > public > chatwarp.txt
--@name Chat Warp
--@author George
--@class processor
--@dependency STEAM_0:0:145101342 libs/mcs.txt
require("libs/mcs.txt") -- This just tells the chip to use the Modular Chat System I made.
-- This section is the chat system configuration, each are customisable
----------------------------------------------------
MCSVars["ChatTag"] = "C.W." --
MCSVars["TagColour"] = ents.owner():getTeamColor()--
MCSVars["ChatColour"] = Color(255,255,255) --
MCSVars["ChatPrefix"] = "/" --
----------------------------------------------------
broadcast("Type ",MCSVars["ChatPrefix"],"help in chat to receieve the list of commands for this chip") -- 'Broadcast' is the function I made in the chat system to print messages, using your custom variables
function autoWirelink(x) -- This function facilitates the automatic wirelinking of each warp drive, itll default to the first drive in the list that you have on your ship (ill add a function to change that on tuesday)
local driveTypes = {"bsg_drive", "quantum_slipstream_drive", "spore_drive", "st_warp_drive", "sg_hyperdrive"}
local add2WL = {}
for i=1,#driveTypes do
local Table = find.byClass(driveTypes[i],function(Ent) if Ent:owner() == ents.owner() then add2WL[#add2WL+1] = Ent end end)
end
BSGDrive = nil
QSDrive = nil
SPDrive = nil
STDrive = nil
SGDrive = nil
ValidDrives = {}
for i = 1,#add2WL do
if add2WL[i]:class() == "bsg_drive" then
BSGDrive = add2WL[i]:getWirelink()
ValidDrives[#ValidDrives + 1] = BSGDrive
elseif add2WL[i]:class() == "quantum_slipstream_drive" then
QADrive = add2WL[i]:getWirelink()
ValidDrives[#ValidDrives + 1] = QADrive
elseif add2WL[i]:class() == "spore_drive" then
SPDrive = add2WL[i]:getWirelink()
ValidDrives[#ValidDrives + 1] = SPDrive
elseif add2WL[i]:class() == "st_warp_drive" then
STDrive = add2WL[i]:getWirelink()
ValidDrives[#ValidDrives + 1] = STDrive
elseif add2WL[i]:class() == "sg_hyperdrive" then
SGDrive = add2WL[i]:getWirelink()
ValidDrives[#ValidDrives + 1] = SGDrive
end
end
end
timer.create("UpdateWL", 1, 0, autoWirelink) -- This just updates the wirelink every second forever
WarpVecs = {}
WarpNames = {}
prevLoc = Vector(0,0,0)
--[[Universe Co-Ords]]--
WarpVecs["hiigara"] = Vector( 7233.18, 8624.72, -5006.35 )
WarpVecs["desert"] = Vector( 9854.70, -10693.44, -8444.55 )
WarpVecs["lava"] = Vector( -9754.43, -105.95, -3562.54 )
WarpVecs["universe"] = Vector( 7385.85, -2656.28, -6099.56 )
WarpVecs["asteroids"] = Vector( -847.53, -2208.65, -3274.53 )
--[[Pegasus Co-Ords]]--
WarpVecs["shakuras"] = Vector( -7507.86, -7344.48, 8284.30 )
WarpVecs["pegasus"] = Vector( 2046.19, -8507.82, 9335.28 )
WarpVecs["station"] = Vector( 8492.68, -9132.07, 9554.00 )
--[[Milkyway Co-Ords]]--
WarpVecs["earth"] = Vector( -505.55, 8090.60, 8921.81 )
WarpVecs["moon"] = Vector( -4463.02, 13613.67, 10532.53 )
WarpVecs["milkyway"] = Vector( -8357.80, 6864.69, 9980.18 )
--[[Misc Co-Ords]]--
WarpVecs["build1"] = Vector( 10097.53, 12261.29, -15329.73 )
WarpVecs["build2"] = Vector( 10097.53, 4027.18, -15329.73 )
WarpVecs["build3"] = Vector( 10097.53, -4094.64, -15329.73 )
WarpVecs["build4"] = Vector( 10097.53, -12318.82, -15329.73 )
--[[Universe Names]]--
WarpNames["hiigara"] = "Hiigara | Chat Name: hiigara"
WarpNames["desert"] = "Desert | Chat Name: desert"
WarpNames["lava"] = "Lava | Chat Name: lava"
WarpNames["universe"] = "Universe Space | Chat Name: universe"
WarpNames["asteroids"] = "Asteroids | Chat Name: asteroids"
--[[Pegasus Names]]--
WarpNames["shakuras"] = "Shakuras | Chat Name: shakuras"
WarpNames["pegasus"] = "Pegasus Space | Chat Name: pegasus"
WarpNames["station"] = "Pegasus Station Hangar | Chat Name: station"
--[[Milkyway Names]]--
WarpNames["earth"] = "Earth | Chat Name: earth"
WarpNames["moon"] = "The Moon | Chat Name: moon"
WarpNames["milkyway"] = "Milkyway Space | Chat Name: milkyway"
--[[Misc Names]]--
WarpNames["build1"] = "Build Room 1 | Chat Name: build1"
WarpNames["build2"] = "Build Room 2 | Chat Name: build2"
WarpNames["build3"] = "Build Room 3 | Chat Name: build3"
WarpNames["build4"] = "Build Room 4 | Chat Name: build4"
function warpDInfo(index)
local WV = WarpVecs[index]
local WN = WarpNames[index]
if WV ~= nil and WN ~= nil then
return WarpVecs[index],WarpNames[index]
else
return
end
end
function destName( value )
if value ~= nil then
return WarpNames[value]
end
end
createCMD("warp", function(PLC, loc)
--PLC: Player Command (Just means any word after the command function, in this case being 'warp'
--loc: The location to grab from the table of co-ordinates above
if PLC == nil then
broadcast("Please enter a location to warp to ",ents.owner():name())
elseif PLC == "to" then
local dest = warpDInfo(loc)
if dest ~= nil then
prevLoc = ValidDrives[1]:entity():pos()
ValidDrives[1]["Destination"] = dest
ValidDrives[1]["Activate"] = 1
broadcast("Warping to ", destName(loc))
else
broadcast("Please enter a valid location ",ents.owner():name())
end
else--this makes sure if someone doesnt use 'warp to *loc*', itll still register
local loc = PLC
local dest = warpDInfo(loc)
if dest ~= nil then
prevLoc = ValidDrives[1]:entity():pos()
ValidDrives[1]["Destination"] = dest
ValidDrives[1]["Activate"] = 1
broadcast("Warping to ", destName(loc))
else
broadcast("Please enter a valid location ",ents.owner():name())
end
end
end, "w") --To add additional aliases to each command, add a comma, then your desired alias inside two "
createCMD("locations",function()
for k,v in pairs(WarpNames) do
printConsole(v)
end
broadcast("Printed all stored locations in the console ",ents.owner():name())
end,"loc","locs")
createCMD("back",function()
if ValidDrives[1] ~= nil then
ValidDrives[1]["Destination"] = prevLoc
ValidDrives[1]["Activate"] = 1
broadcast("Warping to the ship's previous location ",ents.owner():name())
end
end)
createCMD("here",function()
if ValidDrives[1] ~= nil then
prevLoc = ValidDrives[1]:entity():pos()
ValidDrives[1]["Destination"] = ents.owner():pos()
broadcast("Warping the ship to you ",ents.owner():name())
end
end)
createCMD("help", function()
broadcast("All the commands for this chip have been posted in the console!")
printConsole("Chat Warp Chip Commands:\nwarp or w \nlocations, loc or locs \nhere\nhelp")
end)
autoWirelink(1)
RE: Chat Warp (Chat Driven Warp Chip) - The17thDoctor - 17-11-2021
A pretty good starfall by the looks of it !
A few suggestions that could make your code more interesting would be to merge Warp Names and Vectors into a single variable called WarpDestination like this :
WarpDestination = {Name = "Hiigara", Vec = Vector(x, y, z)}
This way, your destination informations would be pretty easy to access in one time.
You could also run the wirelink each time you execute a command that would require such wirelink to be made like the warp command.
This way you would avoid to re-run the code every second and thus wasting precious quota (even though the loss is minimal given the function ran every sec)
I would also suggest to avoid adding prevLoc = Vector(), setting it to nil or to the chip's current position would be wiser to make sure users can't accidentally warp back to a destination they've never been to, especially when this destination is 0 0 0. To go further, you could also make it a warp history, with the ability to rewind destinations until the first one registered by the chip.
RE: Chat Warp (Chat Driven Warp Chip) - Avorius - 17-11-2021
Quote:
WarpDestination = {Name = "Hiigara", Vec = Vector(x, y, z)}
This way, your destination informations would be pretty easy to access in one time.
Thats a good idea, would for sure help with streamlining everything and cutting down on bulk, I'll look into adding this on the next version of the chip
Quote:
You could also run the wirelink each time you execute a command that would require such wirelink to be made like the warp command.
This way you would avoid to re-run the code every second and thus wasting precious quota (even though the loss is minimal given the function ran every sec)
Hmm, I probably will change the current way I'm doing the wirelinking completely in the next version, likely utilising hooks to update the chip's wirelinks, and possibly add a function that enables drive-switching and the like.
Quote:
I would also suggest to avoid adding prevLoc = Vector(), setting it to nil or to the chip's current position would be wiser to make sure users can't accidentally warp back to a destination they've never been to, especially when this destination is 0 0 0.
Oops, seems I didn't iron out all of the bugs, I'll update that to be nil instead of Vector()
Afaik when the vector is set to (0, 0, 0) the drive won't engage either way, as your ship would end up in the wall, but, it's better to be safe than sorry. Thanks for pointing that out.
Quote:
To go further, you could also make it a warp history, with the ability to rewind destinations until the first one registered by the chip.
That would be something I would add in the next version, as I feel it would take a lot of time away from me making the other components of this 'little' project I'm working on.
All in all, thank you for the suggestions on this Doc, any other ideas/bugs you find, please let me know 
-George
RE: Chat Warp (Chat Driven Warp Chip) - Avorius - 18-11-2021
Quick update for ya'll,
Just finished adding a rotation function into the chip as I realised earlier that I forgot to implement one.
If you're already using it, you shouldn't have to update the chip (as it hopefully will do so automatically), in the case that you do you can just re-download it from my shared section.
For those of you who have no interest in using the chip and want to see the code for that section, here it is:
createCMD("rotate",function(PLC)
if ValidDrives[1] ~= nil then
if PLC ~= nil then
broadcast("Rotating ship by ", PLC,"°")
ValidDrives[1]["Angle Offset"] = Angle(ValidDrives[1]:entity():ang().p, tonumber(PLC), ValidDrives[1]:entity():ang().r)
ValidDrives[1]["Destination"] = ValidDrives[1]:entity():pos()
ValidDrives[1]["Activate"] = 1
end
else
broadcast("You do not have a warp drive on your ship ",ents.owner():name()) return
end
end,"r")
I also updated all the commands with this bit of code, to make sure the user knows if they don't have a Warp Drive on their ship, instead of the ship quietly blanking them:
else
broadcast("You do not have a warp drive on your ship ",ents.owner():name()) return
end
Happy Warping!
-George
|