Random Item healthdurability

Post » Tue May 08, 2012 5:14 am

You might know I have been cooking up a small Roguelike using Oblivion as a base for fun.

Currently I have been playing around with the idea of making all armor and weapons have random durability. So finding a new cool dagger in a chest it would have 34 durability and require you to repair it before using it at full potential. I dislike finding almost completely new armor and weapons off of skeletons. I have been playing around with the idea but I am finding this fairly simple concept a bit harder to do than I am expecting.

Does anyone here know the simplest way to go about doing this?

So far I have not been able to get this to work.

ref itemRefshort doOnceshort equipOnceshort randValCondMinshort randValCondMaxshort randValCondshort randValEnchbegin OnLoad	if doOnce == 0		set doOnce to 1		set itemRef to GetSelf		set randValCondMin to 1		set randValCondMax to 60		set randValCond to randValCondMin + GetRandomPercent * (randValCondMin - randValCondMax+1) / 100		ModObjectHealth randValCond itemRef	endifendbegin OnAdd	if doOnce == 0		set doOnce to 1		set itemRef to GetSelf		set randValCondMin to 1		set randValCondMax to 60		set randValCond to randValCondMin + GetRandomPercent * (randValCondMin - randValCondMax+1) / 100		ModObjectHealth randValCond itemRef	endifendbegin OnEquip	if equipOnce == 0		set equipOnce to 1		set randValEnch to GetRandomPercent		if randValEnch <= 2			Message "This item has a deadly curse..."					endif	endifend
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Tue May 08, 2012 7:53 am

Others know the OnLoad, etc. blocks better than me, so I leave that to others. but I can tell you that the part where you actually change the item heatlt doesn't do what you think. ModObjectHealth changes the base object health. E.g. if you find a sword whose base health is 200 and you call ModObjectHealth -50 on that, what you do, is to reduce the durability of all swords in the game of that type from 200 to 150 - without changing the current health of the sword you found.

To do what you want, you need to use SetCurrentHealth instead. E.g. something like:

let currentHealth :=  itemRef.GetCurrentHealth * GetRandomPercent  / 100itemRef.SetCurrentHealth currentHealth 
This will randomize the current health, with the avarage half of what it was.
User avatar
Lalla Vu
 
Posts: 3411
Joined: Wed Jul 19, 2006 9:40 am

Post » Tue May 08, 2012 1:57 am

Thank you TheNiceOne :)

However, I tried your suggestion and it seems like the item still has 100% health no matter what... :/
This is really strange...
User avatar
sam smith
 
Posts: 3386
Joined: Sun Aug 05, 2007 3:55 am

Post » Tue May 08, 2012 10:23 am

I know absolutely nothing about scripting, but this is the internet, so I get an opinion!

Is it possible to use OBSE to directly inflict wear damage on the item(s)? That, from the outside, would seem to be the ideal case, since items have varying health levels. x% damage will knock off x% health no matter what it's base health.

Using (somehow) the Disintegrate Armor or Weapon spell effects for example when an item spawns?
User avatar
Portions
 
Posts: 3499
Joined: Thu Jun 14, 2007 1:47 am

Post » Tue May 08, 2012 3:22 am

I know absolutely nothing about scripting, but this is the internet, so I get an opinion!

Is it possible to use OBSE to directly inflict wear damage on the item(s)? That, from the outside, would seem to be the ideal case, since items have varying health levels. x% damage will knock off x% health no matter what it's base health.

Using (somehow) the Disintegrate Armor or Weapon spell effects for example when an item spawns?
Disintegrate weapon/armor can only be casted on an actor, reducing the health of the weapon/armor he/she have.
It can't be casted directly on an item.

To inflict damage to an item you have to do what TheNiceOne said: SetCurrentHealth


@TheCastle
I've picked this from the OBSE documentation about http://obse.silverlock.org/obse_command_doc.html#Inventory_Reference
Spoiler
scriptName ExampleInvRefSCR	; attached to a container/actor reference	ref iter	ref container	short count	begin onActivate		let container := getSelf		foreach iter <- container			let count := iter.GetRefCount			print "Found " + $count + " " + iter.GetName + "(s)"			if iter.GetOwner && iter.GetOwner != playerRef				if iter.IsEquipped == 0		; can't remove equipped items					; move stolen items to another container					iter.RemoveMeIR someOtherContainerRef				endif			else				; remove completely				iter.RemoveMeIR			endif			; iter is now invalid because RemoveMeIR was used - so we won't attempt to continue using it		loop	; now that loop has terminated, iter has been set to null (0)	end
Just change it to:
Spoiler
scriptName ExampleInvRefSCR	; attached to a container/actor referenceref iterref containershort newHealthfloat mult	begin onActivate		let randValCondMin := 0		; You can find broken items		let randValCondMax := 100		; But also intact items		let container := getSelf		foreach iter <- container			If (iter.isArmor) || (iter.isWeapon)				let mult := randValCondMin + GetRandomPercent*(randValCondMax-randValCondMin)				let newHealth := (iter.GetCurrentHealth) * mult/100				iter.SetCurrentHealth newHealth			endif		loop	end
There's only 1 little problem: if there are more items of the same kind in the container (Example 2 steel gauntlets), they get the same health value.
To solve this you should do:

Check if there are more items of same kind of the one currently processed (and how many).
Remove all these items
WHILE
Create a temporary ref for a single item of that kind.
Edit his health
Add it to the container
LOOP (Until you've put back all them in the container)
User avatar
Michelle Serenity Boss
 
Posts: 3341
Joined: Tue Oct 17, 2006 10:49 am

Post » Tue May 08, 2012 10:38 am

Thank you guys and sorry for the delayed response.
What is strange about this is I have felt like I have had a pretty good grasp of scripting on this engine now. I am not spectacular by any means but I feel like I can do things... Then I look at the above code examples and I am puzzled as hell lol... Its a good thing this forum exists or I would have wasted a hell of a lot of time attempting to figure out the above. :/
User avatar
Eileen Müller
 
Posts: 3366
Joined: Fri Apr 13, 2007 9:06 am

Post » Tue May 08, 2012 7:26 am

And on that note the script still does not seem to change the health of the items... I need the script to be on the weapons and armor because there will be times when an item is simply sitting in the world as well as being added to chests. I give the player a bronze dagger as the starting weapon and would prefer it to not be at 100% health either. What is really strange is that I don't seem to see documentation on a lot of the commands used on the wiki...

Not sure how I can go about making the above script example you have given me to be placed on the weapons and armor themselves rather than on the containers.
User avatar
Abel Vazquez
 
Posts: 3334
Joined: Tue Aug 14, 2007 12:25 am

Post » Tue May 08, 2012 6:48 am

Ok I figured it out now and have it working properly. Now to come up with an interesting list of enchantments and potential curses for weapons and armor :)
Thank you everyone!
User avatar
He got the
 
Posts: 3399
Joined: Sat Nov 17, 2007 12:19 pm


Return to IV - Oblivion