Author Topic: Televator (one asgard teleporter)  (Read 10221 times)

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Televator (one asgard teleporter)
« on: September 24, 2016, 01:03:54 am »
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 teleporter
It 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.

Code: [Select]
@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)
   
}

« Last Edit: September 24, 2016, 09:19:11 pm by kevinminion »

Shifty

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +2/-34
    • View Profile
  • IGN: Shifty
Re: Televator (one asgard teleporter)
« Reply #1 on: September 24, 2016, 11:30:51 am »
@kevinminion


Great job on the E2!


You may want to add the function of auto-updating, because I will be using them on moving ships and warping stations.

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Re: Televator (one asgard teleporter)
« Reply #2 on: September 24, 2016, 09:19:54 pm »
@RendStung @Shifty

I have updated a few things for version 1.1

Please see above