+ Reply to Thread
Results 1 to 5 of 5

Thread: Chat commands and entity discovery, works but is imperfect

  1. #1
    Lurker hyperchickens is on a distinguished road hyperchickens's Avatar
    Join Date
    May 2009
    Posts
    20

    Default Chat commands and entity discovery, works but is imperfect

    I have been working on a script using information and tutorials on the forums, wiki, and internet in general that makes props you spawn orbit around a set target, which by default is the e2 chip. I have chat commands to change the target and also the props that orbit, but its not perfect.

    When the chip is spawned the currently existing props will begin to orbit, but when they are dropped with the chat command, using the pick up command will not pick them up unless the chip is re-uploaded.

    The script which originally inspired me to make this (which i haven't used as any sort of reference) can pick up props without having to reset the chip, but i no longer have the script so i cant compare it to mine.

    Also, when the targeting command is used, props will fly to the origin. And will return when i use the null command.

    If anyone can tell me what is wrong with my entity discovery code and point me in the right direction, it would be 3.5% more excellent than expensive ice cream and i would appreciate it.

    Code:
    @name proporbit
    @persist Counter Theta TotalProps OrbitHeight P Y R OrbitSpeed Radius Orbit
    @persist FoundProps:array TargArray:array String:array
    @persist Facing:angle Inertia:angle Chpfl:vector DiffPos:vector Dest:vector
    @persist OrbitTarg:entity
    
    ##################### Chat Commands
    if(first()|duped()) {
        runOnTick(1)
        runOnChat(1)
        OrbitTarg = entity()
        Orbit = 0
        OrbitHeight = 100         
        Radius = 300
        OrbitSpeed = 1
        runOnChat(1)
        findClearWhiteList()
        findIncludePlayerProps(owner())    
        findByClass("prop_physics") 
        FoundProps = findToArray()
    }
    if(chatClk(owner())) {
        if(owner():lastSaid():left(4) == "face") {
            String = lastSaid():explode(" ")
            Name = String:string(2)
            if(Name=="null") {
                FaceTarg=entity()
            }elseif(Name=="aim") {
                #FaceTarg=owner():eye()
            }else{
                FaceTarg = findPlayerByName(Name)
            }
        }elseif(owner():lastSaid():left(5) == "orbit") {
            String = lastSaid():explode(" ")
            Name = String:string(2)
            if(Name=="null") {
                OrbitTarg=entity()
            }else{
                OrbitTarg = findPlayerByName(Name)
            }
        }elseif(owner():lastSaid():left(3) == "set") {
            String = lastSaid():explode(" ")
            Var = String:string(2)
            Val = String:string(3):toNumber()
            if(Var=="radius") {
                Radius=Val
            }elseif(Var=="orbitheight") {
                OrbitHeight=Val
            }elseif(Var=="orbitspeed") {
                OrbitSpeed=Val
            }
        }elseif(owner():lastSaid():left(4) == "prop") {
            String = lastSaid():explode(" ")
            Cmd = String:string(2)
            if(Cmd=="drop") {
                Temp = FoundProps:removeEntity(1)
                Temp:setColor(255,255,255,255)
                Temp:setMaterial("")
            }elseif(Cmd=="dropfirst") {
                Temp = FoundProps:popEntity()
                Temp:setColor(255,255,255,255)
                Temp:setMaterial("")
            }elseif(Cmd=="excludefirst") {
                Temp = FoundProps:popEntity()
                Temp:setColor(255,255,255,255)
                Temp:setMaterial("")
                findExcludeEntity(Temp) 
            }elseif(Cmd=="exclude") {
                Temp = FoundProps:removeEntity(1)
                Temp:setColor(255,255,255,255)
                Temp:setMaterial("")
                findExcludeEntity(Temp) 
            }elseif(Cmd=="include") {
                findClearBlackList()
            }elseif(Cmd=="grab") {
                findClearWhiteList()
                findIncludePlayerProps(owner())    
                findByClass("prop_*") 
                FoundProps = findToArray()
            }
        }elseif(owner():lastSaid():left(4) == "mode") {
            String = lastSaid():explode(" ")
            Cmd = String:string(2)
            if(Cmd=="orbit") {
                Orbit=1
            }
        }
    }
    
    #####################
    TotalProps = FoundProps:count()
    AllProps = FoundProps:entity(Counter+1)
    Counter = (Counter+1)%TotalProps
    
    ##################### Make Props Orbit
    Theta = Theta+OrbitSpeed
    Theta = mod(Theta,360)
    OrbitCenter = OrbitTarg:pos() + vec(0,0,OrbitHeight)
    OrbitOffset = vec(Radius*cos(Theta+((360/TotalProps)*Counter)),Radius*sin(Theta+((360/TotalProps)*Counter)),0)
    TargPropPos = OrbitCenter + OrbitOffset
    DiffPos = TargPropPos-AllProps:pos()
    if(Orbit) {
        AllProps:applyForce((DiffPos*10-AllProps:vel())*AllProps:mass())
    }
    
    insta-by-the-way-edit: hello everyone, i am new here
    Last edited by hyperchickens; 07-30-2009 at 05:32 PM. Reason: latest version, new features

  2. #2
    Wire Aficionado
    Beer is a jewel in the rough Beer is a jewel in the rough Beer is a jewel in the rough Beer's Avatar
    Join Date
    Jul 2007
    Location
    Dallas, Texas
    Posts
    1,378

    Default Re: Chat commands and entity discovery, works but is imperfect

    Well for one thing you don't have runOnChat(1) anywhere. I'm not absolutely sure you need it if you use runOnTick, but I would use it anyway. You should include that in if (first()) {}

    That's also where you should put runOnTick(1) because there's no sense in re-executing that code every time your expression runs. And you have runOnTick(1) AND interval(10) which is completely unnecessary.

    AND there's no point in using elseif with if (first()) {}. You may also want to include duped() with first() because if you duplicate your expression it saves its current state AFAIK.. and you'd want it to be reset when you dupe so it can re-find prop_physics.

    There are a number of problems with your code, and I suggest getting those worked out first to better narrow down your main issue.

    Code:
    if (first() | duped()) {
        runOnTick(1)
        runOnChat(1)
        ... etc ...
    }
    
    
    if (chatClk(owner())) {
        if (lastSaid():left(4)=="targ") {
        }
    
        if (lastSaid():left(4)=="prop") {
        }
    }
    
    
    #all your code that needs to run every tick goes out here
    
    Welcome to the forum.
    Last edited by Beer; 07-07-2009 at 02:15 PM.

  3. #3
    Lurker hyperchickens is on a distinguished road hyperchickens's Avatar
    Join Date
    May 2009
    Posts
    20

    Default Re: Chat commands and entity discovery, works but is imperfect

    Here's my modified first section. A lot of the problems that were in there I didn't even notice, but after formatting it the way you suggested, the prop pick up and drop commands work.
    It still has the weird bug with the first prop where at least one prop has to exist before the chip is spawned for the orbit to work. The player targeting still doesn't work.

    Ill be testing out some different ways of detecting players for a while.

    Code:
    if(first()|duped()) {
        runOnTick(1)
        runOnChat(1)
        FaceTarg = entity()
        Face = 1
        Orbit = 1
        runOnChat(1)
        findClearWhiteList()
        findIncludePlayerProps(owner())    
        findByClass("prop_physics") 
        FoundProps = findToArray()
    }
    if(chatClk(owner())) {
        if(owner():lastSaid():left(4) == "targ") {
            String = lastSaid():explode(" ")
            Name = String:string(2)
            if(Name=="null") {
                FaceTarg=entity()
            }else{
                findClearWhiteList()
                findPlayerByName(Name)
                FaceTarg = find()
            }
        }elseif(owner():lastSaid():left(4) == "prop") {
            String = lastSaid():explode(" ")
            Cmd = String:string(2)
            if(Cmd=="droplast") {
                FoundProps:pop()
            }elseif(Cmd=="dropfirst") {
                FoundProps:remove(1)
            }elseif(Cmd=="excludelast") {
                findExcludeEntity(FoundProps:popEntity())
            }elseif(Cmd=="graball") {
                findClearWhiteList()
                findIncludePlayerProps(owner())    
                findByClass("prop_physics") 
                FoundProps = findToArray()
            }
        }
    }
    
    Last edited by hyperchickens; 07-07-2009 at 02:10 PM. Reason: mix up in code

  4. #4
    Wirezard

    Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,151

    Default Re: Chat commands and entity discovery, works but is imperfect

    Quote Originally Posted by hyperchickens
    findClearWhiteList()
    findPlayerByName(Name)
    FaceTarg = find()
    No need for those lines, as "findPlayerByName()" is not a normal find function. The function itself returns the entity. You can shorten those three lines to this line:
    Code:
    FaceTarg = findPlayerByName(Name)
    
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr


    Wire FPGA

  5. #5
    Lurker hyperchickens is on a distinguished road hyperchickens's Avatar
    Join Date
    May 2009
    Posts
    20

    Default Re: Chat commands and entity discovery, works but is imperfect

    Ah thanks.
    edit: That made targeting work! Thanks guys. Commands for targeting and prop managing now work. I just need to get rid of the first prop bug.
    I also updated the script at the top to reflect changes.
    edit2: I fixed the first prop but by changing find by class to find in sphere. Now im going on a major quest for more features. Thanks again Beer and Matte for your help. I probably would have been stuck in the same place without it.
    Last edited by hyperchickens; 07-07-2009 at 10:49 PM. Reason: solved

+ Reply to Thread

Similar Threads

  1. Help with entity discovery
    By Elmo the Emo Emperor in forum Expression 1 & 2
    Replies: 9
    Last Post: 07-05-2009, 03:32 AM
  2. Help with Entity Discovery
    By JureXL in forum Technical Support
    Replies: 4
    Last Post: 07-01-2009, 11:43 AM
  3. Need help with entity discovery
    By thirty9th in forum Expression 1 & 2
    Replies: 8
    Last Post: 06-22-2009, 03:10 PM
  4. Entity Discovery, LUA error after a few tries.
    By vortexnl in forum Expression 1 & 2
    Replies: 0
    Last Post: 05-21-2009, 06:33 AM
  5. Learning Entity Discovery.
    By vortexnl in forum Expression 1 & 2
    Replies: 10
    Last Post: 05-03-2009, 03:16 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
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots