Adding Monster group & OnHit scripts

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Adding Monster group & OnHit scripts

Post by stranf »

So I looked through the DFNs and was wondering if it is possible to edit them to include a type type tag.

For example add a line:

Code: Select all

Type=Undead.

Basically I want to create some magical weapons that do special damage to specific monster types. For example, let's create a fabled Magic Sword that does some flaming damage to only undead creatures.

IE:

Code: Select all

if (Monster.Type == Undead)
{
  PlayAnimation(monster, fireAnimation);
  Damage(monster, 2d6);

}
If it is possible to do this, let me know.
Thanks!
Last edited by stranf on Sat Apr 01, 2006 9:01 pm, edited 1 time in total.
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Add a RACE=# tag to the weapons, and they'll do double damage against creatures belonging to the specific race (and yes, undeads already belong to the Undead race in races.dfn, which would be RACE=11). :)
-= Ho Eyo He Hum =-
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Thanks, that's what I needed to know.

If I get some free time, I'll start the weapons.


Do you know, off the top of your head, the correct function to display the explosin/fire/other emotes an animations to a target?
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Try something like:

Code: Select all

someChar.SpellStaticEffect( 43 ); // explosion
someChar.SpellStaticEffect( 51 ); // flamestrike
For a list of the static or moving effects done, have a squiz at spells.dfn sometime :) First two bytes of STATFX is the effect number, ditto with MOVEFX
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Thanks. It will be saturday at the earliest that I can tackle this, but it should be fun when completed. Thanks again.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Ok, I want to get my "flame weapons" out by the end of today.

I was searching the index....there is no mention of an "onHit" function.

How do I fire the script when the weapon strikes a foe?

Maybe you scripters can help me with syntax. Here is the pseudocode:

Code: Select all

onHit(target,ourObj)
{
  if (random(100) > 50)  //50% chance for fire damage
   {
     target.SpellStaticEffect( 43 ); // explosion effect
     target.FireDamage(2d8);   //2d8 firedamage 

    }



}//end onHit function

stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

No takers?

This must be harder than I thought it'd be...
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

More likely is we are just lazier than you think. :)

Let me have a look...
Scott
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

onAttack() is the event we call based on the attacker when he successfully hits a target.

onDefense() is the event we call based on the defender when he is successfully hit.

onSwing() is called every time we try to swing (but not necesarrily when we hit).
Scott
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

So you would want something like this:

Code: Select all

function onAttack( mAttacker, mDefender )
{
	CItem *mWeapon = GetWeapon( mAttacker );
	if( mWeapon.type == 40 && RandomNum( 0, 100 ) > 50 ) // The entire 40's type range is unused
	{
		mDefender.MagicEffect( 43 );
		mDefender.PlaySound( 0x0207 );
		mDefender.Damage( RollDice( 2, 8, 0 ), mAttacker );
	}
}

function GetWeapon( mAttacker )
{
	CItem *rHand = mAttacker.FindItemLayer( 1 );
	if( ValidateObject( rHand ) )
	{
		if( rHand.type != 9 ) // Spellbook
			return rHand;
		else
			return null;
	}

	CItem *lHand = mAttacker.FindItemLayer( 2 );
	if( ValidateObject( lHand ) )
		return lHand;

	return null;
}
Scott
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

I think that's a somewhat problematic solution, because, to me, the script lies in the wrong place.

Fundamentally, you're wanting to script the behaviour of the weapon when it is used to attack. So you really want a script that you can attach to an item, not a character.

I've not looked at the code in a bit, so I'm not entirely sure. But I think we need to figure out the events that are really required, and what they trigger for.

Off the top of my head (because I have to go out shortly)


1) onAttack
2) onDefend
3) onBeginCombat
4) onEndCombat
5) onDeathBlow
6) onSwing

onAttack needs to trigger for both the character and the weapon
onDefend needs to trigger for the target, at least, with maybe support for items as well? (eg the onDefend script decides that something special happens, and potentially triggers the onDefend script for a magic piece of armour?)

