Help with a custom weapon hit script

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 097.
Note: Core 097 is no longer officially supported.

Moderator: POL Developer

Post Reply
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Help with a custom weapon hit script

Post by Poi »

I am making a bow with a custom hit script to use, this is what I have so far:

ItemDesc:

Code: Select all

Weapon 0x13PB
{
	//MainStuff
	Name		poisonbow
	Desc		poison bow
	VendorBuysFor	1999
	color		373
	graphic		5042

	//WeaponInfo
	Speed		30
	Attribute	Archery
	Anim		0x12
	Damage		9d9+8
	HitSound	0x235
	MissSound	0x239
	ProjectileAnim	0xf42
	ProjectileType	0xf3f
	ProjectileSound	0x235
	MinRange	0
	MaxRange	30
	MaxHP		100

	//Booleans
	Projectile	1
	TwoHanded	1

	//Scripts
	DestroyScript	onDestroy
	HitScript	PoisonBow
	OnHitScript	PoisonBow
	//Custom Values
	strrequired	60
	mindam		26
	maxdam		87
}
And this is the PoisonBow.src file:

Code: Select all

use uo;
use os;

include ":magery:spells";
include ":attributes:attributes";
include ":timedScripts:timedScripts";

program PoisonBow(attacker, defender, weapon, armor, basedamage, rawdamage)
	var mobile := attacker;
	var targ := defender;
	if ( !MS_MobileCheck(mobile, targ) )
		return 0;
	endif

	// Duration: (3 + (Magery * 0.4)) seconds
	var duration := CInt(3 + AP_GetSkill(mobile, MAGERY) * 0.4);
	var poison_level := 5;
	TS_StartTimer(targ, "DefaultPoison", duration, poison_level, mobile);

return 1;
endprogram
But my problem is that the bow works just the same as any other bow, its not using my hit script, I tried onhitscript and hitscript, not sure what else to do =/
Polytropon
New User
Posts: 19
Joined: Wed Sep 15, 2010 9:47 pm

Re: Help with a custom weapon hit script

Post by Polytropon »

Are you sure the script is even running? (by placing a Print or so)
If it does, the problem sould be that you messed with the distro functions.
If it does not, maybe you are hooking the attack and overriding the scripts. Or you have a wrong bow which doesn´t have that scripts attached (everything is possible).
Justae
Expert Poster
Posts: 79
Joined: Thu May 24, 2007 2:12 pm
Location: South Africa

Re: Help with a custom weapon hit script

Post by Justae »

I would be very surprised if it worked at all.

Re-check your objtype ?
The one you have posted here is invalid Weapon 0x13PB
0x13PB is not a valid hexadecimal number.
I suspect your POL.CFG may be set to ignore such errors, so POL loads, but this bow simply will not exist.
Change the Weapon Objtype to a valid bow objtype, for example :

Weapon 0x13B2
{
Name Bow
Desc Bow
........
........
........
}

0x13b2 is in the art muls, it's part of the client items. If you like you can define a NEW objtype in a valid range, let's say for example's sake objtype 0x7b00 (You can check your open unused objtypes in a file named 'objtypes.txt' in the root of your POL directory.) Do not pick any 'free' objtypes below 0x4fff or >= 0x8000 < 0x8fff

So 0x13b2, if you check UOFiddler, is a normal bow objtype. 0x13b2 is also the Graphic for this bow, so in order to create your new poison bow, you would :

Weapon 0x7b00
{
Name PoisonBow
Desc Poison Bow
graphic 0x13B2
color 373
etc
etc
etc
}

Your second problem is that the Bow itself is not the "attacking" weapon. It is simply the vehicle that uses the attacking "arrows". In other words, you need to create a new item, PoisonArrow, much in the same way you create any other item. The poison arrow itself should be recognised by your combat calculation scripts, the one's that do all the damage calculations (specifically for ranged/projectile weapons), should carry the poison-check and application code. Look for a function in all your includes named "function ModByDist" If you have that, you need to modify the way that works so that poison arrows do their thing.

Poison Arrow item example :

Item 0x6051
{
Name poisonarrow
Desc poison arrow%s
Graphic 0x0f3f
color 373
VendorSellsFor 80
VendorBuysFor 25
Weight 1/100
DestroyScript ::maindestroy
}

