Jump to content

Need Help with a Script...


TallgeeseIV

Recommended Posts

I'm trying to get the game to seamlessly switch this armor with another that's identical except for a damaged version of the texture, and give it the original armor's health percentage when it get's to 50% health.

 

the problem is i have to make sure it only switches once, and then still be able to switch back when the armor's been repaired above 50%.

 

i'm reeeaaally bad at toggles, i don't understand them at all... here's what i have so far:

 

float ARSHealth
int Toggle

Begin GameMode
set ARSHealth to player.GetEquippedCurrentHealth 2
If ARSHealth <= 0.5 && Toggle == 0
	player.RemoveItem SamPowerArmor 1 1
	player.AddItemHealthPercent SamPowerArmorDam 1 ARSHealth 1
	player.EquipItem SamPowerArmorDam 0 1
	set Toggle to 1
Else
	set Toggle to 0
EndIf
If ARSHealth > 0.5 && Toggle == 0
	player.RemoveItem SamPowerArmorDam 1 1
	player.AddItemHealthPercent SamPowerArmor 1 ARSHealth 1
	player.EquipItem SamPowerArmor 0 1
	set Toggle to 1
Else
	set Toggle to 0
EndIf
End

 

as you can see my toggle would never work, i just need to know how to make it work...

 

or, if anyone has a better solution, please offer it. i tried destruction data but that didn't work, but maybe i did it wrong...

Link to comment
Share on other sites

I'm not sure about it, but here's what I think is correct:

float ARSHealth
int Toggle          ; if wearing damaged version = 1, if not = 0

Begin GameMode
       set ARSHealth to player.GetEquippedCurrentHealth 2
       If ARSHealth <= 0.5 && Toggle == 0
               player.RemoveItem SamPowerArmor 1 1
               player.AddItemHealthPercent SamPowerArmorDam 1 ARSHealth 1
               player.EquipItem SamPowerArmorDam 0 1
               set Toggle to 1
       EndIf
       If ARSHealth > 0.5 && Toggle == 1
               player.RemoveItem SamPowerArmorDam 1 1
               player.AddItemHealthPercent SamPowerArmor 1 ARSHealth 1
               player.EquipItem SamPowerArmor 0 1
               set Toggle to 0
       EndIf
End

As you see, I changed the function of your int Toggle a little (see comment).

I never tried anything like this, but maybe you can try it out and post your result.

Link to comment
Share on other sites

why not just use GetEquipped instead of toggle ?

If You're going to run that in quest script You'll need getequipped anyway.

If You're going to run it as spell effect initiated by OnEquip You can do just multiple scripts (one which switches to damaged, other to undamaged).

 

begin GameMode
 ref   rActor
 float fHealth
 
 set rActor to Player
 set fHealth to rActor.GetEquippedCurrentHealth 2
 if rActor.GetEquipped SamPowerArmor && fHealth < 0.5
   ... replace with damaged armor 
 elseif rActor.GetEquipped SamPowerArmorDam && fHealth >= 0.5
   ... replace with undamaged armor    
 endif
end

Link to comment
Share on other sites

Initiation by "OnEquip" shouldn't work in my opinion.

As it only checks once when being equipped (at least I think so). Which means:

Hey I got this damaged armor, let's see is it repaired itself, - No it didn't. Done.

 

But indeed you can simply use GetEquipped instead of toggle, but it's no such a big of a difference.

Link to comment
Share on other sites

@thc1234 it needs to be a constant script, not a quest or effect based script. it's basically to show the visuals of the player's armor being damaged or not, without affecting the player in any other way. it needs to be constant and seamless, and this was the only way i could think of doing it.

 

@neguel no good. the script has no effect while wearing the armor, and crashes the game when you take it off or put it on. back to the drawing board, there has to be a similar script already in use or something...

Link to comment
Share on other sites

Part of the problem is the assumption that GetEquippedCurrentHealth returns a percentage. It doesn't. It returns the number of hitpoints left on the equipped item. To get the health percent, you need to get the Ref of the Armor, the base health, and equippedcurrenthealth, and then do the math.

If the script is running every frame, there will probably be a few frames in between armor switches where it will return 0 for the armor ref. You want to make sure that the script waits until GetEquippedObject (or GetEquipped) returns a valid armor.

 

 

ref rARSArmorREF
float ARSHealth
short ARSBaseHealth
float ARSPercentHealth
int Toggle 


Begin GameMode 

 set rARSArmorREF to player.GetEquippedObject 2
 
 IF (rARSArmorREF)  ;Skip everything if in transition - might CTD without this if script is running every frame
  set ARSHealth to player.GetEquippedCurrentHealth 2 
  set ARSBaseHealth to GetBaseHealth rARSArmorREF
  set ARSPercentHealth to ARSHealth / ARSBaseHealth
  
  IF (Toggle == 0)
   If ARSPercentHealth <= 0.5
    player.RemoveItem SamPowerArmor 1 1 
    player.AddItemHealthPercent SamPowerArmorDam 1 ARSPercentHealth 1 
    player.EquipItem SamPowerArmorDam 0 1 
    set Toggle to 1
   EndIf
  EndIf

  IF (Toggle == 1)
   If ARSPercentHealth > 0.5
    player.RemoveItem SamPowerArmorDam 1 1 
    player.AddItemHealthPercent SamPowerArmor 1 ARSPercentHealth 1 
    player.EquipItem SamPowerArmor 0 1 
    set Toggle to 0
   EndIf
  EndIf
 EndIF
End

Link to comment
Share on other sites

whoa, definitely the closest. It works perfectly when the armor reaches 50% or less, but the game crashes when i go through a door wearing the new damaged version, and when i equip it again after unequipping it. any idea why?
Link to comment
Share on other sites

Ah, I got it! basically instead of using a single script with a toggle, i realized i could use the GetEquipped command and make a slightly different script for each armor and use the armor equipped at the time itself as the primary toggle, then have another toggle to essentially turn the script off:

 

Undamaged Version:

 

float ARSHealth
int Toggle

Begin GameMode
If player.GetEquipped SamPowerArmor == 1 && Toggle != 1
	set ARSHealth to player.GetEquippedCurrentHealth 2 / 400
	If ARSHealth <= 0.5 && player.GetEquipped SamPowerArmorDam != 1
		set Toggle to 1
		player.RemoveItem SamPowerArmor 1 1
		player.AddItemHealthPercent SamPowerArmorDam 1 ARSHealth 1
		player.EquipItem SamPowerArmorDam 0 1
	EndIf
EndIf
End

 

Damaged Version:

 

float ARSHealthDam
int ToggleDam

Begin GameMode
If player.GetEquipped SamPowerArmorDam == 1 && ToggleDam != 1
	set ARSHealthDam to player.GetEquippedCurrentHealth 2 / 400
	If ARSHealthDam > 0.5 && player.GetEquipped SamPowerArmor != 1
		set ToggleDam to 1
		player.RemoveItem SamPowerArmorDam 1 1
		player.AddItemHealthPercent SamPowerArmor 1 ARSHealthDam 1
		player.EquipItem SamPowerArmor 0 1
	EndIf
EndIf
End

 

Works like a charm. I even cut out all the armor from the tesla armor but kept the electricity effect, then made that an armor addon for the damaged version so it has electricity surrounding it when its broken, sooo cool. i can't wait to show this off and put it up for download!

Edited by TallgeeseIV
Link to comment
Share on other sites

  • Recently Browsing   0 members

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