Jump to content

[LE] How the hell do i Script this ?


Recommended Posts

2. you can always stop loop when player leave cell

Sure, you could always do something like:

Event OnCellAttach()

	Actor playerRef = Game.GetPlayer()
	Cell playerCell = playerRef.GetParentCell()
	float halfHealth = GetBaseActorValue("Health") * 0.5
	
	Cell myCell = GetParentCell()
	
	while (GetActorValue("Health") > halfHealth && IsDead() == false && myCell == playerCell)
		Utility.Wait(1.0)
	endWhile

	if ((GetActorValue("Health") <= halfHealth || IsDead() == true) && myCell == playerCell)
		YourContainer.Enable()
	endif
	
endEvent

3. for what you need function if you can use math ?

I called it a "convenience function" for a reason.

 

Dear Reneer,

 

you posted:

if (GetActorValuePercentage("Health") <= 50 || IsDead() == true)
I believe it should be as follow

if (GetActorValuePercentage("Health") <= 0.5 || IsDead() == true)
you give answer:

3. GetActorValuePercentage isn't "useless" it is simply a convenience function.
GetActorValuePercentage is native function, GetAVPercentage is the convenience function

 

I have rewritten your sample code as follow:

EnableTrigger50pActorScript

 

Scriptname EnableTrigger50pActorScript extends Actor
; https://forums.nexusmods.com/index.php?/topic/7517246-how-the-hell-do-i-script-this/

  Objectreference PROPERTY myObject auto


; -- EVENTs -- 3

EVENT OnInit()
    RegisterForSingleUpdate(1.0)
ENDEVENT


EVENT OnDeath(Actor akKiller)
    UnRegisterForUpdate()
    myObject.Enable()
ENDEVENT


EVENT OnUpdate()
IF (GetAVPercentageHealth() > 0.5)
    IF self.IsDead()
        ; see OnDeath() event
    ELSE
        RegisterForSingleUpdate(1.0)
    ENDIF
ELSE
    ; actors health is equal or lower than 50 percentage
    myObject.Enable()
ENDIF
ENDEVENT


; -- FUNCTIONs -- 2

; https://www.creationkit.com/index.php?title=GetActorValuePercentage_-_Actor
; "This function will always return 1.0, if the actor values maximum is Zero."

;-------------------------------------
Float FUNCTION GetAVPercentageHealth()  ; make your own function
;-------------------------------------
; Obtain the AV percentage of health
; This version does not take in account for buffed stats.

    float f = self.GetActorValue("Health")            ; current actorValue of health
;;;    float f = GetAVHealthMax()

    f =   f / self.GetBaseActorValue("Health")
      RETURN f
ENDFUNCTION


;------------------------------
Float FUNCTION GetAVHealthMax()  ; make your own function
;------------------------------
; Obtain the maximum AV of health
; This version takes in account for buffed stats.

    float B = self.GetBaseActorValue("Health")        ; base actor value
    float f = self.GetActorValue("Health")            ; current actor Value
    
    f = Math.Ceiling( f / self.GetActorValuePercentage("Health") ) as Float        ; current max value

IF (B < f)
    RETURN B    ; base value
ENDIF
;---------
    RETURN f    ; current value is bigger than base
ENDFUNCTION

 

 

EnableTrigger50pScript

 

Scriptname EnableTrigger50pScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/7517246-how-the-hell-do-i-script-this/

  Objectreference PROPERTY myObject auto


; -- EVENTs -- 3

EVENT OnInit()
    RegisterForSingleUpdate(1.0)
ENDEVENT


EVENT OnDeath(Actor akKiller)
    UnRegisterForUpdate()
    myObject.Enable()
ENDEVENT


EVENT OnUpdate()
    actor aRef = self.GetActorReference()

IF (GetAVPercentageHealth() > 0.5)
    IF aRef.IsDead()
        ; see OnDeath() event
    ELSE
        RegisterForSingleUpdate(1.0)
    ENDIF
ELSE
    ; actors health is equal or lower than 50 percentage
    myObject.Enable()
ENDIF
ENDEVENT


; -- FUNCTIONs -- 2

; https://www.creationkit.com/index.php?title=GetActorValuePercentage_-_Actor
; "This function will always return 1.0, if the actor values maximum is Zero."

;-------------------------------------
Float FUNCTION GetAVPercentageHealth()  ; make your own function
;-------------------------------------
; Obtain the AV percentage of health
; This version does not take in account for buffed stats.

    actor aRef = self.GetActorReference()

    float f = aRef.GetActorValue("Health")            ; current actorValue of health
;;;    float f = GetAVHealthMax()

    f =   f / aRef.GetBaseActorValue("Health")
      RETURN f
ENDFUNCTION


;------------------------------
Float FUNCTION GetAVHealthMax()  ; make your own function
;------------------------------
; Obtain the maximum AV of health
; This version takes in account for buffed stats.

    actor aRef = self.GetActorReference()

    float B = aRef.GetBaseActorValue("Health")        ; base actor value
    float f = aRef.GetActorValue("Health")            ; current actor Value
    
    f = Math.Ceiling( f / aRef.GetActorValuePercentage("Health") ) as Float        ; current max value

IF (B < f)
    RETURN B    ; base value
ENDIF
;---------
    RETURN f    ; current value is bigger than base
ENDFUNCTION

 

GetActorValuePercentage is a Native function, true, but I meant "convenience function" in the sense that you use the function instead of doing all the math yourself. And yes, there were some errors in the code I wrote. I hashed out the code in a few minutes. It was meant as a quick example for maxarturo to build upon. But thank you for pointing out the mistake.

Edited by Reneer
Link to comment
Share on other sites

I'm not from england / america / canada so my english is potato...

i dont event know what "convenience " mean... :x

 

Actor playerRef = Game.GetPlayer()

 

better version is

 

Actor Property PlayerRef Auto

cause u dont waste time for function xD

 

but ok idc, not gonna read this topic any more :x...

 

my language is Polish and little Russian and English :)

and well some German French and Japan cause i have few friends from this countries so they teach me sometimes xD

 

last time Shaurows teach me that canada is not only English but French too in few places :P lel

 

 

GL with this Script and bye !...

Link to comment
Share on other sites

Thanks a lot guys for all of your suggestions !!.


I'll check them all & test them all in a few days, right now i can't because i think i'm coming down with something... i'm not feeling too good... and i think fever is knocking at my door...


Again thank you all for taking the time to look at this !.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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