[FIXED] Swingin' Dummies
- Xuri
- Site Admin
- Posts: 3704
- Joined: Mon Jun 02, 2003 9:11 am
- Location: Norway
- Has thanked: 48 times
- Been thanked: 8 times
- Contact:
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.
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 =-
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
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--;
}
}
- Xuri
- Site Admin
- Posts: 3704
- Joined: Mon Jun 02, 2003 9:11 am
- Location: Norway
- Has thanked: 48 times
- Been thanked: 8 times
- Contact:
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.
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.
-= Ho Eyo He Hum =-
- Xuri
- Site Admin
- Posts: 3704
- Joined: Mon Jun 02, 2003 9:11 am
- Location: Norway
- Has thanked: 48 times
- Been thanked: 8 times
- Contact:
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 
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
-= Ho Eyo He Hum =-