+ Reply to Thread
Results 1 to 9 of 9

Thread: Need help with entity discovery

  1. #1
    Inactive thirty9th is on a distinguished road thirty9th's Avatar
    Join Date
    Nov 2007
    Posts
    69

    Default Need help with entity discovery

    Hello, everyone. I'm a long-time lurker of the WireMod forums, looking for a little help on a small project of mine.

    I've been working on a small robot/drone that follows me, usually over my head, and responds to chat commands. I've had some success so far; 39Botv1 is able to stay with me at great speeds, look in whatever direction I am, or aim at specified coordinates. It also says hello when asked and changes color on command.

    I need some help with the defense/combat portion of 39Bot. Currently, I am trying to get it to target a player and aim at it based on a chat command that I issue. I'm not very experienced with entity discovery, so can someone tell me why this code wouldn't work?

    Most of the outputs and persist variables are for debugging purposes, and please excuse my shoddy organization.

    The relevant code areas are highlighted.

    Code:
    @name Follow Cube V1
    @inputs
    @outputs Bearing Varc1 Varc2 Varc3 Playername:string Pos:vector
    @persist Force_final:angle Vector1:vector Varc1 Varc2 Varc3 
    @persist Follow Aim PlayerTar:entity Playername:string
    
    runOnTick(1)
    ##### SETTINGS #####
    Box = entity():isWeldedTo()
    Owner = Box:owner()
    Box:setMass(50)
    ##### CALCULATIONS #####
    if ( Aim == 0 ) {
        P = Box:angles():pitch()
        Y = Box:angles():yaw()
        R = Box:angles():roll()
    }
    if ( Aim == 1 ) {
        P = Box:angles():pitch()
        Y = Box:bearing(Owner:aimPos())
        R = Box:angles():roll()
    }
    if ( Aim == 2 ) {
        P = Box:elevation(Owner:aimPos())
        Y = Box:bearing(Owner:aimPos())
        R = Box:angles():roll()
    }
    if ( Aim == 3 ) {
        Playername = Owner:lastSaid():lower():sub(13,50):trim()
        findIncludePlayer(Playername)
        PlayerTar = find()
        P = Box:elevation(PlayerTar:pos())
        Y = Box:bearing(PlayerTar:pos())
        R = Box:angles():roll()
    }
    ##### PYR MOVEMENT #####
    Force_final = -ang(P,Y,R) * 70
    Box:applyAngForce(Force_final + $Force_final*5)
    ##### XYZ MOVEMENT #####
    if ( Follow ) {
        Vector1 = (Owner:pos() - Box:pos() + vec(0,0,100)) * 500
        Box:applyForce(Vector1 + $Vector1*5)
    }
    ##### SPEECH #####
    runOnChat(1)
    if (Owner:lastSaid():lower() == "hello, 39bot." & chatClk(Owner)) {
        print("Hello, master.")
    }
    if (Owner:lastSaid():lower():sub(0,6) == "[color" & chatClk(Owner)) {
        Varc1 = Owner:lastSaid():lower():sub(8,10):toNumber()
        Varc2 = Owner:lastSaid():lower():sub(12,14):toNumber()
        Varc3 = Owner:lastSaid():lower():sub(16,18):toNumber()
        Box:setColor(Varc1,Varc2,Varc3)
    }
    if (Owner:lastSaid():lower():sub(0,11) == "[killplayer" & chatClk(Owner)) {
        Aim = 3
    }
    if (Owner:lastSaid():lower() == "[passive" & chatClk(Owner)) {
        Follow = 1
        Aim = 1
    }
    if (Owner:lastSaid():lower() == "[follow" & chatClk(Owner)) {
        Follow = 1
    }
    if (Owner:lastSaid():lower() == "[stop" & chatClk(Owner)) {
        Follow = 0
    }
    if (Owner:lastSaid():lower() == "[off" & chatClk(Owner)) {
        Follow = 0
        Aim = 0
    }
    if (Owner:lastSaid():lower() == "[look" & chatClk(Owner)) {
        Aim = 1
    }
    if (Owner:lastSaid():lower() == "[aim" & chatClk(Owner)) {
        Aim = 2
    }
    
    Any help is appreciated.

  2. #2
    Wire Amateur adeeda is on a distinguished road adeeda's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    86

    Default Re: Need help with entity discovery

    You'll probably want to find the player in your chat section, as it can be found just when you say the player's name.

    You'll want to use findPlayerByName(Playername) rather than findInclude. findInclude just includes that player in future finds, and is redundant if you're finding him by his name. However, the P Y and R should stay in the (AIM=3) section, as you'll want those calculated every tick.

    I'm not sure how to overhaul your chat code, and I'm not sure how to include finding the name in your current chat code.... Someone else can help with that.
    Anne drew Andrew and Drew, and Druanne drew Anne, Drew, Andrew, and Ru.
    AnDrEw in-game.

  3. #3
    Inactive thirty9th is on a distinguished road thirty9th's Avatar
    Join Date
    Nov 2007
    Posts
    69

    Default Re: Need help with entity discovery

    Ah! Success. Thanks for that findPlayerByName() function. With a little reorganization, it ended up working; The find function and assigning it to PlayerTar just had to be done once, under the runOnTick(1) section. Otherwise it was just flickering back and forth between 0 many times per second.

    39bot will now aim at me when I say "[killplayer Sir. 39".

    Your help is much appreciated.

    Updated code if you're interested in the developement.

    Thanks again for your help.

    Code:
    @name Follow Cube V1
    @inputs
    @outputs Bearing Varc1 Varc2 Varc3 Playername:string Pos:vector Aim
    @persist Force_final:angle Vector1:vector Varc1 Varc2 Varc3 
    @persist Follow Aim PlayerTar:entity Playername:string
    
    runOnTick(1)
    ##### SETTINGS #####
    Box = entity():isWeldedTo()
    Owner = Box:owner()
    Box:setMass(50)
    ##### CALCULATIONS #####
    if ( Aim == 0 ) {
        P = Box:angles():pitch()
        Y = Box:angles():yaw()
        R = Box:angles():roll()
    }
    if ( Aim == 1 ) {
        P = Box:angles():pitch()
        Y = Box:bearing(Owner:aimPos())
        R = Box:angles():roll()
    }
    if ( Aim == 2 ) {
        P = Box:elevation(Owner:aimPos())
        Y = Box:bearing(Owner:aimPos())
        R = Box:angles():roll()
    }
    if ( Aim == 3 ) {
        Pos = PlayerTar:pos()
        P = Box:elevation(PlayerTar:pos())
        Y = Box:bearing(PlayerTar:pos())
        R = Box:angles():roll()
    }
    ##### PYR MOVEMENT #####
    Force_final = -ang(P,Y,R) * 70
    Box:applyAngForce(Force_final + $Force_final*5)
    ##### XYZ MOVEMENT #####
    if ( Follow ) {
        Vector1 = (Owner:pos() - Box:pos() + vec(0,0,100)) * 500
        Box:applyForce(Vector1 + $Vector1*5)
    }
    ##### SPEECH #####
    runOnChat(1)
    if (Owner:lastSaid():lower() == "hello, 39bot." & chatClk(Owner)) {
        print("Hello, master.")
    }
    if (Owner:lastSaid():lower():sub(0,6) == "[color" & chatClk(Owner)) {
        Varc1 = Owner:lastSaid():lower():sub(8,10):toNumber()
        Varc2 = Owner:lastSaid():lower():sub(12,14):toNumber()
        Varc3 = Owner:lastSaid():lower():sub(16,18):toNumber()
        Box:setColor(Varc1,Varc2,Varc3)
    }
    if (Owner:lastSaid():lower():sub(0,11) == "[killplayer" & chatClk(Owner)) {
        Playername = Owner:lastSaid():lower():sub(13,50):trim()
        PlayerTar = findPlayerByName(Playername)
        Aim = 3
    }
    if (Owner:lastSaid():lower() == "[passive" & chatClk(Owner)) {
        Follow = 1
        Aim = 1
    }
    if (Owner:lastSaid():lower() == "[follow" & chatClk(Owner)) {
        Follow = 1
    }
    if (Owner:lastSaid():lower() == "[stop" & chatClk(Owner)) {
        Follow = 0
    }
    if (Owner:lastSaid():lower() == "[off" & chatClk(Owner)) {
        Follow = 0
        Aim = 0
    }
    if (Owner:lastSaid():lower() == "[look" & chatClk(Owner)) {
        Aim = 1
    }
    if (Owner:lastSaid():lower() == "[aim" & chatClk(Owner)) {
        Aim = 2
    }
    

  4. #4
    Inactive thirty9th is on a distinguished road thirty9th's Avatar
    Join Date
    Nov 2007
    Posts
    69

    Default Re: Need help with entity discovery

    New problem! I'm adding a function to 39Bot that allows the user to say "[killclosest", which causes it to target the nearest player or NPC and kill it. Once again, the entity discovery functions are eluding me and I need some assistance.

    Why isn't this working?

    RELEVANT CODE AREA
    Code:
    if (Owner:lastSaid():lower() == "[killclosest" & chatClk(Owner)) {
        findClosest(Owner:pos))
        AimTar = find()
        AimTarmod = vec(0,0,0)
        Aim = 4
        print("Attempting to terminate target.")
    }
    

    FULL CODE
    Code:
    @name 39Bot
    @inputs
    @outputs Fire Light:vector Yes AimTarmod:vector AimTar:entity
    @persist Force_final:angle Vector1:vector Varc1 Varc2 Varc3 
    @persist Follow Aim PlayerTar:entity Playername:string
    @persist ObjectTar:entity Objectname:string AimTar:entity
    @persist AimTarmod:vector
    
    runOnTick(1)
    ##### SETTINGS #####
    Box = entity():isWeldedTo()
    Owner = Box:owner()
    Box:setMass(50)
    ##### CALCULATIONS #####
    if ( Aim == 0 ) {
        P = Box:angles():pitch()
        Y = Box:angles():yaw()
        R = Box:angles():roll()
    }
    if ( Aim == 1 ) {
        P = Box:angles():pitch()
        Y = Box:bearing(Owner:aimPos())
        R = Box:angles():roll()
    }
    if ( Aim == 2 ) {
        P = Box:elevation(Owner:aimPos())
        Y = Box:bearing(Owner:aimPos())
        R = Box:angles():roll()
    }
    if ( Aim == 3 ) {
        P = Box:elevation(PlayerTar:pos()+vec(0,0,60))
        Y = Box:bearing(PlayerTar:pos())
        R = Box:angles():roll()
        PlayerTarH = PlayerTar:health()
           if ( PlayerTarH > 0 ) {
                Fire = 1 
            }
            elseif ( PlayerTarH <= 0 ) {
                Fire = 0
                print("Target is down.")
                interval(3000)
                Aim = 1 
            }
    }
    if ( Aim == 4 ) {
            if ( AimTar:model():sub(0,11) == "models/head" ) { AimTarmod = vec(0,0,-60)  Yes = 1}
            if ( AimTar:model():sub(0,11) == "models/antl" ) { AimTarmod = vec(0,0,-55) }
            if ( AimTar:model():sub(0,50):trim() == "models/zombie/classic_torso.mdl" ) { AimTarmod = vec(0,0,-55) }        
            if ( AimTar:model():sub(0,50):trim() == "models/zombie/fast_torso.mdl" ) { AimTarmod = vec(0,0,-55) }
            if ( AimTar:model():sub(0,50):trim() == "models/combine_scanner.mdl" ) { AimTarmod = vec(0,0,-60) }
            if ( AimTar:model():sub(0,50):trim() == "models/manhack.mdl" ) { AimTarmod = vec(0,0,-60) }
            if ( AimTar:model():sub(0,50):trim() == "models/crow.mdl" | "models/pigeon.mdl" | "models/seagull.mdl" ) { AimTarmod = vec(0,0,-60) }
        P = Box:elevation(AimTar:pos()+vec(0,0,60)+AimTarmod)
        Y = Box:bearing(AimTar:pos())
        R = Box:angles():roll()
        AimTarH = AimTar:health()
            if ( AimTarH > 0 ) {
                Fire = 1
            }
            elseif ( AimTarH <= 0 ) {
                Fire = 0
                print("Target is down.")
                interval(3000)
                Aim = 1
            }
    }
    ##### PYR MOVEMENT #####
    Force_final = -ang(P,Y,R) * 100
    Box:applyAngForce(Force_final + $Force_final*5)
    ##### XYZ MOVEMENT #####
    if ( Follow ) {
        Vector1 = (Owner:pos() - Box:pos() + vec(0,0,100)) * 500
        Box:applyForce(Vector1 + $Vector1*5)
    }
    ##### SPEECH #####
    runOnChat(1)
    if (Owner:lastSaid():lower() == "hello, 39bot." & chatClk(Owner)) {
        print("Hello, master.")
    }
    if (Owner:lastSaid():lower():sub(0,6) == "[color" & chatClk(Owner)) {
        Varc1 = Owner:lastSaid():lower():sub(8,10):toNumber()
        Varc2 = Owner:lastSaid():lower():sub(12,14):toNumber()
        Varc3 = Owner:lastSaid():lower():sub(16,18):toNumber()
        Box:setColor(Varc1,Varc2,Varc3)
        hint("Color changed.",7)
    }
    if (Owner:lastSaid():lower():sub(0,11) == "[killplayer" & chatClk(Owner)) {
        Playername = Owner:lastSaid():lower():sub(13,50):trim()
        PlayerTar = findPlayerByName(Playername)
        Aim = 3
        print("Attempting to terminate target.")
    }
    if (Owner:lastSaid():lower():sub(0,11) == "[killtarget" & chatClk(Owner)) {
        AimTar = Owner:aimEntity()
        AimTarmod = vec(0,0,0)
        Aim = 4
        print("Attempting to terminate target.")
    }
    if (Owner:lastSaid():lower() == "[killclosest" & chatClk(Owner)) {
        findClosest(Owner:pos))
        AimTar = find()
        AimTarmod = vec(0,0,0)
        Aim = 4
        print("Attempting to terminate target.")
    }
    if (Owner:lastSaid():lower() == "[passive" & chatClk(Owner)) {
        Follow = 1
        Aim = 1
        hint("Passive mode.",7)
    }
    if (Owner:lastSaid():lower() == "[follow" & chatClk(Owner)) {
        Follow = 1
        hint("Following.",7)
    }
    if (Owner:lastSaid():lower() == "[stop" & chatClk(Owner)) {
        Follow = 0
        Fire = 0
        hint("Stopping.",7)
    }
    if (Owner:lastSaid():lower() == "[off" & chatClk(Owner)) {
        Follow = 0
        Aim = 0
        Fire = 0
        Light = vec(0,0,0)
        hint("Turning off.",7)
    }
    if (Owner:lastSaid():lower() == "[look" & chatClk(Owner)) {
        Aim = 1
        hint("Look mode.",7)
    }
    if (Owner:lastSaid():lower() == "[aim" & chatClk(Owner)) {
        Aim = 2
        hint("Aim mode.",7)
    }
    if (Owner:lastSaid():lower() == "[lighton" & chatClk(Owner)) {
        Light = vec(255,255,255)
        hint("Light on.",7)
    }
    if(Owner:lastSaid():lower() == "[lightoff" & chatClk(Owner)) {
        Light = vec(0,0,0)
        hint("Light off.",7)
    }
    if(Owner:lastSaid():lower() == "[lightdim" & chatClk(Owner)) {
        Light = vec(100,100,100)
        hint("Light dimmed.",7)
    }
    if(Owner:lastSaid():lower() == "[info" & chatClk(Owner)) {
        AimTar = Owner:aimEntity()
        if ( AimTar:isPlayer() ) { 
            print("Target is a player.") 
            print("Name:"+AimTar:name())
            print("Health:"+AimTar:health())
            print("Armor:"+AimTar:armor())
            print("Frags:"+AimTar:frags())
        }
        if ( AimTar:isNPC() ) { 
            print("Target is an NPC.")
            print("Type:"+AimTar:model())
            print("Health:"+AimTar:health())
        }
        if ( AimTar:isVehicle() ) {
            print("Target is a vehicle.")
            print("Type:"+AimTar:model())
        }
        if ( AimTar:isWorld() ) {
            print("Target is the world geometry.")
        }
        if ( !AimTar:isPlayer() & !AimTar:isNPC() & !AimTar:isVehicle() & !AimTar:isWorld() ) {
            print("Target is a prop or other object.")
            print("Type:"+AimTar:model())
            print("Mass:"+AimTar:mass())
            print("Size:"+AimTar:radius())
        }
    }
    

  5. #5
    Long Haired Hippie Dude
    Asphid will become famous soon enough Asphid's Avatar
    Join Date
    Oct 2008
    Location
    In a house.
    Posts
    617

    Default Re: Need help with entity discovery

    Code:
        findClosest(Owner:pos))
    
    <Anticept>Will sex for food.
    <Beer>peanus, I like that
    <nath2008uk>I must play with black peanus
    <Jat Goodwin>i like the underage one
    <Black Phoenix>He's a good pedo

  6. #6
    Inactive thirty9th is on a distinguished road thirty9th's Avatar
    Join Date
    Nov 2007
    Posts
    69

    Default Re: Need help with entity discovery

    Code:
    AimTar = findClosest(Owner:pos())
    
    So this should find the entity nearest to me and store it to AimTar?

    For some reason this doesn't find ANY entities for me... Should it work for NPC's as well?

  7. #7
    Long Haired Hippie Dude
    Asphid will become famous soon enough Asphid's Avatar
    Join Date
    Oct 2008
    Location
    In a house.
    Posts
    617

    Default Re: Need help with entity discovery

    The code I said was the first thing that popped out at me, since you were missing a parenthesis. But you need to use one of the find functions,
    Code:
    findInSphere(V,N)  N  Finds entities in a sphere around V with a radius of N, returns the number found after filtering   
    findInCone(V,V,N,A)  N  Like findInSphere but with a cone, arguments are for position, direction, length, and degrees (currently bugged, because the underlying function is bugged)   
    findInBox(V,V)  N  Like findInSphere but with a globally aligned box, the arguments are the diagonal corners of the box   
    findByName(S)  N  Find all entities with the given name   
    findByModel(S)  N  Find all entities with the given model   
    findByClass(S)  N  Find all entities with the given class
    
    findClosest finds the closest result from the things you find.

    For instance, you could do
    Code:
    findInSphere(Owner:pos(), 1000)
    Tar = findClosest(Owner:pos()
    
    <Anticept>Will sex for food.
    <Beer>peanus, I like that
    <nath2008uk>I must play with black peanus
    <Jat Goodwin>i like the underage one
    <Black Phoenix>He's a good pedo

  8. #8
    Inactive thirty9th is on a distinguished road thirty9th's Avatar
    Join Date
    Nov 2007
    Posts
    69

    Default Re: Need help with entity discovery

    Thanks for the information. Though, I've heard that findInSphere, among other functions, is broken due to an update?

  9. #9
    Inactive thirty9th is on a distinguished road thirty9th's Avatar
    Join Date
    Nov 2007
    Posts
    69

    Default Re: Need help with entity discovery

    Sorry for the double post, but none of these are working. My turret aims towards (0,0,0) world position when I attempt to feed it a find() target.

+ Reply to Thread

Similar Threads

  1. Entity Discovery, LUA error after a few tries.
    By vortexnl in forum Expression Help
    Replies: 0
    Last Post: 05-21-2009, 06:33 AM
  2. Entity Discovery Searching
    By Playzr in forum Expression Help
    Replies: 9
    Last Post: 05-16-2009, 09:04 AM
  3. Learning Entity Discovery.
    By vortexnl in forum Expression Help
    Replies: 10
    Last Post: 05-03-2009, 03:16 PM
  4. Entity Discovery Bugs
    By goluch in forum Expression Help
    Replies: 9
    Last Post: 04-19-2009, 01:06 PM
  5. Expression 2 - Entity Discovery
    By chiss in forum Wiremod Tutorials
    Replies: 12
    Last Post: 03-17-2009, 12:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts