Televator v1.1
@RendStung @Shifty SETUP:
Place two target finders, an asgard teleporter (and power), and then place the e2 on the asgard teleporter. The chip will auto-find the two target finders and auto-wire the teleporter. If you have more than two target finders, results may not be consistent. It should find the two target finders closest to the chip.
USE:
Step on either target finder to go to the other.
NOTE 1:
The E2 chip only "finds" the target finders once, so if you move them, you will need to reload the chip. Let me know if you plan on putting this in a moving ship and I will change that.
The E2 will constantly update the position of the chip every second.
NOTE 2:
I could have it auto-detect and wire the asgard teleporterIt now does this.
NOTE 3: I couldn't get it to trigger automatically when I stepped on the target finder, hence the Finder and LastFinder variables. If I could remedy this, I could get rid of the interval() statement.
v1.1 still idled under 10 ops when I was testing.
@name Televator_v1.1
# By Kevin Minion
# 09/24/2016 v1.0 Original Code
# v1.1 Request to update GPS for target finders as ships move
#
# PURPOSE: To auto-teleport using target finders and a single asgard teleprter
# Idea from Shifty / RendStung
@inputs Teleporter:wirelink
@outputs
@persist ArrFinders:array
@persist WireLinkFinder1:wirelink WireLinkFinder2:wirelink
@persist Finder1:entity Finder2:entity LastFinder1:entity LastFinder2:entity
@persist GPS1:vector GPS2:vector
@trigger
interval(1000) # Check every second
if (first() || dupefinished()) {
# Find target finders, sort by distance
findIncludePlayerProps(owner())
findByClass("gmod_wire_target_finder")
findSortByDistance(entity():pos())
ArrFinders = findToArray()
print("Found " + ArrFinders:count() + " target finders")
# Save the wirelinks of the target finders for later
WireLinkFinder1 = ArrFinders[1,entity]:wirelink()
WireLinkFinder2 = ArrFinders[2,entity]:wirelink()
# Clear the Teleporter input of this chip
entity():deleteWire("Teleporter")
# Wire the Teleporter input of this chip to the Asgard teleporter it is welded to
if (entity():isWeldedTo():model() != "models/boba_fett/props/asgard_console/asgard_console.mdl") {
print("This chip MUST be welded to the asgard teleporter!")
} else {
Worked = entity():createWire(entity():isWeldedTo(),"Teleporter","wirelink")
if (Worked) {
hint("createWire worked!",3)
} else {
hint("createWire failed!",3)
}
}
}
GPS1 = ArrFinders[1,entity]:pos()
GPS2 = ArrFinders[2,entity]:pos()
Finder1 = WireLinkFinder1["1_Ent",entity]
Finder2 = WireLinkFinder2["1_Ent",entity]
if ((Finder1!=LastFinder1) && Finder1:isPlayer() && Finder1:isAlive()) {
Teleporter["Origin",vector] = GPS1
Teleporter["Dest" ,vector] = GPS2
timer("Send",350)
} elseif ((Finder2!=LastFinder2) && Finder2:isPlayer() & Finder2:isAlive()) {
Teleporter["Origin",vector] = GPS2
Teleporter["Dest" ,vector] = GPS1
timer("Send",350)
}
LastFinder1 = Finder1
LastFinder2 = Finder2
if (clk("Send")) {
Teleporter["Send" ,number] = 1
timer("clear",200)
}
if (clk("clear")) {
Teleporter["Send" ,number] = 0
Teleporter["Origin",vector] = vec(0,0,0)
Teleporter["Dest" ,vector] = vec(0,0,0)
}