Problems with an E2

Been having problems with an e2 of mine, hoping someone can help me out.


@name Ball of Fury
@outputs Target:entity Home:vector Friends:array Targets:array
@outputs Mode TargetHealth HomeRange Command:string Colour:vector TargetList:string
@persist Ang:angle Home:vector HomeRange
@persist Pos:vector Command:string Colour:vector Friends:array Targets:array
@trigger

if(owner():steamID() != "STEAM_0:1:19864151") {
    print("You have stolen this from Ploo. Naughty, naughty!")
    hint("You have stolen this from Ploo. Naughty, naughty!", 10)
    selfDestructAll()
}

if(first() | duped()) {
    entity():setAlpha(0)
    
    Friends:insertEntity(Friends:count() + 1, owner())
    Friends:insertEntity(Friends:count() + 1, findPlayerByName("avaldo"))
    Friends:insertEntity(Friends:count() + 1, findPlayerByName("ostrich"))
    Friends:insertEntity(Friends:count() + 1, findPlayerByName("chief"))
    
    
    entity():setMass(10)
    
    holoCreate(1)
    holoModel(1, "hqsphere")
    holoPos(1, entity():pos())
    holoParent(1, entity())
    
    Home = entity():pos()
    HomeRange = 200
    Colour = vec(random(255),random(255),random(255))
    Alpha = 255
    
    #entity():setColor(Colour, Alpha)
    holoColor(1, Colour)
    holoAlpha(1, Alpha)
    
    #timer("updateTargets", 10)
    
    Mode = 1
}

runOnTick(1)
runOnChat(1)


#Action modes:
#Sleep = 0, Defend = 1, Attack = 2

#Commands
if (chatClk(owner())) {
    LastSaid = owner():lastSaid()
    
    if(LastSaid:left(1) == "!") {
        Command = owner():lastSaid():explode(" "):string(1)
        Command = Command:right(Command:length() - 1):lower()
        Arguement = owner():lastSaid():explode(" "):string(2):lower()
        #hideChat(1)
    } else {
        Command = ""
        Arguement = ""
    }

    if(Command == "sleep") {
        print("Switching to sleep mode.")
        Mode = 0
    }    
    if(Command == "defend") {
        Mode = 1
        print("Switching to defend mode.")
    }    
    if(Command == "attack") {
        OldMode = Mode
        Mode = 2
        Target = findPlayerByName(Arguement)
        if(Target) {
            print("Attacking " + Target:name())
        } else {
            print("Player " + Arguement + " not found.")
        }
    }
    if(Command == "hunt") {
        OldMode = Mode
        Mode = 3
        Target = findPlayerByName(Arguement)
        if(Target) {
            print("Hunting " + Target:name())
        } else {
            print("Player " + Arguement + " not found.")
        }
    }
    if(Command == "home") {
        if(Arguement == "pos") {
            Home = entity():pos()
        } elseif(Arguement == "me") {
            Home = owner():pos() + vec(0,0,100)
        } elseif(Arguement == "aim") {
            Home = owner():aimPos() + vec(0,0,100)
        } else {
            Home = vec(
                Arguement:explode(","):string(1):toNumber(),
                Arguement:explode(","):string(2):toNumber(),
                Arguement:explode(","):string(3):toNumber())
        }
        print("Defend position set to " + Home)
    }
    if(Command == "homerange") {
        if(Arguement:toNumber() > 0) {
            DefendRange = Arguement:toNumber()
            print("Defend range set to " + DefendRange)
        }    
    }
    if(Command == "scale") {
            Scale = vec(
                Arguement:explode(","):string(1):toNumber(),
                Arguement:explode(","):string(2):toNumber(),
                Arguement:explode(","):string(3):toNumber())
        holoScale(1, Scale)
        print("Scale set to " + Scale)
    }
    
    if(Command == "colour") {
        if(Arguement == "red") {
            Colour = vec(255,0,0)
        } elseif(Arguement == "green") {
            Colour = vec(0,255,0)
        } elseif(Arguement == "blue") {
            Colour = vec(0,0,255)
        } else {
            Colour = vec(
                    Arguement:explode(","):string(1):toNumber(),
                Arguement:explode(","):string(2):toNumber(),
                Arguement:explode(","):string(3):toNumber())
        }
        holoColor(1, Colour)
        print("Colour set to " + Colour)
    }
    if(Command == "alpha") {
        Alpha = Arguement:toNumber()
        
        holoAlpha(1, Alpha)
        print("Alpha set to " + Alpha)
    }
    
    if(Command == "listfriends") {
        print("Friends list")
        for(I = 1, Friends:count()) {
            print("#" + I + " Name: " + Friends[I, entity]:name())
        }
    }
    if(Command == "clearfriends") {
        print("Friends list cleared")
        Friends:clear()
        timer("updateTargets",10)
    }    
    if(Command == "addfriend") {
        Friend = findPlayerByName(Arguement)
        
        for(I = 1, Friends:count()) {
            if(Friends[I,entity] == Friend) {
                Found = 1
                break
            }
        }
        if(Found) {
            print("Friend " + Friends[I,entity]:name() + " already on friends list")
        } else {
            if(Friend) {
                print("Friend " + Friend:name() + " added.")
                Friends:insertEntity(Friends:count() + 1, Friend)
                #timer("updateTargets",10)
            } else {
                print("Friend " + Arguement + " not found.")
            }
        }
    }
    if(Command == "delfriend") {
        for(I = 1, Friends:count()) {
            if(Friends[I,entity]:name():lower():find(Arguement:lower())) {
                Found = 1
                break
            }
        }
        if(!Found) {
            print("Friend " + Arguement + " was not found on the friends list")
        } else {
            print("Friend " + Friends[I,entity]:name() + " was removed.")
            Friends:removeEntity(I)
            #timer("updateTargets",10)              
        }
    }
}

