Thread: custom animated button

Results 1 to 9 of 9

Threaded View

  1. #1
    Registered User Sprengmeister's Avatar
    Join Date
    Mar 2016
    Location
    Germany
    Posts
    24

    custom animated button

    Hi, it would be nice if someone can help me with this.
    I try to script a func_button similar entity that uses animations. It's a wall mounted torch that can have serveral states:
    Burning,
    flame goes off via animation,
    idle in non burning state,
    flame turning on via animation,
    switch as button ( rotates by ~90°) also as animation,
    stays switched horizontally
    and switch back to a vertical orientation, via animation, too.

    I spent a lot of time to make this model work fine and now I don't want to discard it for another solution, so my questions are:
    - can I inherate from CBaseButton? And is there a list with the possible syntaxes of ScriptBase(Entity/PlayerWeaponEntity/...) I didn't found anything in the api.
    - How to use the use types? Can I lock the torch for button uses while it's burning?
    - how to fire the target of that entity via script?

    BTW: At first I tried to change the animation sequences by map entities, the problem was, that the sequences not started at their first frame. Is there any solution to reset the frame of an sequence? If so, I could use this thing without a script.

    This is my code till now, I know, it's not ready yet:
    Code:
    enum WallTorchAnimation 
    {
        WALLTORCH_IDLE_FIREON = 0,
        WALLTORCH_FIRE_TURNOFF,
        WALLTORCH_IDLE_FIREOFF,
        WALLTORCH_FIRE_TURNON,
        WALLTORCH_BUTTON_SETON,
        WALLTORCH_BUTTON_IDLEON,
        WALLTORCH_BUTTON_SETOFF
    };
    
    class CWallTorchButton : ScriptBaseEntity
    {    
        bool m_bTurnFireOff = false;
        bool m_bTurnFireOn = false;
        void Spawn()
        {
            g_EntityFuncs.SetModel( self, "models/Che/props/walltorch.mdl" );
            g_EntityFuncs.SetSize( self.pev, Vector(-4, -32, -20), Vector(4, 0, 32) );
            g_EntityFuncs.SetOrigin( self, self.pev.origin );
            
            
            self.pev.movetype = MOVETYPE_FLY;
            self.pev.solid = SOLID_BBOX;
            self.pev.nextthink = g_Engine.time + 0.1f;
    
            SetThink( ThinkFunction(Burn) );
        }
        
        void Precache()
        {
            g_Game.PrecacheModel( "models/Che/props/walltorch.mdl" );
        }
        
        void Burn()
        {
            self.sequence = 0;
            if(m_bTurnFireOff){
                SetThink( ThinkFunction(TurnOff) );
            }
            self.pev.nextthink = g_Engine.time + 1;
        }
        
        void TurnOff()
        {
            self.sequence = 1;
            SetThink( ThinkFunction(IdleOff) );
            self.pev.nextthink = g_Engine.time + 1;
        }
        
        void IdleOff()
        {
            self.sequence = 2;
            if(m_bTurnFireOn){
                SetThink( ThinkFunction(TurnOn) );
            }
           // if(use in this state){
           //    apply BUTTON_SETON animation and fire the target there
           // }
            self.pev.nextthink = g_Engine.time + 0.2;
        }
        
        void TurnOn()
        {
            self.sequence = 3;
            SetThink( ThinkFunction(Burn) );
            self.pev.nextthink = g_Engine.time + 1;
        }
       // [...]
       // button think functions with it's animations...
       // [...]
        void Use(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float value)
        {
        
        }
        
    }
    Last edited by Sprengmeister; 16-07-2017 at 05:19 PM.

Posting Permissions

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