onBeginCombat/onEndCombat are fairly self explanatory. onEndCombat may want to pass a flag, though, something like:

onEndCombat( attacker, defender, flag );

where flag

1 == defender died
2 == attacker died
3 == defender fled
4 == attacker fled

Getting all these in together and playing well could be quite an issue, to say the least. The two onAttacks and onDefends would need to be able to communicate (perhaps the onAttack for the weapon does the pretty stuff, and passes back a damage modifier/canceller? ditto for onDefend), I think, and I would suggest that there are three scenarios for that

1) Player has onAttack, item has no script
2) Player has no script, item has onAttack
3) Player and item have onAttack

Only in case 3 can you rely on the player script calling the item one. In the other two, you'd have to handle it in code. Similar thing would happen for onDefend.

onSwing would be an event that determines if an attack lands (ie leads to an onAttack event). This would potentially be like onAttack, attached to both PC and/or item (wrestling vs weapon damage). And a quick after thought, as I'm about to run out the door: you could probably do a triple implementation for onSpellCast as well. For the attacker, for the defender, and for the defender's armour (if any).
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Maarc wrote: onSwing would be an event that determines if an attack lands (ie leads to an onAttack event). This would potentially be like onAttack, attached to both PC and/or item (wrestling vs weapon damage).
Isn't the onSwing event meant as a way to completely override the combat calculations?
Maarc wrote:And a quick after thought, as I'm about to run out the door: you could probably do a triple implementation for onSpellCast as well. For the attacker, for the defender, and for the defender's armour (if any).
With magic moving to JS is this event really needed?
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

If onSwing is meant to be a complete override, it isn't. Nothing that returns from that call will stop the code from executing, it just gets called every time a character takes a swing. Note that also, it occurs before range checks, so an onSwing event will occur even if you're half the map away.

As for onSpellCast, yes, there's still a need. Sure, magic's get moved out to JS, but that's the behaviour of the spells themselves, by and large, only. You'll still want to know when a character is casting: for NPCs, so you can switch targets and so on, for defender's, so you know when you've been hit by a spell (this would be triggered by the JS code), and on the defender's armour (if relevant and any), so that a magic platemail of grounding can discharge lightning, for instance.

And they were just thoughts off the top of my head. This isn't a comment on how the code is NOW, just some ideas as to how I think it should behave, in a broad sense. It would give enough hooks, hopefully, that all aspects of the combat code can be hooked relevantly with little fuss (for eg, right now, giwo's script would need to be applied to NPCs, not the weapon itself, where it logically should sit in the behaviour of the weapon).
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Wow. This got complex fast. :?

I know I don't do any hard-coding, so my opinion dosen't carry as much weight,

But I'd like and onHit script that can be attached to the weapons, not the PC.

The script would fire when the weapon is a *hit*.

(This prevents flame damage from damaging the monster, even if it is a miss.)

From a .js standpoint, this would be the easiest to code.

no hard-coding such a function into UOx3 in C++ is another story best left for the masters...... 8)
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

While the JS code I pasted above isn't being fired by the item (and thus you don't have the script associated with the item but the character) it would work well enough.

Basically just put that script as 0 (global) and set the type of the fire weapons to 40 (or 41, I don't recall off the top of my head what random type number I picked).

There's something to be said for using the system as it is. ;)
Scott
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Thanks. I'll give it a try.

You say I can script any weapon range in the 40s?

Is there any other range of numbers free to edit?

Thanks
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

http://sourceforge.net/docman/display_d ... _id=113893

Any number on that list is technically free.

Note that types cap at 255
Scott
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

You could also add a custom tag in your DFNs and then check against that ;).
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

That's a good point, Grimson. what is the function that checks Tag names?

In my scripts I have been using Hex ##s and it has, at time, been rather complex.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

If you've no objection, giwo, I'll see if I can't dig into the combat event routines and try and rationalise some of it, make life a bit easier, see how feasible the idea I presented is.
Post Reply