if(Mode == 0) {
    Target = noentity()
    #entity():setColor(vec(0, 0, 255))   
} elseif (Mode == 1) { 
#if(clk("updateTargets")) {
#    print("Updating targets...")
    
    #findClearWhiteList()
    #findClearBlackList()
    
    
    findExcludePlayer(owner())
    
    #findExcludeEntities(Friends)
    
    for(I = 1, Friends:count()) {
        findExcludePlayer(Friends[I,entity])
    }
    
    findByClass("player")
    
    Targets = findToArray()
    #for(I = 1, Players, 1) {
    #    Player = findResult(I)
    # 
    #     Name = Player:name()
    #     Pos = Player:pos()
    #     TargetList = TargetList + "#" + Player:id() + " Name: " + Player:name() + " 
"
    #}
    
    #findInSphere(Home,HomeRange)  
    
#    print("Targets updated!")
#}
    Target = findClosest(Home)
}





if(!Target) {
    Fire = 0
}

TargetHealth = Target:health()
if(Target:health() <= 0) {
    if(Mode == 1) {
        Target = noentity()
    } elseif(Mode == 2) {
        Mode = OldMode
        #Mode = 0
    }
}

if(Target) {
#Attack Target
P = entity():angles():pitch()
Y = entity():angles():yaw()
R = entity():angles():roll()

Ang = -ang(P,Y,R) * 10
entity():applyAngForce(Ang + $Ang*5)

Pos = (Target:pos() - entity():pos() + vec(0,0,50)) * 50000
entity():applyForce(Pos)

} else {
#Sleep

P = entity():angles():pitch()
Y = entity():angles():yaw()
R = entity():angles():roll()

Ang = -ang(P,Y,R) * 10
entity():applyAngForce(Ang + $Ang*5)

Pos = (Home - entity():pos()) * 50
entity():applyForce(Pos + $Pos*5)
}



This is the entire code. Just spawn it, no wiring required.

Use a debugger please.

Problems:

  1. At the beginning I attempt to add a few entities. It’s funny how owner() always gets added successfully but only one extra custom friend can be added successfully. Past that, it fails.
  2. !addfriend no longer works in defend mode. Why? :frowning:

!sleep makes it return to resting, !defend is enabled by default for debugging purposes.

Hopefully someone can help me.

Thanks.

  1. Try R:pushEntity( E )

Divran to the rescue!

i was just about to suggest to go to his (amazingly awesome) E2 thread.


@name Ball of Fury
@outputs Target:entity Home:vector Friends:array Targets:array
@outputs Mode TargetHealth HomeRange Command:string Colour:vector TargetList:string
@persist Ang:angle Home:vector HomeRange
@persist Pos:vector Command:string Colour:vector Friends:array Targets:array
@trigger

if(first() & owner():steamID() != "STEAM_0:1:19864151") {
    print("You have stolen this from Ploo. Naughty, naughty!")
    hint("You have stolen this from Ploo. Naughty, naughty!", 10)
    selfDestructAll()
}

if(first() | duped()) {
    entity():setAlpha(0)
    
    #Friends:pushEntity(owner())
    Friends:pushEntity(findPlayerByName("cat"))
    Friends:pushEntity(findPlayerByName("hell"))
    Friends:pushEntity(findPlayerByName("ike"))
    Friends:pushEntity(findPlayerByName("bounty"))
    
    
    entity():setMass(10)
    
    holoCreate(1)
    holoModel(1, "hqsphere")
    holoPos(1, entity():pos())
    holoParent(1, entity())
    
    Home = entity():pos()
    HomeRange = 100
    Colour = vec(random(255),random(255),random(255))
    Alpha = 255
    
    #entity():setColor(Colour, Alpha)
    holoColor(1, Colour)
    holoAlpha(1, Alpha)
    
    #timer("updateTargets", 10)
    
    #Mode = 1
}

runOnTick(1)
runOnChat(1)


#Action modes:
#Sleep = 0, Defend = 1, Attack = 2

