saamziel Posted February 28, 2009 Share Posted February 28, 2009 hi, im having trouble making a timer my goal is to have a weapon add one ammo to itself every 5 real life seconds but i cant seen to get it to work i used the getsecondspassed function and copied the wiki's example but it wont work for me can anyone help me out please Link to comment Share on other sites More sharing options...
Cipscis Posted February 28, 2009 Share Posted February 28, 2009 Posting your script is always a good idea, that way we can see if you've made a mistake somewhere. I'd recommend using something like this:short sGameModeSwitch float fTimer ref rContainer Begin OnEquip set sGameModeSwitch to 1 set rContainer to GetContainer set fTimer to 5 End Begin OnUnequip set sGameModeSwitch to 0 End Begin GameMode if sGameModeSwitch if fTimer >= 0 set fTimer to fTimer - GetSecondsPassed else set fTimer to 5 rContainer.AddItem AmmoItem 1 endif endif EndMake sure that you've properly attached the script to your weapon by selecting it in the "Script" drop-down menu in the Weapon window, too. Cipscis Link to comment Share on other sites More sharing options...
saamziel Posted March 1, 2009 Author Share Posted March 1, 2009 this is the code i used ScriptName SSScript float timer begin OnEquip if timer < 5 set timer to timer + GetSecondsPassed else ;5 seconds have passed, do something special player.additem AmmoMicroFusionCell 1 set timer to 0 endif end Link to comment Share on other sites More sharing options...
Cipscis Posted March 1, 2009 Share Posted March 1, 2009 You can't run a timer during an OnEquip block, as the timer will only run for the frame in which the item is equipped. Since the item is a weapon, you can't use an Object Effect, so you'll have to use a script like this:ScriptName SSScript float fTimer short sEquipped Begin OnEquip set sEquipped to 1 End Begin OnUnequip set sEquipped to 0 End Begin GameMode if sEquipped if fTimer < 5 set fTimer to fTimer + GetSecondsPassed else ;5 seconds have passed, do something special player.AddItem AmmoMicroFusionCell 1 set fTimer to 0 endif endif End Cipscis Link to comment Share on other sites More sharing options...
saamziel Posted March 1, 2009 Author Share Posted March 1, 2009 works perfectly thank you so much Link to comment Share on other sites More sharing options...
Cipscis Posted March 1, 2009 Share Posted March 1, 2009 You're very welcome! I'm glad to hear that it's working now. Cipscis Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.