As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

HL2/Hammer Weapon Scripting (Urgent)

drhazarddrhazard Registered User regular
edited June 2009 in Help / Advice Forum
Anyone have any experience with scripting in HL2/Hammer? I'm trying to create a laser-defense system. When the player fires an RPG, a laser beam shoots from the ground to the flying rocket, causing it to explode. Unfortunately, I don't know how to reference the rocket that's been fired.

Are there any triggers that use it as the !activator? The trigger_rpgfire doesn't--the player is the !activator for it.

I'd like to get this over with tonight, or I'm going to have to put it on the backburner. Any help is appreciated.

SCB.jpg
drhazard on

Posts

  • Options
    LegionnairedLegionnaired Registered User regular
    edited June 2009
    drhazard wrote: »
    Anyone have any experience with scripting in HL2/Hammer? I'm trying to create a laser-defense system. When the player fires an RPG, a laser beam shoots from the ground to the flying rocket, causing it to explode. Unfortunately, I don't know how to reference the rocket that's been fired.

    Are there any triggers that use it as the !activator? The trigger_rpgfire doesn't--the player is the !activator for it.

    I'd like to get this over with tonight, or I'm going to have to put it on the backburner. Any help is appreciated.

    Coming from a programming background and not a source background...

    Make the class representing the defense turret have a class variable that keeps track of all valid targets for the system.

    Add to the spawn method of the rocket to add a reference to itself to that class variable.

    Have the instances of the defense turrets try to aquire a target if they don't have one, and shoot at the rocket until it's dead.

    Pseudo-code:
    CDefenseTurretTargettable : // Some Interface that guarantees a 'getposition' type method.
    
    CRocket : CombatEntity{
    
    void spawn() {
      // stuff....
    
      CDefenseTurret.addValidTarget(<CDefenseTurretTargettable>self);
    }
    }
    
    
    
    CDefenseTurret : CombatEntity {
       class variable vector<CDefenseTurretTargettable> valid_targets;
       void think() {
          if self.current_target == null
             self.current_target = self.class.aquireTarget(self.position);
          if self.curent_target != null
             shoot_at_target(self.current_target)
       }
       class method CDefenseTurretTargettable aquireTarget(cPosition x) {
          sort_by_closest_to_position(valid_targets, x)
          if valid_targets.length != 0 
             return valid_targets.pop
          else return null
       }
    }
    

    All of this makes a lot more sense if you have any sort of aspect oriented solution available to you, because then you just say in one place...
        advise [list of valid targets] after spawn() do
           CDefenseTurret.addValidTarget(self)
        end
    

    Legionnaired on
  • Options
    drhazarddrhazard Registered User regular
    edited June 2009
    Having this as new weapon code instead of scripting decreases its portability, though. Plus, I'm not particularly interested in the player having this functionality--it'd all be in a single scripted sequence. I guess I'm asking if Hammer/HL2/Source already has exactly what you suggested. :P

    I may try to do this as a worst-case scenario, though, so thanks. If anyone else has any ideas, though, I'd appreciate it.

    drhazard on
    SCB.jpg
  • Options
    yalborapyalborap Registered User regular
    edited June 2009
    While I don't have any experience with Source, or much of any programming, I do distinctly know that the gunships WILL fire on rockets and destroy them, and thus there must be some script or facet of AI that makes them do this. So I'd say your best bet would be to just look at it, see what makes it tick, and copy that into your thing with the appropriate modifications.

    yalborap on
  • Options
    drhazarddrhazard Registered User regular
    edited June 2009
    Yeah, I remember that--which is what makes it seem reasonable to do--but I'm not sure how to decipher how the gunship AI chooses their target.

    drhazard on
    SCB.jpg
  • Options
    drhazarddrhazard Registered User regular
    edited June 2009
    Ugh, and I can't even look into the code itself--I only have Visual C#, and I need Visual .NET. Not my day, it looks like.

    drhazard on
    SCB.jpg
Sign In or Register to comment.