Jump to content

How to run an ObjectScript in GameMode only 1x per second?


irswat

Recommended Posts

I have this script and I only want it to run 1 time per second, instead of every frame. I want to keep it as an object script in game mode though. what would I do? Here is the code:

scn OldSniperModScript

float hfPlayer
int AlertFlag
int rDSniperAF
ref rSniper
float WeapMaxRange

begin GameMode

        set AlertFlag to 0
        set rDSniperAF to 0
        set rSniper to 00000000
        set hfPlayer to 0
        set WeapMaxRange to GetMaxRange WeapNVGhillieSniperRifle
        
        if player.IsInInterior == 0
            set rSniper to GetSelf
            set hfPlayer to player.GetDistance rSniper
    
            if GetDead == 1
                ;MessageEX "Sniper %i is dead" rSniper
                set AlertFlag to 0
            elseif GetDead == 0
                if hfPlayer <= WeapMaxRange
                    ;MessageEX "Sniper is %g units away" hfPlayer
                    set AlertFlag to 1
                elseif hfPlayer > WeapMaxRange
                    ;MessageEX "Sniper is out of range by %g units" (hfPlayer-WeapMaxRange)
                    set AlertFlag to 0
                endif
            endif
        
            if AlertFlag || GetDetected player
                rSniper.Look player
                rSniper.UseWeapon WeapNVGhillieSniperRifle rSniper player 5 0 0 1 0  
            endif
        endif
end


Edited by irswat
Link to comment
Share on other sites

 

scn OldSniperModScript

float hfPlayer
int AlertFlag
int rDSniperAF
ref rSniper
float WeapMaxRange

float timer

begin GameMode

        if(timer < 1)
            set timer to timer + getsecondspassed
            return
        else
            set timer to 0
        endif

        set AlertFlag to 0
        set rDSniperAF to 0
        set rSniper to 00000000
        set hfPlayer to 0
        set WeapMaxRange to GetMaxRange WeapNVGhillieSniperRifle
        
        if player.IsInInterior == 0
            set rSniper to GetSelf
            set hfPlayer to player.GetDistance rSniper
    
            if GetDead == 1
                ;MessageEX "Sniper %i is dead" rSniper
                set AlertFlag to 0
            elseif GetDead == 0
                if hfPlayer <= WeapMaxRange
                    ;MessageEX "Sniper is %g units away" hfPlayer
                    set AlertFlag to 1
                elseif hfPlayer > WeapMaxRange
                    ;MessageEX "Sniper is out of range by %g units" (hfPlayer-WeapMaxRange)
                    set AlertFlag to 0
                endif
            endif
        
            if AlertFlag || GetDetected player
                rSniper.Look player
                rSniper.UseWeapon WeapNVGhillieSniperRifle rSniper player 5 0 0 1 0  
            endif
        endif
end
Link to comment
Share on other sites

scn OldSniperModScriptWithTimer

float hfPlayer
int AlertFlag
ref rSniper
float WeapMaxRange
float timer

begin GameMode

		set AlertFlag to 0
		set rSniper to 00000000
		set hfPlayer to 0
		set WeapMaxRange to GetMaxRange WeapNVGhillieSniperRifle
		
		if player.IsInInterior == 0
			if(timer < 1)
            		set timer to timer + getsecondspassed
          		return
        		else
           		set timer to 0
				set rSniper to GetSelf
				set hfPlayer to player.GetDistance rSniper
		
				if GetDead == 1
					MessageEX "Sniper %i is dead" rSniper
					set AlertFlag to 0
				elseif GetDead == 0 && player.GetDead == 0
					if hfPlayer <= WeapMaxRange
						MessageEX "Sniper is %g units away" hfPlayer
						set AlertFlag to 1
					elseif hfPlayer > WeapMaxRange
						MessageEX "Sniper is out of range by %g units" (hfPlayer-WeapMaxRange)
						set AlertFlag to 0
					endif
				endif
			
				if AlertFlag 
					rSniper.UseWeapon WeapNVGhillieSniperRifle rSniper player -1 0 0 0 0  
				else if IsDetected player
					StartCombat player
				endif
				if player.GetDead
					set AlertFlag to 0
				endif
			
		endif
      endif

return
end


Is this right?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...