Announcement

Collapse
No announcement yet.

My script thread (old : timer problem)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    My script thread (old : timer problem)

    I got a problem with the following script.
    When the player press the use key during 10 seconds it should update the actor status, but I got this error :

    Error: E:\UT2004\Abysse_scripts\Classes\PControl.uc(51) : Error, 'Timer': Expression has no effect


    function UsedBy( Pawn user )
    {
    setTimer(1,true);

    if (user.IsPlayerPawn()&& (ControllingPawn != none))
    {
    event Timer()
    {
    ControllingPawn = user;
    DecompteControleur++;

    if(DecompteControleur >= 10)
    {
    UpdateStatus();
    DecompteControleur=0;
    break;
    }
    }
    }
    }
    I don't found any tutorial about unreal timer
    does someone can help me ?
    thanks

    #2
    Timer() is a seperate function. You are trying to put it inside another function which you cant do. This is what your code should look like:


    Code:
    function UsedBy( Pawn user )
    {
    if (user.IsPlayerPawn()&& (ControllingPawn != none))//when true timer will be called in 1 second
            setTimer(1,true);
    }
    
    event Timer() 
    {
    ControllingPawn = user;
    DecompteControleur++;
    
    if(DecompteControleur >= 10)
    {
    UpdateStatus();
    DecompteControleur=0;
    break;
    }
    }
    The only problem with this is that the timer function doesn't know what user is. So you will need a global variable to store the user in the usedby function, so that the timer function can get that reference to the pawn.

    Comment


      #3
      break; is not authorized here, so I can't stop the process. I don't find any stoptimer or endtimer function. Is there any way to stop the timer ?

      Comment


        #4
        Code:
        SetTimer(1.0, false);
        This will disable the timer, u can put it anywhere u want, just make sure it's on a place where it is actually executed.

        NOTE: After this line the timer still runs 1 more time. And there isn't really anything u can do about that.
        The FALSE at the 2nd parameter indicates it won't repeat anymore.

        Code:
        if (user.IsPlayerPawn()&& (ControllingPawn != none))//when true timer will be called in 1 second
        Just for clarity, This wont call the timer in 1 second. It will start the timer immidiatly and the timer will repeat itself at the rate specified in the 1st parameter ( in seconds ) so this will loop the timer 1 time per second.

        Comment


          #5
          thank you, it work like this :

          function UsedBy( Pawn user )
          {
          if (User.IsPlayerPawn() && (Activateur == none)){
          Activateur = User;
          SetTimer(0.5,true);
          User.ClientMessage( "activé" );
          DecompteControleur=0;
          }
          }

          event Timer()
          {
          if (Activateur != none){
          DecompteControleur++;
          Activateur.ClientMessage( "Activateur != none" );

          if(DecompteControleur >= 20)
          {
          Activateur.ClientMessage( "controlé !" );
          ControllingPawn = Activateur;
          UpdateStatus();
          DecompteControleur=0;
          SetTimer(0.01,false);
          }
          }

          }
          but, with this script, the player use the actor and can go away, the actor will automaticaly activated after 10 second.

          It's not the exact plot, because I want that the player stay there and hold the use key to activate it.
          I have found this :

          function bool KeyEvent( out EInputKey Key, out EInputAction Action, FLOAT Delta )
          {
          return false;
          }
          but the KeyEvent is unknown because it's under Object.Interactions and not in Object.Actor
          so it seems that it's impossible to use this function with an actor, except if I copy/paste all the code from Interactions and interaction classes :bulb:

          is there anyway to chek if a player is holding the use key, and how long he hold it ?

          EDIT :

          I have found bHoldingFire, bHoldingStart, bHoldingBack and bHoldingDuck, but not bHoldingUse

          Comment


            #6
            heyhey, I have found :
            Disable('Timer') and Enable('Timer') !!


            this allow to stop the timer and restart it.

            (for search : stoptimer, endtimer, disabletimer, enabletimer, starttimer)

            Comment


              #7
              hi, hi come back with the ineraction question.

              I have found on the wiki a thread about interaction, but I don't found how to make it work in my mod.

              The result : the player must hold the use key on an actor during 10 seconds to activate it.

              The script :

              In my xCtrlGame (game rules) script :

              function bool HoldingUse(Pawn Other) {
              local PlayerController PC;

              PC = Level.GetLocalPlayerController();

              // Run a check to see whether this mutator should create an interaction for the player
              if ( PC != None && ((PC.PlayerReplicationInfo.bIsSpectator && bAffectSpectators) || (bAffectPlayers && !PC.PlayerReplicationInfo.bIsSpectator)) )
              {
              PC.Player.InteractionMaster.AddInteraction("Abysse _Scripts.HoldingUse", PC.Player); // Create the interaction
              bHoldingUse = True; // Set the variable so this lot isn't called again
              PC.ClientMessage( "bholdinguse = true !" );
              }
              return bHoldingUse;
              }
              The HoldingUse script :


              class HoldingUse extends Interaction;
              var pawn Activateur;
              var bool bHoldingUse;

              Function Initialize()
              {
              Log("Interaction Initialized");
              }

              event bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
              { local PlayerController PC;
              PC = Level.GetLocalPlayerController();
              if (Key==IK_E)
              {
              if((Action==IST_Hold)&&(Delta >= 0)){
              PC.ClientMessage( "touche E active !" );
              bHoldingUse = true;
              }
              }
              return Super.KeyEvent(Key,Action,Delta);
              }

              DefaultProperties
              {
              bActive=True;
              }
              In the actor script :


              function UsedBy( Pawn user )
              {
              if (User.IsPlayerPawn() && (Activateur == none)&&(User.GetTeamNum() != (ActivatingTeam -1))){
              Activateur = User;
              Enable('Timer');
              SetTimer(0.5,true);
              User.ClientMessage( "activé" );
              DecompteControleur=0;
              }
              else {
              //PlayerController(User.Controller).ClientOpenMenu(L evel.Game.GameUMenuType,,"TL");
              //popup de controle
              }
              }

              event Timer()
              {
              if (Activateur != none){
              if (bHoldingUse){
              DecompteControleur++;
              Activateur.ClientMessage( "Activateur != none" );

              if(DecompteControleur >= 20)
              {
              Activateur.ClientMessage( "controlé !" );
              ControllingPawn = Activateur;
              ActivatingTeam == Activateur.GetTeamNum() + 1;
              Activateur=none;
              UpdateStatus();
              DecompteControleur=0;
              Disable('Timer');
              }
              }
              else {
              Activateur.ClientMessage( "dé controlé !" );
              Activateur = none;
              DecompteControleur=0;
              Disable('Timer');
              }
              }

              }
              In game, the actor understand that someone try to activate it
              the " if (Activateur != none){" from the actor script works, but then I have immediatly the message from :

              else {
              Activateur.ClientMessage( "dé controlé !" );

              so if (bHoldingUse){ is false :/

              I have tried lots of things but nothing work.
              Could someone help me please ?

              thanks

              Comment

              Working...
              X