Jump to content

scripting questions


saamziel

Recommended Posts

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

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
End

Make 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

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

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

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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