Jump to content

Script Noobie, need some very basic help to get started.


Recommended Posts

Posted

I want to start learning the script syntax, and after reading the TES4 Construction Kit it seems easy enough.

 

To begin, I want to try scripting so that whenever my character gets hit, he mutters something as long as he didn't say anything for the last 3 seconds.

 

So, this is what I think I need to do:

 

1) Create new sound entry. Pointed it to directory full of .wav's and called it MVgetHitSound

 

2) Create a new script, lets call it MVOnHit

 

ScriptName MVOnHit

short currentHP
short newHP
short doOnce

Begin GameMode

;Set up variables:
if doOnce == 0
	set currentHP to player.GetCurrentHealth
	set newHP to currentHP
	set doOnce to 1
endif

;Loop to check when currentHP != newHp
if currentHP != newHP
	set newHP to currentHP
	player.playsound3d MVgetHitSound
endif

End

 

 

3) Attach script to Player NPC.

 

 

4) Skip ???, go straight to profit.

 

However, I'm missing something. I don't know to add a timed delay, nor do I know why this won't werk.

 

Halp plz?

 

Posted

Hi kflee,

First, create a new "dummy" quest, put a check in 'Start Game Enabled' and set 'Script Processing Delay' to 0.1.
Now, create a new script, set 'Script Type' to 'Quest', and use this code:

scn	MVOnHit

float	fLastHP
float	fCurrentHP
float	fDelay

begin GameMode

	if fDelay
		set fDelay to (fDelay > 0) * (fDelay - GetSecondsPassed)
	endif

	if fCurrentHP != player.GetCurrentHealth
		set fCurrentHP to player.GetCurrentHealth
		if (fCurrentHP < fLastHP) && (fDelay == 0)
			set fDelay to 3
			player.PlaySound3D MVgetHitSound
		endif
		set fLastHP to fCurrentHP
	endif

end

 

Finally, return to the quest you created and have it use this script.

Posted (edited)

Hmmm, the script won't save.

 

EDIT: Oh, now it does.

 

Problem is that it doesn't seem to work.

 

EDIT: Got working with the PrintC commands to debug, it seems that Player.getCurrentHealth is always returning 100.000?

Wat.

 

Oh, I got it working. Great success.

 

Thank you for helping me out!

Edited by kflee
  • Recently Browsing   0 members

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