Cheers,
Justae.
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Re: Help with a custom weapon hit script

Post by Poi »

I see what you mean about the objtype, i didn't know they were hexadecimal numbers, so thanks for clearing that up.

I added poison arrows and understand what you mean about the bow not the attacking weapon.

I searched all the files for ModByDist, and didn't find any files with that in it(used a search utility), so what I'm wondering is can I put HitScript on the arrows? I really want to do the entire hit part with a custom script(Figure out the damage, the poison, everything) right now all I have is the poison part but I will add more later, but HitScript wont work if I put it on the custom arrows?
Justae
Expert Poster
Posts: 79
Joined: Thu May 24, 2007 2:12 pm
Location: South Africa

Re: Help with a custom weapon hit script

Post by Justae »

Hello Poi,

In your combat code somewhere, there must be a section that looks at damage done by projectile weapons. You need to find that and modify it to cater for poisoned arrows. You can try setting a poison hitscript on the arrows alone, but you would have to define them differently to standard arrows and I am not sure that should be the way to do this.

Try looking for files damages.inc and hitscript.inc, somewhere there you will find the calculations for projectile weapons, they have to exist someplace. My shard code is way too modified for me to show you as an example, it would only serve to confuse you.

Best regards,
Justae.
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Re: Help with a custom weapon hit script

Post by Poi »

I may be on the wrong path, but I gave this a try:

I changed pkg\systems\combat\config\hitscripts.cfg:


Elem WeaponHitScripts
{
//Script Name Path
Script FireHit :weapons:hitScripts/FireHit
Script IceHit :weapons:hitScripts/IceHit
Script LightningHit :weapons:hitScripts/LightningHit
Script PoisonHit :weapons:hitScripts/PoisonHit
}

and added poisonhit.src to pkg\items\weapons\hitscripts\


and my poisonhit.src looks like:

Code: Select all

use uo;
use os;
use util;

include ":damage:damage";
include "include/client";
include "include/sounds";
include ":timedScripts:timedScripts";
include ":attributes:attributes";

program HitScript(params)
	var attacker	:= params[1];
	var defender	:= params[2];
	//var weapon	:= params[3];
	//var armor	:= params[4];
	//var basedamage	:= params[5];
	//var rawdamage	:= params[6];
	params := 0; // Not needed anymore.
		
	ApplyDamageEX(defender, RandomDiceRoll("1d3"), DMG_PHYSICAL, attacker);
	
	var mobile := attacker;
	var targ := defender;

	// Duration: (3 + (Magery * 0.4)) seconds
	var duration := CInt(3 + AP_GetSkill(mobile, MAGERY) * 0.4);
	var poison_level := 5;
	TS_StartTimer(targ, "DefaultPoison", duration, poison_level, mobile);

return 1;
endprogram

I added poison arrows to my poison bow, and put hitscript :weapons:hitscripts:poisonhit to both the bow and the arrows, but its still acting like a normal bow, am I still on the wrong path?

I looked up damage.inc and hitscript.inc and didn't find any helpful info =/
Justae
Expert Poster
Posts: 79
Joined: Thu May 24, 2007 2:12 pm
Location: South Africa

Re: Help with a custom weapon hit script

Post by Justae »

It appears you may be using POL distro source code.
In that case your damage type is incorrect, it should be DMG_POISON, not DMG_PHYSICAL

I am not sure why the MAGERY skill is used as a duration timer, you may want to consider changing that to ARCHERY in your situation.

Make that change, recompile and try again.

Regards,
Justae
Poi
Grandmaster Poster
Posts: 298
Joined: Fri Apr 14, 2006 9:36 am

Re: Help with a custom weapon hit script

Post by Poi »

Well I did physical because getting hit by an arrow will still hurt, weather its poisoned or not ;)
but maybe I will do the DMG_POISON instead of the timer script for my poison damage part.

I found out that If I turn the combathook off, it uses the mainhitscript and it calls my weapon hit script and works, but it has way to many issues, it doesn't stop attacking, it attacks myself instead of the "defender" etc, so now I need to figure out why the CombatHook doesn't call my weapon hitscript, any ideas?
Post Reply