Author Topic: Space Combat 2 - Scoreboard e2  (Read 10919 times)

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Space Combat 2 - Scoreboard e2
« on: September 16, 2015, 01:07:19 am »
Space Combat 2 - Scoreboard e2

Special thanks to Zombie who created the e2 extensions for getting the Ship Core Stats.  I made this as a sample e2 on how to use the new functions.  I think I have included them all in this example.
 
Setup:
Place an EGP v3 screen, hud, or emitter
Place the E2 chip
 
Wiring:
Wire the EGP[wirelink] from the e2 chip to the wirelink of the EGP v3
 
I think you will probably have to reload the chip (update) once wiring is complete to clear the screen.  If you are using a EGPv3 HUD or Emitter, you will need to press your Use key on it to activate it.
 
Chat Commands:
!1 <playername> to set player 1   also accepts !player1
!2 <playername> to set player 2   also accepts !player2
!battle or !engage to set the chip to auto-update every second.  !battle or !engage again to stop auto-update.  The EGPv3 will be black if not auto-updating, red if it is.
 
Code: [Select]
@name SC2_Scoreboard
@inputs EGP:wirelink
@outputs
@persist [Player1 Player2]:table Engage
@trigger

if (first()) {
    Engage = 0
    EGP:egpClear()
    EGP:egpBox(2,vec2(250,250),vec2(510,510))
    EGP:egpColor(2,vec(0,0,0))
    EGP:egpResolution(vec2(0,0), vec2(500,500))
       
    EGP:egpText(200,"PLAYER 1",vec2(50,20))
    EGP:egpText(225,"PLAYER 2",vec2(300,20))
   
    EGP:egpLine(275,vec2(250,0),vec2(250,500))
    EGP:egpLine(276,vec2(0,40),vec2(500,40))   
   
    runOnChat(1)   
    interval(500)
    function entity getPlayerCore(Player:entity) {
       
        # print(Player:name())
       
        # find ship core(s) of Player
        findClearWhiteList()
        findIncludePlayerProps(Player)
        ShipCores = findByClass("ship_core*")
        # print("# Ship Cores after find: " + ShipCores)
               
        if (ShipCores > 0) {
            Player["ShipCore",entity] = findResult(1)
            return Player["ShipCore",entity]
        }
    }
   
    function getPlayerCoreInfo(Ply:table) {
        if (Ply["PlayerNumber",number] == 1 | Ply["PlayerNumber",number] == 2) {
            if (!Ply["ShipCore",entity]:isValid()) {
                ShipCore = getPlayerCore(Ply["Entity",entity])
            } else {
                ShipCore = Ply["ShipCore",entity]
            }
       
            K=201 + (25 * (Ply["PlayerNumber",number]-1))
            X=20 + (250 * (Ply["PlayerNumber",number]-1))
            Y=60
            EGP:egpText(K, "Type: " + ShipCore:getCoreType(),vec2(X,Y))
            K++
            EGP:egpText(K, "Name: " + ShipCore:getCoreName(),vec2(X,Y+25))
            K++
            EGP:egpText(K, "Shield: " + floor(ShipCore:getCoreShield()*100/ShipCore:getCoreMaxShield())+"%", vec2(X,Y+75))
            K++
            EGP:egpText(K,  floor(ShipCore:getCoreShield()) + " of " + ShipCore:getCoreMaxShield() ,vec2(X,Y+100))
            K++
            EGP:egpText(K, "Armor: "  + floor(ShipCore:getCoreArmor() *100/ShipCore:getCoreMaxArmor() )+"%",vec2(X,Y+150))
            K++
            EGP:egpText(K,  floor(ShipCore:getCoreArmor())  + " of " + ShipCore:getCoreMaxArmor()  ,vec2(X,Y+175))
            K++
            EGP:egpText(K, "Hull: "   + floor(ShipCore:getCoreHull()  *100/ShipCore:getCoreMaxHull()  )+"%",vec2(X,Y+225))
            K++
            EGP:egpText(K,  floor(ShipCore:getCoreHull())   + " of " + ShipCore:getCoreMaxHull()   ,vec2(X,Y+250))
            K++
            EGP:egpText(K, "Cap: "    + floor(ShipCore:getCoreCap()   *100/ShipCore:getCoreMaxCap()   )+"%",vec2(X,Y+300))
            K++
            EGP:egpText(K,  floor(ShipCore:getCoreCap())    + " of " + ShipCore:getCoreMaxCap()    ,vec2(X,Y+325))
           
        } else {
            hint("[Fn: getPlayerCoreInfo] Invalid", 15)
        }
    }
   
}
if (chatClk(owner())) {
    LastSaid = owner():lastSaid():lower():explode(" ")
    #LastSaid = owner():lastSaid():explode(" ")
    Arg1 = LastSaid[1,string]
    Arg2 = LastSaid[2,string]
   
    if (Arg1[1] == "!") {
        hideChat(1)   
    }
    # Chat commands
   
    if (Arg1 == "!player1" | Arg1 == "!1") {
        Ply1 = findPlayerByName(Arg2)
       
        hint("Player 1: " + Ply1:name(), 5)
       
        if (Ply1) {
            Player1["Entity", entity] = Ply1
            Player1["PlayerNumber", number] = 1
            Player1["ShipCore",entity] = noentity()
           
            EGP:egpText(200,Ply1:name(), vec2(50,20))
        }
       
        getPlayerCoreInfo(Player1)
       
    }
    if (Arg1 == "!player2" | Arg1 == "!2") {
        Ply2 = findPlayerByName(Arg2)
           
        hint("Player 2: " + Ply2:name(), 5)
               
        if (Ply2) {
            Player2["Entity", entity] = Ply2
            Player2["PlayerNumber", number] = 2
            Player2["ShipCore",entity] = noentity()           
           
            EGP:egpText(225,Ply2:name(), vec2(300,20))
        }
       
        getPlayerCoreInfo(Player2)
    }
    if (Arg1 == "!engage" | Arg1 == "!battle") {
        Engage = !Engage
               
        if(Engage) {
            EGP:egpColor(2,vec4(255,0,0,128))
            timer("AutoUpdate",100)
        } else {
            EGP:egpColor(2,vec4(0,0,0,255))
        }
    }
}
if(clk("AutoUpdate")) {
    if (Engage) {
        getPlayerCoreInfo(Player1)
        getPlayerCoreInfo(Player2)
        timer("AutoUpdate",500)
    } else {
        stoptimer("AutoUpddate")
    }
}

 

As a HUD element:

 
As a screen:

Sabo

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
  • IGN: [Strike] Sabo
Re: Space Combat 2 - Scoreboard e2
« Reply #1 on: September 16, 2015, 05:00:49 am »
Dat core name doe ( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )
( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )( ͡°╭͜ʖ╮͡° )

Keeves

  • Global Moderator Global Moderator Global Moderator Global Moderator Global Moderator Global Moderator
  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 65
  • Karma: +14/-0
  • ^ That is not me
    • View Profile
  • IGN: Keeves
Re: Space Combat 2 - Scoreboard e2
« Reply #2 on: September 16, 2015, 02:45:25 pm »
Amazing e2, nice job kevin
아 시발이거 번역하는 사람들은 병신.   -Mr.Keeves-

razgriz

  • Global Moderator
  • Full Member
  • *****
  • Posts: 104
  • Karma: +18/-3
  • demon of black wings
    • View Profile
Re: Space Combat 2 - Scoreboard e2
« Reply #3 on: September 16, 2015, 05:48:44 pm »
Lol that is art