+ Reply to Thread
Results 1 to 8 of 8

Thread: Making An E2 Chip Stay At It's Current World Position

  1. #1
    Inactive SkCorps is on a distinguished road SkCorps's Avatar
    Join Date
    Oct 2008
    Posts
    17

    Default Making An E2 Chip Stay At It's Current World Position

    Alright, essentially what I want to do is make an E2 chip (that floats over my head) to get its current world position and stay there when I say /stay, and when I say /followme start following me again. I know how to do the chat commands, but the rest puzzles me. How do I do it?

    I would also like it to be able to follow a player, for example, /follow PLAYERNAME.

    Here's the E2 code, if it helps.

    Code:
    @name Music Chip V2.0
    @persist Vector:vector E:entity
    #Timers and trails
    if(first())
    {
        runOnTick(1)
        runOnChat(1)
        
        entity():setTrails(7,1,1,"trails/tube",vec(255,255,255),200)
    
        Musicplay = 0
    }
    
    #If run on game ticks
    if(tickClk())
    {
    if(entity():isConstrained()) {
        E=entity():isConstrainedTo()
        } 
        else {
            E=entity()
            }
    Vector=owner():pos()-E:pos()+vec(0,0,100)
    E:applyForce(1*(1*Vector+30*$Vector))
    }
    
    #When something is said
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_disco")){
              Musicplay = 1
              entity():soundPlay(1,0,"music/HL1_song25_REMIX3.mp3")
         }
    
    }
    
    
    #When something is said
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_stillalive")){
              Musicplay = 1
              entity():soundPlay(1,0,"music/portal_still_alive.mp3")
         }
        
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_sectorsweep")){
              Musicplay = 1
              entity():soundPlay(1,0,"music/VLVX_song23.mp3")
         }
    }
    
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_combinetheme")){
              Musicplay = 1
              entity():soundPlay(1,0,"music/hl2_song15.mp3")
         }
    }
    
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_vortalcombat")){
              Musicplay = 1
              entity():soundPlay(1,0,"music/VLVX_song22.mp3")
         }
    }
    
         if(Said:find("/nomusic")){
              Musicplay = 0
              soundStop(1)
          }
    
    }
    
      if(Said:find("/stay")){
    
    }
    
    Last edited by SkCorps; 07-07-2009 at 04:36 PM.

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

    Default Re: Making An E2 Chip Stay At It's Current World Position

    You're going to need two vectors; one for the current position of the chip and one for the destination.

    In the format I see from your code, you'll want something like this; add it to the When something is said section.

    e2 Code:
    1. if(Said == "/followme"){
    2. HoverTarget = owner()
    3. Follow = 1
    4. }

    This is the basic format for getting it to follow you.
    The " + vec(0,0,100) " will offset it, making it hover just over your head.
    The " * 500 " is multiplying the force, making it more responsive to movement. You can tweak this to your liking.

    e2 Code:
    1. if(Follow){
    2. Vector1 = entity():pos()
    3. Vector2 = HoverTarget:pos()
    4. ForceFinal = (Vector2 - Vector1 + vec(0,0,100)) * 500
    5. entity():applyForce(ForceFinal + $ForceFinal*5)
    6. }

    The format for applyForce to follow something is:

    e2 Code:
    1. Force = (Destination - CurrentPos) * Multiplier
    2. entity():applyForce(Force + $Force*5)

    Following another player is the same concept; you just need to store a player's entity to HoverTarget and that player will become the destination.

    Check the wiki, but you'd want to do something that takes the second part of a string, e.g. "/followplayer playername" and uses that to find a player ( findPlayerbyName(playername) ). That will return that player's entity.

  3. #3
    Wire Sofaking mjmr89 is on a distinguished road mjmr89's Avatar
    Join Date
    Mar 2008
    Posts
    501

    Default Re: Making An E2 Chip Stay At It's Current World Position

    That code is correct, but I *HIGHLY* recommend using entity():vel() instead of using $something.

  4. #4
    Wirererer eduardo is on a distinguished road eduardo's Avatar
    Join Date
    Jan 2009
    Posts
    363

    Default Re: Making An E2 Chip Stay At It's Current World Position

    so like make the velocity 0 so it stays in place?

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

    Default Re: Making An E2 Chip Stay At It's Current World Position

    No, what Mjmr means, I think, is to use entity():vel() in place of $Force*5 in my last code box above.

    These are two separate methods for controlling wobble; one uses the change in force, and the other uses the entity's current velocity.

  6. #6
    Wire Sofaking mjmr89 is on a distinguished road mjmr89's Avatar
    Join Date
    Mar 2008
    Posts
    501

    Default Re: Making An E2 Chip Stay At It's Current World Position

    Yep, thats what I mean. It's better than using the delta of the force because in some situations, the force changes (for example, if you wanted to follow a *moving* target). I don't know, it's hard to explain. It's just generally better to only take into consideration the entity you are moving's velocity.

  7. #7
    Inactive SkCorps is on a distinguished road SkCorps's Avatar
    Join Date
    Oct 2008
    Posts
    17

    Default Re: Making An E2 Chip Stay At It's Current World Position

    Here's my 'stay in place' code so far, unfortunately it doesn't work...
    Code:
    @name Music Chip V3.0
    @persist Vector:vector E:entity CurPos:vector
    #Timers and trails
    Follow = 1
    if(first())
    {
        runOnTick(1)
        runOnChat(1)
        
        entity():setTrails(7,1,1,"trails/tube",vec(255,255,255),200)
    }
    
    #If run on game ticks
    if(tickClk())
    {
    if(entity():isConstrained()) {
        E=entity():isConstrainedTo()
        } 
        else {
            E=entity()
            }
    
    Vector=owner():pos()-E:pos()+vec(0,0,100)
    E:applyForce(1*(2*Vector+30*$Vector))
    }
    
    
    #When something is said
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_disco")){
            hint("Music: HL1 Disco Remix", 5)
              entity():soundPlay(1,0,"music/HL1_song25_REMIX3.mp3")
         }
    }
    #When something is said
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_stillalive")){
            hint("Music: Still Alive", 5)
              entity():soundPlay(1,0,"music/portal_still_alive.mp3")
         }
    if(chatClk(owner())){
         Said = owner():lastSaid():lower()
         if(Said:find("/music_rock")){
            hint("Music: Combine Theme", 5)
              entity():soundPlay(1,0,"music/hl2_song15.mp3")
         }
    }
         if(Said:find("/nomusic")){
            hint("Music off", 5)
              soundStop(1)
          }
    }
        if(Said:find("/stay")){
            Follow = 0
            hint("Staying at current world position", 5)
            CurPos = E:pos()
        
    }
        if(Follow == 0){
            if(tickClk())
    {
    if(entity():isConstrained()) {
        E=entity():isConstrainedTo()
        } 
        else {
            E=entity()
            }
            E:applyForce(1*(1*CurPos*$CurPos))
    }
    }
    

  8. #8
    Wire Amateur RabidCrab is on a distinguished road RabidCrab's Avatar
    Join Date
    Jan 2008
    Location
    Oregon
    Posts
    88

    Default Re: Making An E2 Chip Stay At It's Current World Position

    You're running applyForce twice during an execution, once at the top of the code, another at the bottom. Remove the bottom applyForce() and it should work.
    I'm named after the crustacean, not the STD.




    All my crap is built on Drunkie's server

+ Reply to Thread

Similar Threads

  1. Making something just stay where it is
    By bobthe2lol in forum Help & Support
    Replies: 7
    Last Post: 07-08-2009, 01:18 PM
  2. Replies: 2
    Last Post: 07-04-2009, 10:37 PM
  3. Letting a plate(E2) hover at it's current position.
    By vortexnl in forum Expression Help
    Replies: 14
    Last Post: 05-08-2009, 04:20 PM
  4. Making props' stay in your head's position with E2.
    By Quantum in forum Help & Support
    Replies: 5
    Last Post: 04-11-2009, 12:22 PM
  5. How to get the current Z position of a player?
    By Beer in forum Help & Support
    Replies: 4
    Last Post: 07-25-2007, 01:04 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