[FIXED] Swingin' Dummies

Here we stuff all the bugs we've managed to squash/squish/squelch.
Post Reply
Lok1728
UOX3 Newbie
Posts: 14
Joined: Fri Feb 03, 2006 2:54 am
Has thanked: 0
Been thanked: 0

Swingin' Dummies

Post by Lok1728 »

If you take a hit at the training dummie(s) - they don't stop swinging. You have to wait for it to stop before you can fight it some more, but it doesn't happen..

:lol:
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 »

Very peculiar. The script (trainingdummy.js) looks okay, and other items with timers (apple trees, for instance) work fine, so not sure what's wrong...

It never seems to reach the onTimer function from the little testing I've been able to do so far.

EDIT: Wait, I take the last part back, it does reach the onTimer function.
-= Ho Eyo He Hum =-
Lok1728
UOX3 Newbie
Posts: 14
Joined: Fri Feb 03, 2006 2:54 am
Has thanked: 0
Been thanked: 0

Post by Lok1728 »

Well, I tried it again. The dummy is still swinging. I take that the timer is set for 30 seconds or something?

I'm attaching the code I have in my trainingdummy.js

Code: Select all

function onUse( pUser, iUsed )
{
	var pSock = pUser.socket;
	
	//Check if user is in range of combat dummy
	if( !iUsed.InRange( pUser, 1 ) )
	{
		pUser.SysMessage( GetDictionaryEntry( 482, pSock.Language )); //You need to be closer to use that.
		return false;
	}
	else if( iUsed.id == 0x1070 || iUsed.id == 0x1074 ) //if training dummy is motionless
	{
		//Determine weapon-type by calling external script and loading a value set there afterwards
		TriggerEvent( 2500, "getWeaponType", pUser );
		var weaponType = pUser.GetTag( "weaponType" );
		
		if( weaponType == "BOWS" || weaponType == "XBOWS" )
		{
			pUser.SysMessage( GetDictionaryEntry( 938, pSock.Language )); //Practice archery on archery buttes!
			return false;
		}
		
		//Check if character is mounted or not, and then call up an external script to determine combat animations
		if( pUser.isonhorse )
			TriggerEvent( 2501, "getHorseCombatAnim", pUser, weaponType );
		else
			TriggerEvent( 2501, "getFootCombatAnim", pUser, weaponType );
		var combatAnim = parseInt( pUser.GetTag( "combatAnim" )); //convert to decimal for use with DoAction
		pUser.DoAction( combatAnim );

		//Remove the temporary tags we set on our character above
		pUser.SetTag( "weaponType", null );
		pUser.SetTag( "combatAnim", null );
		
		//Play some random sound effects when the training dummy is hit
		switch( RandomNumber( 0, 2 ) ) 
		{
			case 0: pUser.SoundEffect( 0x013B, true );	break;
			case 1: pUser.SoundEffect( 0x013C, true );	break; 
			case 2: pUser.SoundEffect( 0x013D, true );	break;
			default:  ConsoleMessage( " cSkills::TDummy -> Fallout of switch statement without default" );	return false;
		}
		
		//Change the motionless dummy to a swinging dummy!
		if( iUsed.id == 0x1070 )
			iUsed.id++;
		else if( iUsed.id == 0x1074 )
			iUsed.id++;
			
		//Star a timer so the dummy doesn't swing forever
		iUsed.StartTimer( 3000, 1, true );
		
		//Check the player's tactics skill to see if he gets chance to gain more skill
		if( pUser.skills.tactics > 250 )
			pUser.SysMessage( GetDictionaryEntry( 939, pSock.Language )); //You feel you would gain no more from using that.
		else
			pUser.CheckSkill( 27, 0, 250 );
	}
	else
		pUser.SysMessage( GetDictionaryEntry( 483, pSock.Language )); //You must wait for it to stop swinging!
	return false;
}

function onTimer( iUsed, timerID )
{
	//If timer is 1, stop the swinging dummy
	if( timerID == 1 )
	{
		if( iUsed.id == 0x1071 )
			iUsed.id--;
		else if( iUsed.id == 0x1075 )
			iUsed.id--;
	}	
}
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 »

Nah it's set to 3000 milliseconds, i.e. 3 seconds. But it keeps swinging here as well.

It looks like it's getting the timerID wrong somehow, because it reaches onTimer function but never changes the ID of the item.

And now I'm beginning to think the code for reloading JS-files is bugged as well, because I put in a iUsed.TextMessage( iUsed.id ) line in the onTimer function, and now the training dummy keeps saying it's own ID even though I've commented out the line and reloaded the script many times. :P
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Based upon what I see in the code, there is no problem with how we are passing the data to the onTimer() event, and your StartTimer() call looks fine as well.

As for reloading, I also had a look at that, and could find no evident issue.
Scott
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 »

Well, I think I found a fix for this issue, though I'm not entirely sure what causes it:

Change iUsed.StartTimer( 3000, 1, true ); to iUsed.StartTimer( 3000, 1, false);, and the training dummies should once again stop swinging once the timer has run out.

I'm not sure why this change was necessary, since the script seemed to be working when I initially released it :?.. Another thing I noticed was that the above change was not necessary if I removed all the TriggerEvent calls... no idea why :P
-= 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 »

Hey, Xuri, do already swinging dummies stop once you fix this script? Or must those dummies be deleted and then re-created? Thanks
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 »

Any existing ones will not be fixed automatically, no - so you either have to delete & recreate them or change their ID back to the original, non-animated ones. Probably just as easy to do the former :)
-= Ho Eyo He Hum =-
Post Reply