irswat Posted March 14, 2014 Share Posted March 14, 2014 (edited) 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 March 14, 2014 by irswat Link to comment Share on other sites More sharing options...
luthienanarion Posted March 14, 2014 Share Posted March 14, 2014 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 More sharing options...
irswat Posted March 14, 2014 Author Share Posted March 14, 2014 (edited) edited Edited March 14, 2014 by irswat Link to comment Share on other sites More sharing options...
irswat Posted March 14, 2014 Author Share Posted March 14, 2014 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 More sharing options...
luthienanarion Posted March 14, 2014 Share Posted March 14, 2014 That will work if you want to run the 4 set statements and the player.IsInInterior check every frame and only process the rest once a second. Link to comment Share on other sites More sharing options...
irswat Posted March 14, 2014 Author Share Posted March 14, 2014 no need to run the timer at all if the player is inside. it is a sniper mod script. thank you so much. Link to comment Share on other sites More sharing options...
Recommended Posts