My Next Awesome Script! - spittoon.js

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

My Next Awesome Script! - spittoon.js

Post by Mindless Automaton »

I was brainstorming really hard trying to figure out what kind of script this emu was missing. (other than an exploding rabbit one)

And sudden, it hit me! A spittoon javascript!
// Spittoon Script
// Mindless Automaton

function onUseChecked( pUser, iUsed )
{
    var isInRange = pUser.InRange( iUsed, 3 );
    if( !isInRange )
    {
        pUser.SysMessage( "You are too far away to reach that." );
        return false;
    }

    if( pUser.gender == 0 )
    {
        pUser.SoundEffect(0x446, true);
    }  

    if( pUser.gender == 1 )
    {
        pUser.SoundEffect(0x334, true);
    }  

    if( pUser.gender == 2 )
    {
        pUser.SoundEffect(0x22, true);

    }  
        pause(750);
        pUser.SoundEffect(0x2DF, true);
        return false;
}

function pause(millis)
{
    var date = new Date();
    var currentDate = null;

    do { currentDate = new Date(); }
    while (currentDate-date < millis);
}
Woo hoo!
Last edited by Mindless Automaton on Thu Jun 19, 2008 2:54 am, edited 1 time in total.
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
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 »

Don't use your pause function. The server's single threaded, and what it will do is pause the entire server for 750 milliseconds. You don't want the entire world freezing every time someone uses a spittoon, surely? :)

Use a timer, there should be plenty of examples floating around for that.
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

The problem was that the sounds played at the same time otherwise.

I'll check into the timer and check it out.

Thanks!
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

Code: Select all

// Spittoon Script
// Mindless Automaton

function onUse( pUser, iUsed )
{
	var isInRange = pUser.InRange( iUsed, 3 );
	if( !isInRange )
 	{
		pUser.SysMessage( "You are too far away to reach that." );
		return false;
	}

	if( pUser.gender == 0 ) 
	{
		pUser.SoundEffect(0x446, true);
	}	

	if( pUser.gender == 1 ) 
	{
		pUser.SoundEffect(0x334, true);
	}	

	if( pUser.gender == 2 ) 
	{
		pUser.SoundEffect(0x22, true);

	}	
		iUsed.StartTimer( 750, 1, true );
		return false;
}

function onTimer( iUsed, timerID )
{
	if( timerID == 1 )
	{
		iUsed.SoundEffect(0x2DF, true);

	}
}
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Post Reply