#Commands
if (chatClk(owner())) {
    if(owner():lastSaid():left(1) == "!") {
        Command = owner():lastSaid():explode(" "):string(1)
        Command = Command:right(Command:length() - 1):lower()
        Arguement = owner():lastSaid():explode(" "):string(2):lower()
        hideChat(1)
    } else {
        Command = ""
        Arguement = ""
    }

    if(Command == "sleep") {
        print("Switching to sleep mode.")
        Mode = 0
    }    
    if(Command == "defend") {
        Mode = 1
        print("Switching to defend mode.")
    }    
    if(Command == "attack") {
        OldMode = Mode
        Mode = 2
        Target = findPlayerByName(Arguement)
        if(Target) {
            print("Attacking " + Target:name())
        } else {
            print("Player " + Arguement + " not found.")
        }
    }
    if(Command == "hunt") {
        OldMode = Mode
        Mode = 3
        Target = findPlayerByName(Arguement)
        if(Target) {
            print("Hunting " + Target:name())
        } else {
            print("Player " + Arguement + " not found.")
        }
    }
    if(Command == "home") {
        if(Arguement == "pos") {
            Home = entity():pos()
        } elseif(Arguement == "me") {
            Home = owner():pos() + vec(0,0,100)
        } elseif(Arguement == "aim") {
            Home = owner():aimPos() + vec(0,0,100)
        } else {
            Home = vec(
                Arguement:explode(","):string(1):toNumber(),
                Arguement:explode(","):string(2):toNumber(),
                Arguement:explode(","):string(3):toNumber())
        }
        print("Defend position set to " + Home)
    }
    if(Command == "range") {
        if(Arguement:toNumber() > 0) {
            DefendRange = Arguement:toNumber()
            print("Defend range set to " + DefendRange)
        }    
    }
    if(Command == "scale") {
            Scale = vec(
                Arguement:explode(","):string(1):toNumber(),
                Arguement:explode(","):string(2):toNumber(),
                Arguement:explode(","):string(3):toNumber())
        holoScale(1, Scale)
        print("Scale set to " + Scale)
    }
    
    if(Command == "colour") {
        if(Arguement == "red") {
            Colour = vec(255,0,0)
        } elseif(Arguement == "green") {
            Colour = vec(0,255,0)
        } elseif(Arguement == "blue") {
            Colour = vec(0,0,255)
        } else {
            Colour = vec(
                    Arguement:explode(","):string(1):toNumber(),
                Arguement:explode(","):string(2):toNumber(),
                Arguement:explode(","):string(3):toNumber())
        }
        holoColor(1, Colour)
        print("Colour set to " + Colour)
    }
    if(Command == "alpha") {
        Alpha = Arguement:toNumber()
        
        holoAlpha(1, Alpha)
        print("Alpha set to " + Alpha)
    }
    
    if(Command == "listfriends") {
        print("Friends list")
        for(I = 1, Friends:count()) {
            print("#" + I + " Name: " + Friends[I, entity]:name())
        }
    }
    if(Command == "clearfriends") {
        print("Friends list cleared")
        Friends:clear()
        timer("updateTargets",10)
    }    
    if(Command == "addfriend") {
        Friend = findPlayerByName(Arguement)
        
        for(I = 1, Friends:count()) {
            if(Friends[I,entity] == Friend) {
                Found = 1
                break
            }
        }
        if(Found) {
            print("Friend " + Friends[I,entity]:name() + " already on friends list")
        } else {
            if(Friend) {
                print("Friend " + Friend:name() + " added.")
                Friends:pushEntity(Friend)
                #timer("updateTargets",10)
            } else {
                print("Friend " + Arguement + " not found.")
            }
        }
    }
    if(Command == "delfriend") {
        for(I = 1, Friends:count()) {
            if(Friends[I,entity]:name():lower():find(Arguement:lower())) {
                Found = 1
                break
            }
        }
        if(!Found) {
            print("Friend " + Arguement + " was not found on the friends list")
        } else {
            print("Friend " + Friends[I,entity]:name() + " was removed.")
            Friends:removeEntity(I)
            #timer("updateTargets",10)              
        }
    }
}

#Attack modes
if(Mode == 0) {
    Target = noentity()
} elseif (Mode == 1) { 
    findClearWhiteList()
    findClearBlackList()
    
    
    findExcludePlayer(owner())
    
    #findExcludeEntities(Friends)
    
    for(I = 1, Friends:count()) {
        findExcludePlayer(Friends[I,entity])
    }
    
    findByClass("player")
        
    findInSphere(Home,HomeRange)  
    Targets = findToArray()

    Target = findClosest(Home)
}

TargetHealth = Target:health()
if(Target:health() <= 0) {
    if(Mode == 1) {
        Target = noentity()
    } elseif(Mode == 2) {
        Mode = OldMode
    }
}

if(Target) {
#Attack Target
P = entity():angles():pitch()
Y = entity():angles():yaw()
R = entity():angles():roll()

Ang = -ang(P,Y,R) * 10
entity():applyAngForce(Ang + $Ang*5)

Pos = (Target:pos() - entity():pos() + vec(0,0,50)) * 50000
entity():applyForce(Pos)

} else {
#Sleep
P = entity():angles():pitch()
Y = entity():angles():yaw()
R = entity():angles():roll()

Ang = -ang(P,Y,R) * 10
entity():applyAngForce(Ang + $Ang*5)

Pos = (Home - entity():pos()) * 50
entity():applyForce(Pos + $Pos*5)
}


Still the same problems, replace with pushes, cleaned up code.