Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: The Propsplosion E2

  1. #1
    Exo
    Exo is offline
    Banned Exo's Avatar
    Join Date
    Dec 2010
    Posts
    28

    Default The Propsplosion E2

    Description: A prop exploder. Hitting 'use' will accumulate your props into one large bunch, and then explode them in a violent manner.

    For links to my other creations, head here:


    Disclaimer: What you do with this chip is not my business. Appreciate the code for what it is, not what people decide to do with it.



    Merry Christmas, everyone!

    Sorry, been sick with a cold, but here's what I've got so far. Prop size scaling now works fairly well, but I haven't addressed the bug with the lag (when using more than 20 or so props at a time) yet. I'll drop that fix in after Christmas.

    Code:
    @name PropSplosion
    @inputs
    @outputs
    @persist Me:entity PropList:array PropPositionList:array SearchFlag PropCount Index ExplosionPosition:vector ExplosionSequenceInitiated NumPropsAtDestination AllPropsAtDestination PropsVibrating Exploding
    
    interval(1)
    
    # ================
    # Set up constants
    # ================
    
    # These change the rate of prop movement and how quickly they slow when they reach their destination
    DeltaSmoother = 5
    DeltaMultiplier = 10
    
    # The desired mass of the props being thrown around
    #  Higher mass generally means they will be flung further away
    Mass = 50000
    
    
    # ====================
    # Initialize variables
    # ====================
    if (first()) {
    
        # Set up the owner variable (convenience)
        Me = owner()
    
        # Initialize some variables
        #  Not required, but is easier to keep track of initial values    
        PropCount = 0
        Index = 0
        SearchFlag = 0
        ExplosionSequenceInitiated = 0
        NumPropsAtDestination = 0
        AllPropsAtDestination = 0
        PropsVibrating = 0
        Exploding = 0
        ExplosionComplete = 0
    }
    
    # Destroy the chip if it's duped
    if (duped()) {
        selfDestruct()
    }
    
    # ====================
    # Timer Flags
    # ====================
    # Run a search to grab new props, if they are present
    
    if (clk("SearchFlag")) { SearchFlag = 0 }
    
    if (clk("PropsCoagulated")) { AllPropsAtDestination = 1 }
    
    if (clk("Exploding")) {
        Exploding = 1
        Index = 0
    }
    
    # Find all the props to use in this explosion
    #  We run this continously during the explosion sequence in case we are using
    #  breakable props (which may have been destroyed during the coagulation phase)
    if (!SearchFlag & ExplosionSequenceInitiated) {
        SearchFlag = 1
        timer("SearchFlag", 500)
        findIncludePlayerProps(owner())
        findByClass("prop_physics")
        findSortByDistance(Me:aimPos()) # No real reason to do this, it just keeps me organized
        if(PropCount!=findToArray():count()){
            PropList=findToArray()
            PropCount=PropList:count() # Again, for convenience
        }
    }
    
    # ====================
    # Activation key
    # ====================
    if (Me:keyUse() & !ExplosionSequenceInitiated) {
    
        # Set the explosion position and initialize variables
        ExplosionPosition = Me:aimPos() + vec(0, 0, 100)
        ExplosionSequenceInitiated = 1
        NumPropsAtDestination = 0
        AllPropsAtDestination = 0
        PropsVibrating = 0
        Exploding = 0
        ExplosionComplete = 0
        Index = 0
    }
    
    # ============================
    # ============================
    # Begin the explosion sequence
    # ============================
    # ============================
    
    # ============================
    # If all props have arrived...
    # ============================
    if (AllPropsAtDestination & !PropsVibrating) {
        # Store the current position of each prop
        PropPositionList = array()
        for(I=0, PropCount - 1, 1) {
            PropPositionList:pushVector(PropList:entity(I+1):pos())
        }
        PropsVibrating = 1
        
        
        # Set the explosion timer (to be used in a later version of this chip)
        timer("Exploding", 1)
    }
    
    
    
    # ===============================
    # Perform movements for the props
    # ===============================
    if (ExplosionSequenceInitiated) {
        
        # Iterate over each prop while we still have ops left in our quota.
        while (opcounter() < maxquota()) {
            
            # Grab the current prop from the prop array, based on index
            CurrentProp = PropList:entity(Index + 1)
            
            # Set the mass of the prop
            CurrentProp:setMass(Mass)
            
            
            # Vibrations are to be used in a later version of this chip
            VibrationAmount = 0
            if (!PropsVibrating) {
                AimPos = ExplosionPosition
            } else {
                VibrationVector = vec(random(-VibrationAmount, VibrationAmount), random(-VibrationAmount, VibrationAmount), random(-VibrationAmount, VibrationAmount))
                AimPos = PropPositionList:vector(Index + 1) + 10
                AimPos += VibrationVector
            }
            
            # If we're currently exploding, set the aim position for each prop relative to its
            #  position from the explosion's center
            if (Exploding) {
                AimPos = CurrentProp:pos() - ExplosionPosition + vec(0, 0, CurrentProp:radius())
                AimPos = AimPos * 5000000
            }
            
            # Calculate the X/Y planar distance
            A = (AimPos:x() - CurrentProp:pos():x())
            ASquared = A * A
            B = (AimPos:y() - CurrentProp:pos():y())
            BSquared = B * B
            PlaneDistance = sqrt(ASquared + BSquared)
            
            # Check to see if the prop is at the explosion destination
            if (PlaneDistance < CurrentProp:radius() * PropCount / 2) {
                NumPropsAtDestination += 1
            }
            
            # =========================
            # Thrust calculations
            # =========================
            
            # Calculate the initial thrust vector
            Thrust = (AimPos - CurrentProp:pos()) + CurrentProp:massCenterL()
            
            # Add vertical thrust based on planar distance to arc the projectile
            Thrust = Thrust + vec(0, 0, PlaneDistance / 5)
            
            # Calculate the thrust delta and apply it to the thrust vector
            Delta = CurrentProp:vel() / DeltaSmoother
            Thrust = (Thrust - Delta) * DeltaMultiplier
            
            # Apply thrust multiplier based on calculated mass
            Multiplier = CurrentProp:mass()/10
            if (Multiplier < 1) {
                Multiplier = 1
            }
            Thrust = Thrust * Multiplier
            
            # Apply the final thrust to the chip
            CurrentProp:applyForce(Thrust)
            
            # Check to see if all the props have reached their destination
            if (NumPropsAtDestination == PropCount & !Exploding) {
                timer("PropsCoagulated", 550)
                break
            }
            
            # Incremend the index number so we start working on the next prop in the array
            Index++
            if (Index > PropCount) {
                
                # If we're exploding, and we've iterated over each prop, stop this explosion sequence
                if (Exploding) {
                    ExplosionSequenceInitiated = 0
                }
                NumPropsAtDestination = 0
                Index = 0
                break
            }
        }
    }
    Last edited by Exo; 12-25-2010 at 12:39 AM. Reason: Added code.

  2. #2
    No U Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    6,686

    Default Re: The Propsplosion E2

    This is much cooler than the other chips. You could have posted all chips in the same thread, though.
    Get dropbox and get 250 mb extra space: Dropbox

  3. #3
    Developer Jack37's Avatar
    Join Date
    Jul 2009
    Location
    Slovakia
    Posts
    1,330

    Default Re: The Propsplosion E2

    This one is cool

    Only the small secrets need to be protected. The big ones are kept secret by public incredulity.

  4. #4
    Exo
    Exo is offline
    Banned Exo's Avatar
    Join Date
    Dec 2010
    Posts
    28

    Default Re: The Propsplosion E2

    Quote Originally Posted by Divran View Post
    This is much cooler than the other chips. You could have posted all chips in the same thread, though.
    Thanks for the suggestion, but how do you propose I do it so that the single thread doesn't look sloppy? I have several more chips I'll be releasing, but how will anyone be able to read a thread with 6 - 10 video links, 6-10 code blocks, and 6-10 descriptions/usage in the first post?

    I'm new to posting in forums, so feedback is appreciated.

    Regards,
    Exo

  5. #5
    Exo
    Exo is offline
    Banned Exo's Avatar
    Join Date
    Dec 2010
    Posts
    28

    Default Re: The Propsplosion E2

    Quote Originally Posted by Jack37 View Post
    This one is cool
    Thanks, Jack37. I'll have the code posted for it soon. Right now, this one doesn't scale properly if you use larger props and also creates a lot of collision lag during the gathering phase - two bugs I have solutions for already.

    I'm also going to make it so that the props accumulate while you hold 'e' while also following your cursor around. Then, dependent upon how long you hold 'e' before releasing it, scatter the props in a proportionate-sized explosion.

  6. #6
    No U Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    6,686

    Default Re: The Propsplosion E2

    Quote Originally Posted by Exo View Post
    Thanks for the suggestion, but how do you propose I do it so that the single thread doesn't look sloppy? I have several more chips I'll be releasing, but how will anyone be able to read a thread with 6 - 10 video links, 6-10 code blocks, and 6-10 descriptions/usage in the first post?

    I'm new to posting in forums, so feedback is appreciated.

    Regards,
    Exo
    Well it's too late now, but it isn't hard. You could try to remember for your next series of contraptions. Here's my contraptions thread if you want to take a look at how I did it: http://www.wiremod.com/forum/custom-...ns-thread.html

    Also try to not post two posts in a row. Edit your previous post instead.
    Get dropbox and get 250 mb extra space: Dropbox

  7. #7
    Wire Sofaking N00bDud3's Avatar
    Join Date
    Jul 2009
    Location
    Error: Unknown Location
    Posts
    1,295

    Default Re: The Propsplosion E2

    That's pretty cool.
    Also, I just realized something. Almost every single video of an E2 moving stuff around, the stuff is usually blue barrels. Why is that? I also test with them when I move stuff...


  8. #8
    No U Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    6,686

    Default Re: The Propsplosion E2

    Quote Originally Posted by N00bDud3 View Post
    That's pretty cool.
    Also, I just realized something. Almost every single video of an E2 moving stuff around, the stuff is usually blue barrels. Why is that? I also test with them when I move stuff...
    I usually use the combine helicopter bomb model. I use it because it's at the front of the default initial spawnlist.
    Get dropbox and get 250 mb extra space: Dropbox

  9. #9
    Exo
    Exo is offline
    Banned Exo's Avatar
    Join Date
    Dec 2010
    Posts
    28

    Default Re: The Propsplosion E2

    Quote Originally Posted by Divran View Post
    Well it's too late now, but it isn't hard. You could try to remember for your next series of contraptions. Here's my contraptions thread if you want to take a look at how I did it: http://www.wiremod.com/forum/custom-...ns-thread.html

    Also try to not post two posts in a row. Edit your previous post instead.
    Ahhh, gotcha. How do you keep all of your contraptions at the top of the thread? You simply do that upon the initial creation of the thread and then create a new thread for anything you don't post at that, exact moment?

    PS: I appreciate the patience and advice. It's more than some others have given me during my short stay.


    Quote Originally Posted by N00bDud3 View Post
    That's pretty cool.
    Also, I just realized something. Almost every single video of an E2 moving stuff around, the stuff is usually blue barrels. Why is that? I also test with them when I move stuff...
    Haha, I use them because they don't seem to stick together very well. More boxy props often tend to get tangled, or at least lag more because they have more collisions. Helicopter balls are probably just as good, but I think they tend to roll more freely when they drop to the ground.

  10. #10
    No U Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    6,686

    Default Re: The Propsplosion E2

    Quote Originally Posted by Exo View Post
    Ahhh, gotcha. How do you keep all of your contraptions at the top of the thread? You simply do that upon the initial creation of the thread and then create a new thread for anything you don't post at that, exact moment?
    Back when I made that thread, I made several posts that said "reserved" so that I could edit them when I needed them.
    Get dropbox and get 250 mb extra space: Dropbox

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
unnecessary
unnecessary
unnecessary
unnecessary
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots