UOX3 Script Engine

API and Event handling

 

inRange
Prototype
function inRange( pCharacter, objInRange, objType )
When triggeredobjInRange comes into visible range of pCharacter. pCharacter's script is activated
NotesobjType == 0 indicates objInRange is a character
objType == 1 indicates objInRange is an item
PurposeUseful for when you want to do something when a certain thing comes into range. You could yell out guards when a murderer comes into range, for instance, if you're in a guarded region.
Example of Usage
function inRange( pCharacter, objInRange, objType )
{
	if( objType == 1 )	// An item came into range
	{
		pCharacter.DoStaticEffect( 0x376A, 9, 0, );	// Make some sparkles!
		if( objInRange.id == 0x1416 )	// Ooh, it's a purty piece of armour
		{
			pCharacter.EmoteMessage( "*ooooooooooooo*" );
		}
	}
}

 

onAISliver
Prototype
function onAISliver( npcChar )
When triggeredEvery AI loop, during their AI slice
Notes
PurposeGreat customization of AI on a per NPC basis.
Example of Usage
function onAISliver( tChar )
{

tChar.DoAction( 111 );
}
//The NPC tChar performs action 111 (dance-animation in 3D UO clients)
//on every NPC ai check, essentially looping the animation =)

 

onAttack
Prototype
function onAttack( pAttacker, pDefender )
When triggered When pAttacker attacks pDefender (in each "round" of combat)
NotespAttacker's script is activated, and pDefender's onDefense event is fired!
PurposeFlesh out the attacking code.
Example of Usage
function onAttack( pAttacker, pDefender )
{
pAttacker.TextMessage( "Who lives in that castle?" );
pDefender.TextMessage( "Help! Help! I'm being repressed!" );
}

 

onBuy
Prototype
function onBuy( pSock, Vendor )
When triggered Runs on NPC vendor before tradegump opens
NotesCan be used to completely block access to a vendor based on criterias of one's choosing.
PurposeTo allow more control over who can access NPC vendors.
Example of Usage
function onBuy( pSock, Vendor )
{
	// If player does not belong to the undead race, vendor wants nothing to do with him!
	if( pSock.currentChar.raceID != 11 )
	{
		Vendor.TextMessage( "Sorry, I don't sell to the likes of you!" );
		return false;
	}
	else
		return true;
}

 

onBuyFromVendor
Prototype
function onBuyFromVendor( pSock, Vendor, iBought )
When triggeredRuns on item after player verifies purchase, but before purchase has gone through
NotesReturn false will block the sale from going through, without closing the menu.
Return true will make the purchase go through as normal.
PurposeTo allow restricting the purchase of specific items
Example of Usage
function onBuyFromVendor( pSock, Vendor, iBought )
{
	var pUser = pSock.currentChar;
	pUser.TextMessage( "I am buying an item ("+iBought.name+") from a vendor!" );
	Vendor.TextMessage( "I am selling an item!" );
	return true;
}

 

onBoughtFromVendor
Prototype
function onBoughtFromVendor( pSock, Vendor, iBought )
When triggeredRuns on item after purchase has gone through and item has reached player's backpack.
NotesUsed, amongst other things, for automatically turning pet-statues bought from animal-trainers into actual pets
PurposeTo allow manipulating the item that has been bought, immediately after it reaches the player's backpack.
Example of Usage
function onBoughtFromVendor( pSock, Vendor, iBought )
{
	var pUser = pSock.currentChar;
	pUser.TextMessage( "I bought an item ("+iBought.name+") from a vendor!" );
	Vendor.TextMessage( "I just sold an item to some random dude!" );
	return true;
}

 

onCallback
Prototype
function onCallback#( socket, target )
When triggeredTriggered for player who selects a target initiated from a CustomTarget method
Notes# behind onCallback function-name is linked to the # used in the CustomTarget method that initiated the targeting cursor.
PurposeTo handle callbacks from targeting cursors
Example of Usage
function CommandRegistration()
{
	RegisterCommand( "disconnect", 2, true );
}
function command_DISCONNECT( socket, cmdString )
{
	var targMsg = GetDictionaryEntry( 196, socket.Language );
	socket.CustomTarget( 0, targMsg );
}
function onCallback0( socket, ourObj )
{
	if( !socket.GetWord( 1 ) && ourObj.isChar && ourObj.online )
	{
		var targSock = ourObj.socket;
		if( targSock && targSock != socket )
		{
			socket.SysMessage( GetDictionaryEntry( 1029, socket.Language ) );
			targSock.SysMessage( GetDictionaryEntry( 1030, targSock.Language ) );
			targSock.Disconnect();
		}
	}
}

 

onCharDoubleClick
Prototype
function onCharDoubleClick( pUser, targChar )
When triggeredWhen pUser double-clicks targChar. Replaces any code behaviour that may exist
NotestargChar's script is activated
PurposeTo allow greater customization of doubleclicking on characters.
Example of Usage
function onCharDoubleClick( pUser, targChar )
{
	targChar.TextMessage( "If you think you'll be allowed to see my paperdoll, think again!" );
	return false;
}

 

onClick
Prototype
function onClick( pUser, iUsed )
When triggeredWhen pUser single-clicks iUsed. Replaces any code behaviour that may exist
NotesiUsed's script is activated
PurposeTo allow greater customization on clicking on items.
Example of Usage
function onClick( pUser, iUsed )
{
	pUser.SysMessage("You have clicked on: "+iUsed.name );
}

 

onCollide
Prototype
function onCollide( targSock, pColliding, objCollidedWith )
When triggeredWhen pColliding collides with objCollidedWith (stepped on basically)
NotesobjCollidedWith is only an item currently. targSock is -1 if pColliding is an NPC
PurposeReplace of collision based triggers, increase teleporter abilities
Example of Usage
function onCollide( trgSock, srcChar, trgItem )
{
	srcChar.Teleport( srcChar.x + 5, srcChar.y +5, srcChar.z, 0 );
	srcChar.EmoteMessage( "*Eegads, I am teleported!*" );
	//srcChar.DoStaticEffect( 0x376A, 9, 0, 0 );
}

 

onCombatStart
Prototype
function onCombatStart( pAttacker, pDefender )
When triggeredWhen pAttacker attacks someone, pAttacker's script is triggered.
NotesReturn false to override existing hardcoded combat completely, return true to let hardcoded combat run it's course
PurposeTo allow overriding combat functionality
Example of Usage
function onCombatStart( pAttacker, pDefender )
{
	pAttacker.TextMessage( "I'm attacking!" );
	pDefender.TextMessage( "I'm being attacked!" );
	return true;
}

 

onCombatEnd
Prototype
function onCombatEnd( currChar, targChar )
When triggeredWhen either currChar or targChar dies or goes out of range, the script is fired
Notesreturn false to override what happens after combat ends, return true to allow hardcoded implementation to run
PurposeAllow to override what happens when combat between two characters ends
Example of Usage
function onCombatEnd( pDefender, pAttacker )
{
	if( currChar.health != 0 )
		currChar.TextMessage( "Whee! I survived combat!" );
	if( targChar.health != 0 )
		targChar.TextMessage( "Yay! I survived combat!" );
	return true;
}

 

onCombatDamageCalc
Prototype
function onCombatDamageCalc( attacker, defender, getFightSkill )
When triggeredEverytime combat damage calculation occurs this event is fired
NotesReturn a damage value to override the combat calculation of the engine, or a negative value to use the engine
PurposeAllow to override the combat damage calculation
Example of Usage
function onCombatDamageCalc( pAttacker, pDefender, fightSkill )
{
	var baseDamage = pAttacker.attack;
	var hitLoc = CalculateHitLoc();

	if( baseDamage == -1 )  // No damage if weapon breaks
		return 0;

	var damage = ApplyDamageBonuses( 1, pAttacker, pDefender, fightSkill, hitLoc, baseDamage );

	if( damage < 1 )
		return 0;

	damage = ApplyDefenseModifiers( 1, pAttacker, pDefender, fightSkill, hitLoc, damage, true);

	if( damage <= 0 )
		damage = RandomNumber( 0, 4 );

	if( !pDefender.npc )
		damage /= 2;

	return damage;
}

 

onCreateDFN
Prototype
function onCreateDFN( objMade, objType )
When triggeredWhen an item or char is created. Note that for PCs, this is triggered when they first enter the world.
NotesobjType == 0 indicates an item
objType == 1 indicates a character
PurposeUsed for customization of players at creation, or tinkering items/chars when they're made.
Example of Usage
function onCreate( objMade, objType )
{
	if( objType == 1 )
		objMade.SysMessage( "Welcome to Our Unique World(TM)!" );
}
// When this script is setup as "global id" (0) in JSE_FILEASSOCIATIONS.SCP,
// it will send the sysmessage to all NEW characters that enters the world.

 

onCreateTile
Prototype
function onCreateTile( objMade, objType )
When triggeredWhen a non-DFN based item is created.
NotesobjType == 0 indicates an item
objType == 1 indicates a character
PurposeUsed for customization of non-DFN based items at creation.
Example of Usage
function onCreate( objMade, objType )
{
	objMade.name = "A renamed item";
}
// Only scripts using script-id 0 or ones assigned through harditems.dfn will work with this event.

 

onDamage
Prototype
function onDamage( damaged, attacker, damageValue );
When triggeredWhen the char "damaged" gets damaged
NotesThe attacker can be a char or NULL
PurposeCustom reactions to damage.
Example of Usage
function onDamage( damaged, attacker, damageValue )
{
	damaged.TextMessage( "Ouch, those "+damageValue+" points of damage hurt." );
}

 

onDeath
Prototype
function onDeath( pDead );
When triggeredWhen the player or NPC pDead dies
Notes
PurposeCustom death sequence. Can do things like an explosion anim and what not here, for impact's sake.
Example of Usage
function onDeath( pDead )
{
	pDead.Teleport( 1000, 1000, 0 );
}

 

onDeathBlow
Prototype
function onDeathBlow( pKilled, pKiller );
When triggered When a killing blow has been made
Notes
Purpose Custom reactions after a killing blow has been made
Example of Usage
function onDeathBlow( pDead, pKiller )
{
	pDead.health = pDead.health + 10;
	pDead.TextMessage( "But I'm not dead!" );
	return true;
}

 

onDecay
Prototype
function onDecay( iDecaying )
When triggeredWhen iDecaying decays
NotesCURRENTLY BROKEN!!!
Purpose
Example of Usage
function onDecay( iDecaying )
{
	iDecaying.StaticEffect( 0x376A, 9, 6 );
}

 

onDefense
Prototype
function onDefense( pAttacker, pDefender )
When triggeredWhen pAttacker attacks pDefender (in each "round" of combat)
NotespDefender's script fires, pAttacker's onAttack event is also fired
PurposeFlesh out the attacking code.
Example of Usage
function onDefense( pAttacker, pDefender )
{
pAttacker.TextMessage( "Who lives in that castle?" );
pDefender.TextMessage( "Help! Help! I'm being repressed!" );
}

 

onDelete
Prototype
function onDelete( objDestroyed, objType )
When triggeredWhen an item or character is deleted
NotesobjType == 0 indicates an item
objType == 1 indicates a character
Purpose
Example of Usage
function onDelete( objDestroyed, objType )
{
	if( objType == 0 )
		ConsoleMessage( objDestroyed.name+" has been deleted from the world." );
}

 

onDispel
Prototype
function onDispel( objDispelled, objType )
When triggeredWhen objDispelled is dispelled. objDispelled's script is activated.
NotesobjType == 0 indicates a character
objType == 1 indicates an item
Purpose
Example of Usage
function onDispel( objDispelled, objType )
{
	ConsoleMessage( objDispelled.name+" has been dispelled." );
}

 

onDrop
Prototype
function onDrop( iDropped, pDropper )
When triggeredWhen pDropper drops iDropped.
NotesiDropped's script is activated.
PurposeAllowing control over dropping items from cursor
Example of Usage
function onDrop( iDropped, pDropper )
{
	var pSock = pDropper.socket;

	//Lets fetch the serial of the target-location
	var temp1 = pSock.GetByte( 10 );
	var temp2 = pSock.GetByte( 11 );
	var temp3 = pSock.GetByte( 12 );
	var temp4 = pSock.GetByte( 13 );

	//Check the value of Byte 10 to determine if the target is ground, character or container
	if( temp1 == 0 ) //Target is a character
	{
		var targetChar = CalcCharFromSer( temp1, temp2, temp3, temp4 )
		pDropper.TextMessage( "I've dropped this item on a character named "+targetChar.name+", let's bounce it back." );
		return false;
	}
	if( temp1 == 0xFF ) //Target is ground or another item
	{
		pDropper.TextMessage( "I've dropped this item on the ground or on another item." );
		return;
	}
	if( temp1 <= 0x40 ) //Target is a container
	{
		var targetItem = CalcItemFromItem( temp1, temp2, temp3, temp4 );
		pDropper.TextMessage( "I've dropped this item in/on a container with ID "+targetItem.id+"." );
		return;
	}
}

 

onDropItemOnItem
Prototype
function onDropItemOnItem( iDropped, cDropper, iDroppedOn )
When triggeredWhen iDropped is dropped by cDropper on iDroppedOn
NotesFirst iDropped's script is activated, and if it doesn't bounce, then same script is activated for iDroppedOn
Return Value Table:
0 == bounce
1 == don't bounce, use code
2 == don't bounce, don't use code
Purpose
Example of Usage
function onDropItemOnItem( iDropped, cDropper, iDroppedOn )
{
	if( iDropped.id == 0x1f14 ) //If the item being dropped is a recall rune
	{
		if( iDroppedOn.id == 0x0efa ) //If the item being dropped on is a spellbook
		{
			cDropper.TextMessage("I am dropping "+iDropped.name+" on a "+iDroppedOn.name );
		}
	}
	else
	{
		cDropper.TextMessage( "Generic error message!" );
		return 0;
	}
}

 

onDropItemOnNpc
Prototype
function onDropItemOnNpc( pDropper, pDroppedOn, iDropped )
When triggeredWhen iDropped is dropped on pDroppedOn
NotesFirst iDropped's script is activated, and if it doesn't bounce, then same script is activated for pDroppedOn
Return Value Table:
0 == bounce
1 == don't bounce, use code
2 == don't bounce, don't use code
Purpose
Example of Usage
function onDropItemOnNpc( pDropper, pDroppedOn, iDropped )
{
	pDropper.TextMessage("Here, I offer you my this object as a gift of friendship.");
	pDroppedOn.TextMessage("Fudge off!");
	iDropped.colour =13;
	return 0;
}

 

onEnterEvadeState
Prototype
function onEnterEvadeState( mNPC, enemyChar )
When triggeredWhen mNPC enters evasion state in combat due to being unable to reach enemyChar
NotesAs part of entering evasion state, the NPC's health will automatically be reset to maximum
PurposeTo allow custom reactions when NPCs enter evasion state. Could for instance have the NPC lash out in panic and destroy nearby dynamic, non-locked down and blocking items...
Example of Usage
function onEnterEvadeState( mNPC, enemyChar )
{
	mChar.TextMessage( "I've entered the Evade state! My HP will be replenished..." );
	enemyChar.TextMessage( "Oops, I caused the NPC to enter Evade state!" );
}

 

onEnterRegion
Prototype
function onEnterRegion( pEntering, regionEntered )
When triggeredWhen pEntering enters regionEntered
NotesRegion-scripts can be attached to regions through regions.dfn, using the script=# tag
PurposeTo allow custom reactions when players enter regions
Example of Usage
function onEnterRegion( pEntering, regionEntered )
{
	if( pEntering.raceID != 11 )
	{
		//sound the alarm! non-undead intruder to region
		//spawn undead guards
	}
}

 

onEntrance
Prototype
function onEntrance( iEntered, objEntering, objType )
When triggeredWhen objEntering enters the multi object iEntered
NotesobjType == 0 indicates objEntering is a character
objType == 1 indicates objEntering is an item
iEntered's script is activated, objEntering's script is entered
Purpose
Example of Usage
function onEntrance( iEntered, objEntering, objType )
{
	if( objType == 0 )
		objEntering.SysMessage("You have entered "+iEntered.name);
}

 

onEquip
Prototype
function onEquip( pEquipper, iEquipped )
When triggeredWhen pEquipper equips iEquipped
NotesiEquipped's script is activated
Purpose
Example of Usage
function onEquip( pEquipper, iEquipped )
{
	pEquipper.StaticEffect( 0x376A, 9, 6 );
}

 

onFall
Prototype
function onFall( pFall, fallDistance )
When triggeredWhen pFall falls fallDistance
NotespFall can be either an npc or pc, will only trigger if fallDistance is over 20, so it does not trigger whenever a character walks down steps/off small ledges/down hills, etc.
Purpose
Example of Usage
function onFall( pFall, fallDistance )
{
	if( fallDistance > 20 )
		pFall.SysMessage("Yikes! That was a long fall!");
}

 

onFlagChange
Prototype
function onFlagChange( pChanging, newStatus, oldStatus );
When triggeredWhen a player's status changes. IE innocent -> criminal, criminal->murderer, and so on.
NotesMay not fire instantly when the action is made. However, won't be long after change occurs will it be visible.
Purpose
Example of Usage

 

onGumpInput
Prototype
When triggered
Notes
Purpose
Example of Usage

 

onGumpPress
Prototype
function onGumpPress( pSock, pButton, gumpData )
When triggeredWhen a player presses a button in a Gump.
NotespButton is the button-ids for normal gump-buttons, while gumpData handles radiobutton-ids, checkbox-ids, and text-entry-ids(and the text-entries).
Purpose
Example of Usage
function onGumpPress( pSock, pButton, gumpData )
{
	var pUser = pSock.currentChar;
	switch(pButton)
	{
		case 0:
			// abort and do nothing
			break;
		case 1:
			var Text1 = gumpData.getEdit(0);
			pUser.SysMessage( "The first TextEntry was: "+Text1 );
			var Text2 = gumpData.getEdit(1);
			pUser.SysMessage( "The second TextEntry was: "+Text2 )
			var OtherButton = gumpData.getButton(0);
			switch(RadioButton)
			{
				case 0:
					pUser.SysMessage( "You selected RadioButton number: "+OtherButton );
					pUser.DoAction( 15 );
					break;
				case 1:
					pUser.SysMessage( "You selected RadioButton number: "+OtherButton );
					pUser.DoAction( 11 );
					break;
				case 2:
					pUser.SysMessage( "The Checkbox with ID "+OtherButton+" was checked." );
					pUser.DoAction( 18 );
					break;

			}
			break;
	}
}

 

onHouseCommand
Prototype
function onHouseCommand( pSocket, iMulti, cmdID )
When triggeredWhen a player speaks a house command while inside a house
NotescmdID is the ID of a triggerword uttered by the player. These triggerwords are defined client-side.
PurposeTo bring house command handling from hard code to JS engine, making it easier to adjust and extend the housing system in the future.
Example of Usage
function onHouseCommand( pSocket, iMulti, cmdID )
{
	if( ValidateObject( iMulti ) && iMulti.IsInMulti( pSocket.currentChar ))
	{
		switch( cmdID )
		{
			case 34: // Remove Thyself
				pSocket.CustomTarget( 0, "Who do you want to remove from your house?" );
				break;
			default:
				Console.Log( "Unhandled house command detected with cmdID: " + cmdID );
				return false;
		}
	}

	return true;
}

 

onHungerChange
Prototype
function onHungerChange( pChanging, newStatus );
When triggeredWhen a player's hunger level changes goes down.
NotesIf overridden, the normal hunger messages are not displayed.
PurposeTo allow customization of behaviour when a character's hunger level changes. Could be used for wilding of pets, or for changing AI of monsters.
Example of Usage
function onHungerChange( pChanging, newStatus )

{
TextMessage( pChanging, "ooooo, I feel more hungry" );
if( newStatus == 0 )
{
TextMessage( pChanging, "I'm melting, I'm melting!" );
}
}

 

onIterate
Prototype
function onIterate( object )
When triggeredOn every object our iterator comes across.
Notesif return value from script is true, it continues on running the loop
if return value is false, then the loop is halted
PurposeTo allow JS to loop through all world objects.
Example of Usage
function doStuff( socket, pUser )
{
	socket.SysMessage( "Killing all NPCs" );
	var numKilled = IterateOver( "CHARACTER" );
	socket.SysMessage( "Killed " + NumToString( numKilled ) + " NPCs " );
}

function onIterate( charCheck )
{
	if( !charCheck )
		return false;
	if( charCheck.npc )
		charCheck.Kill();
	return true;
}

 

onLeaveRegion
Prototype
function onLeaveRegion( pLeaver, regionLeft )
When triggeredWhen pLeaver leaves regionLeft
NotesRegion-scripts can be attached to regions through the script=# tag in regions.dfn
PurposeTo allow reactions when characters leave regions
Example of Usage
function onLeaveRegion( pLeaver, regionLeft )
{
	//if pLeaver is not allowed to leave the region
	//turn him into a criminal and spawn guards to go after him!
}

 

onLeaving
Prototype
function onLeaving( iLeft, objLeaving, objType )
When triggeredwhen objLeaving leaves the multi object iLeft
NotesobjType == 0 indicates objLeaving is a character
objType == 1 indicates objLeaving is an item
iLeft's script is activated, objLeaving's script is activated
Purpose
Example of Usage
function onLeaving( iLeft, objLeaving, objType )
{
	if( objType == 0 )
		objLeaving.SysMessage("You have left "+iLeft.name);
}

 

onLightChange
Prototype
function onLightChange( object, lightlevel )
When triggeredTriggers for object (char or item) when lightlevel changes
Notes
Purpose
Example of Usage
function onLightChange( object, lightlevel )
{
	(pseudo-code)
	if( object && object is item )
	{
		if( object.id equals unlit lamppost )
		{
			if( lightlevel > 10 ) //high light levels = dark, low light levels = bright
			{
				object.id = lit lamppost
			}
		}
		else if( object.id equals lit lamppost )
		{
			if( lightlevel < 10 )
			{
				object.id = unlit lamppost
			}
		}
	}
}

 

onLogin
Prototype
function onLogin( sockPlayer, pChar )
When triggeredWhen pChar is logged in to the world
NotessockPlayer is never -1
PurposeTo allow customization of what happens when a player logs in. Could pop up custom gumps, or do certain things (say everyone ALWAYS starts in one spot, no matter where they logged in. Diabloesque hall logins).
Example of Usage
function onLogin( sockPlayer, pChar )

{
pChar.Teleport( 1000, 1000, 0, 0 );
}

 

onLogout
Prototype
function onLogout( sockPlayer, pChar )
When triggeredWhen pChar is logging out of the world
NotessockPlayer is never -1
PurposeTo allow customization of what happens when a player logs out. Could pop up custom gumps, or do certain things to the character.
Example of Usage
function onLogin( sockPlayer, pChar )

{
sockPlayer.SysMessage ( "Farewell! Come back soon." );
}

 

onPacketReceive
Prototype
function onPacketReceive( socket, packetNum, subCommand )
When triggeredWhen receiving a network packet
NotesOVERLOADPACKETS needs to be enabled in UOX.INI and each specific packet script must be registered in jse_fileassociations.scp and registered with UOX3 via the PacketRegistration/RegisterPacket functions. Note that subCommand is currently not supported; can be left as 0. IMPORTANT: Once a packet has been registered this way, it needs to be handled in its entirety through the script, including any and all responses expected by the client. Not sending the correct response to a packet, or reading the wrong amount of bytes for the packet can result in unexpected behaviour in client/server.
PurposeSimilar to "packet-hooks" in other emulators - allows overriding the handling of incoming network packets without modifying the server source-code
Example of Usage
function PacketRegistration()
{
	RegisterPacket( [packetID], [subCommand] );
}

function onPacketReceive( pSocket, packetNum, subCommand )
{
	var cmd = pSocket.GetByte( 0 );
	if( cmd != packetNum )
		return;

	... // Read packet data here, using ReadBytes, GetByte, GetWord, GetDWord, GetSByte, GetSWord, GetSDWord and GetString socket methods
	return;
}

 

onPathfindEnd
Prototype
function onPathfindEnd( tChar, pathfindResult )
When triggeredWhen NPC pathfinding after JS methods WalkTo()/RunTo() comes to an end
NotespathfindResult parameter returns -1 if pathfinding failed, 0 if pathfinding partially succeeded but final location was blocked by a character, and 1 if pathfinding succeeded and NPC reached target location
PurposeCan be used to detect when NPC pathfinding comes to an end
Example of Usage
function onPathfindEnd( tChar, pathfindResult )
{
	if( ValidateObject( tChar ))
	{
		tChar.TextMessage( "Pathfinding ended! Result of pathfinding was... ");
		switch( pathfindResult )
		{
			case -1: // Pathfinding failed
				tChar.TextMessage( "...a failure! I couldn't move at all." );
				break;
			case 0: // Pathfinding partially succeeded, but didn't make it all the way to target destination
				tChar.TextMessage( "...a partial success! I made it part of the way there." );
				break;
			case 1: // Reached end of the path
				tChar.TextMessage( "...a success! I reached my target location." );
				break;
			default:
				tChar.TextMessage( "...a success? A failure? I have no idea. Result unknown!" );
				break;
		}

	}
}

 

onPickup
Prototype
function onPickup( iPickedUp, pGrabber )
When triggeredWhen pGrabber picks up iPickedUp
NotesiPickedUp's script is activated.
Purpose
Example of Usage
function onPickup( iPickedUp, pGrabber )
{
	var pSock = pGrabber.socket;

	//Check the value of pSock.pickupSpot to determine where the item was picked up from
	switch( pSock.pickupSpot )
	{
		case 0: //nowhere
			pGrabber.TextMessage( "I picked up this item from... NOWHERE!" );
			break;
		case 1: //ground
			pGrabber.TextMessage( "I picked up this item from the ground." );
			break;
		case 2: //ownpack
			pGrabber.TextMessage( "I picked up this item from my own backpack." );
			break;
		case 3: //otherpack
			pGrabber.TextMessage( "I picked up this item from a container." );
			break;
		case 4: //paperdoll
			pGrabber.TextMessage( "I picked up this item from my paperdoll." );
			break;
		case 5: //bank
			pGrabber.TextMessage( "I picked up this item from my bank box." );
			break;
		default:
			pGrabber.TextMessage( "Error. Redo from Start." );
			break;
	}

	//Use return false to disallow the pickup and bounce item
	//return false;
}

 

onResurrect
Prototype
function onRessurect( pAlive );
When triggered When a player pAlive is being resurrected
NotesOnly applies to PCs
Purpose Control over what happens when a person comes to life once more
Example of Usage
function onResurrect( pAlive )
{
	var ResAmount = pAlive.GetTag( "ResAmount" );
	if( ResAmount && ResAmount < 5 )
	{
		pAlive.SysMessage( "You still have some spirit left... have a good one!" );
		return true;
	}
	else
	{
		pAlive.SysMessage( "You've resurrected too many times already! Have fun in the gray world!" );
		return false;
	}
}

 

onScrollCast
Prototype
function onScrollCast( pUser, spellID )
When triggeredWhen a spell is cast using a magic scroll
NotesReturn value table:
-2: use NORMAL non-JS casting
-1: CANCEL normal spellcasting
0->inf: Spell delay in ms
PurposeTo allow overriding spellcasting from magic scrolls
Example of Usage
function onScrollCast( pUser, spellID )
{
	if( spellID == 18 )
	{
		pUser.TextMessage( "I'm casting a fireball from a fireball-scroll!" );
		return -1;
	}
}

 

onSell
Prototype
function onSell( pSock, Vendor )
When triggeredRuns on vendor before tradegump opens.
Notes
PurposeTo allow greater control over who can sell stuff to specific vendors.
Example of Usage
function onSell( pSock, Vendor )
{
	// If player does not belong to the undead race, vendor wants nothing to do with him!
	if( pSock.currentChar.raceID != 11 )
	{
		Vendor.TextMessage( "RIGHT! As if I would buy from you..." );
		return false;
	}
	else
		return true;
}

 

onSellToVendor
Prototype
function onSellToVendor( pSock, Vendor, iSold )
When triggeredRuns on item after player verifies sale, but before sale actually goes through.
NotesReturn false will block the sale from going through, without closing the menu.
Return true will make the sale go through as normal.
PurposeTo allow greater control over the selling of specific items to vendors
Example of Usage
function onSellToVendor( pSock, Vendor, iSold )
{
	var pUser = pSock.currentChar;
	pUser.TextMessage( "I am selling an item ("+iSold.name+") to a vendor!" );
	Vendor.TextMessage( "I am buying an item!" );
	return true;
}

 

onSoldToVendor
Prototype
function onSoldToVendor( pSock, Vendor, iSold )
When triggeredRuns on item after it has already been sold to the NPC vendor and has reached the NPC vendor's "bought"-backpack
NotesIf the item sold to the vendor stacks with items already there, the script will run on the entire stack, not just the one item specifically sold!
PurposeTo allow greater control over what happens after specific items have been sold to NPCs.
Example of Usage
function onSoldToVendor( pSock, Vendor, iSold )
{
	var pUser = pSock.currentChar;
	pUser.TextMessage( "I sold an item ("+iSold.name+") to a vendor!" );
	Vendor.TextMessage( "I just bought an item from some random dude!" );
	return true;
}

 

onSkill
Prototype
function onSkill( objUsing, skillUsed, objType )
When triggeredwhen objUsing uses skill skillUsed. objUsing's script is activated.
NotesobjType == 0 indicates objUsing is a character
objType == 1 indicates objUsing is an item
PurposeComplements the use of current skill code. Fires before any existing usage code kicks in.
Example of Usage
function onSkill( objUsing, skillUsed, objType )
{
	switch( skillUsed )
	{
	case 0:
		objUsing.TextMessage("Time to do some alchemy work!");
		break;
	case 1:
		objUsing.TextMessage("Now using Anatomy skill!");
		break;
	case 2:
		objUsing.TextMessage("Animal Lore usage Enabled!");
		break;
	//case etc.:
	}
}

 

onSkillChange
Prototype
function onSkillChange( pPlayer, skill )
When triggeredThis is fired if onSkillLoss isn't defined for skill loss, or onSkillGain isn't defined for skill gain.
Notes 
PurposeAllows you to take action when your skill level changes
Example of Usage
function onSkillChange( pPlayer, skill )
{
	pPlayer.TextMessage( pPlayer, "Oh dear, my skill's changed" );
}

 

onSkillCheck
Prototype
function onSkillCheck( pUser, skillID, lowSkill, highSkill )
When triggeredTriggers for character with event attached when a skillcheck is performed
Notes Does not currently reflect the result of the skill-check, nor allow overriding the hardcoded skillcheck.
PurposeFor taking additional action when skillchecks are performed.
Example of Usage
function onSkillCheck( pUser, skillID, lowSkill, highSkill )
{
	pUser.TextMessage( "A skillcheck is being done for skill with ID " + skillID + "!" );
}

 

onSkillGain
Prototype
function onSkillGain( pPlayer, skill )
When triggeredwhen pPlayer gains in skill skill
Notes 
PurposeFor taking actions when you gain skill.
Example of Usage
function onSkillGain( pPlayer, skill )
{
	pPlayer.TextMessage("Wheee! I've gained some skill!");
}

 

onSkillLoss
Prototype
function onSkillLoss( pPlayer, skill )
When triggeredWhen pPlayer loses in skill skill
Notes 
PurposeFor doing something when you lose skill
Example of Usage
function onSkillLoss( pPlayer, skill )
{
	pPlayer.TextMessage( "Oh no, I've lost skill!" );
}

 

onSkillGump
Prototype
function onSkillGump( pUser )
When triggeredWhen pUser tries opening the skill-gump
Notes 
PurposeFor overriding the client's request to open the default skillgump
Example of Usage
function onSkillGump( pUser )
{
	pUser.SysMessage( "Overriding default skillgump, opening custom one instead..." );
	// Insert custom skillgump here!
}

 

onSpellGain
Prototype
function onSpellGain( spellBook, spellNum )
When triggeredTriggered for spellbooks when spells are added to them
Notes
PurposeTo allow overriding what happens when spells are added to spellbooks?
Example of Usage

 

onSpellLoss
Prototype
function onSpellLoss( spellBook, spellNum )
When triggeredTriggered for spellbooks when spells are removed from them
Notes
PurposeTo allow overriding what happens when spells are removed from spellbooks?
Example of Usage

 

onSnooped
Prototype
function onSnooped( pSnooped, pSnooping, bSuccess );
When triggeredWhen pSnooped snoops into pSnooping's pack.
NotesIf overridden, internal behaviour not executed. IE no calling for guards, no messages sent to snooper or snooped. bSuccess is true if successfully snooped, or false if not
PurposeTo allow for behavioural change on snooping behaviour.
Example of Usage
function onSnooped( pSnooped, pSnooping, bSuccess )
{
	pSnooped.TextMessage( "Oi! You! Stop snooping!" );
}

 

onSpeech
Prototype
function onSpeech( strSaid, pTalking, pTalkingTo )
When triggeredWhen pTalking says strSaid to pTalkingTo. pTalkingTo's script is activated. Can also trigger for items with script and this event attached, if ITEMSDETECTSPEECH is enabled in UOX.INI.
Notes
PurposeGreatly improve the speech handling capabilities
Example of Usage
function onSpeech( strSaid, pTalking, pTalkingTo )
{
	pTalkingTo.TextMessage( strSaid );
}
// This is a simple mimic NPC.  Everything that someone says to it is quoted back verbatim

 

onSpeechInput
Prototype
function onSpeechInput(pUser, pItem, pSpeech, pSpeechID)
When triggeredWhen the SpeechInput method is executed
Notes
PurposeTo allow action after speech-input has been requested.
Example of Usage
function onUseChecked( pUser, iUsed)
{
	pUser.SysMessage( "What do you want to rename this item to:" );
	pUser.SpeechInput(1, iUsed);
}

function onSpeechInput(pUser, iUsed, pSpeech, pSpeechID)
{
	if(pSpeech == null || pSpeech == " ")
	{
		pUser.SysMessage( "You didn't type anything!" );
		return;
	}
    	switch(pSpeechID)
    	{
	case 1:
		pUser.SysMessage( "You rename the item to: "+pSpeech );
		iUsed.name = pSpeech;
		break;
	}
}

 

onSpellCast
Prototype
function onSpellCast( pUser, spellID )
When triggeredWhen any spell is cast
NotesReturn value table:
-2: use NORMAL non-JS casting
-1: CANCEL normal spellcasting
0->inf: Spell delay in ms
PurposeTo allow overriding spellcasting on a spell-per-spell basis
Example of Usage
function onSpellCast( pUser, spellID )
{
	if( spellID == 18 )
	{
		pUser.CustomTarget( 0, "What do you want to target with your fireball?" );
	        return -1;
	}
}

 

onSpellTarget
Prototype
function onSpellTarget( myTarget, pUser, spellID )
When triggeredWhen targeting something/someone with a spell
NotesmyTarget can be both items and characters
Purpose
Example of Usage
function onSpellTarget( myTarget, pUser, spellID )
{
	if( spellID == 18 )
	{
		myTarget.TextMessage( "AAAAAAaaaaaaa! I've been hit by a fireball!" );
	}
}

 

onSpellSuccess
Prototype
function onSpellSuccess( pUser, spellID )
When triggeredWhen successfully castin a spell
Notes
Purpose
Example of Usage
function onSpellSuccess( pUser, spellID )
{
	if( spellID == 18 )
	{
		pUser.TextMessage( "Yes! I managed to cast a fireball!" );
	}
}

 

onStatChange
Prototype
function onStatChange( pPlayer, stat )
When triggeredIf onStatLoss isn't defined, and stat went down, or if onStatGained isn't defined and stat went up
Notes
Purpose
Example of Usage
function onStatChange( pPlayer, stat )
{
	pPlayer.TextMessage("Whee my stats changed!");
}

 

onStatGained
Prototype
function onStatGained( pPlayer, stat )
When triggeredWhen pPlayer gains in stat stat
Notes
PurposeFor taking action when a person gains in a stat
Example of Usage
function onStatGained( pPlayer, stat )
{
	pPlayer.TextMessage("Whee I gained some stat!");
}

 

onStatLoss
Prototype
function onStatLoss( pPlayer, stat )
When triggeredWhen pPlayer loses in stat stat
Notes
PurposeFor taking action when a person loses in a stat
Example of Usage
function onStatLoss( pPlayer, stat )
{
	pPlayer.TextMessage("Awww I lost some stats.");
}

 

onSteal
Prototype
function onSteal( thief, objStolen )
When triggeredWhen objStolen is stolen, objStolen's script is activated
NotesWorks, but gives a console error: ERROR: Chars[-1] referenced is invalid. Crash averted!
PurposeSpecialization of stealing.
Example of Usage
function onSteal( thief, objStolen )
{
	thief.SysMessage( "You attempt to steal the "+objStolen.name );
	ConsoleMessage( objStolen.name+" has been attempted stolen!" );

}

 

onStolenFrom
Prototype
function onStolenFrom( pThief, pVictim, iStolen );
When triggeredWhen the player pThief steals the item iStolen from the character pVictim
Notes
PurposeTo allow for response when items are stolen from a player.
Example of Usage
function onStolenFrom( pThief, pVictim, iStolen )

{
TextMessage( pVictim, "Hey you, get your hands off my banana!" );
Attack( pVictim, pThief );
YellMessage( pVictim, "GUARDS!!!!!!!" );
}

 

onSwing
Prototype
function onSwing( iSwung, pSwinging, pSwingAt )
When triggeredWhen pSwinging swings iSwung at pSwingAt.
NotesEvent can trigger for either pSwinging character or iSwung item, depending on which object script is attached to
Purpose
Example of Usage
function onSwing( iSwung, pSwinging, pSwingAt )
{
	pSwinging.TextMessage( "Have at thee, knave!" );
}

 

onSystemSlice
Prototype
When triggered
Notes
Purpose
Example of Usage

 

onTalk
Prototype
function onTalk( pTalking, strSaid )
When triggeredWhen pTalking says strSaid. pTalking's script is activated
Notes
PurposeGreatly improve the speech handling capabilities
Example of Usage
function onTalk( myChar, mySpeech )
{
	if( mySpeech == "'dig")
		myChar.DoAction(11);
	else
		return true;
}
// This is a simple script that will make the character talking perform the digging animation upon saying "'dig".
// (Note: 'DIG won't be displayed as speech, since script intercepts the text before it is spoken out loud)
// If anything else is said, the script returns true so speech can proceed as normal.

 

onTempChange
Prototype
function onTempChange( object, temperature )
When triggeredTriggers for object (char/item) when temperature changes
Notes
PurposeTo allow reactions for characters/items when temperature changes
Example of Usage

 

onTimer
Prototype
function onTimer( tChar, timerID )
When triggeredWhen tempeffect 40 (StartTimer) duration has elapsed for timer timerID
Notes
PurposeTo be used for custom timer information for characters.
Example of Usage
function onTimer( tChar, timerID )

{
if( timerID == 0 )
{
DoStaticEffect( pCharacter, 0x376A, 9, 0, 0 ); // Make some sparkles!
}
}

 

onTransfer
Prototype
function onTransfer( iTransferred, pSrc, pTrg )
When triggeredWhen pSrc transfers iTransferred to pTrg
NotesiTransferred's script is activated
CURRENTLY BROKEN!!!
Purpose
Example of Usage
function onTransfer( iTransferred, pSrc, pTrg )
{
	pSrc.TextMessage("Whee I'm transferring this item to you, "+pTrg.name+"!");
	pTrg.TextMessage("Thank you, "+pSrc.name+"!");
}

 

onUnequip
Prototype
function onUnequip( pEquipper, iUnequipped )
When triggeredWhen pEquipper unequips iUnequipped
NotesiUnequipped's script is activated
Purpose
Example of Usage
function onUnequip( pUnequipper, iUnequipped )
{
	pUnequipper.StaticEffect( 0x376A, 9, 6 );
}

 

onUnknownTrigger
Prototype
When triggered
Notes
Purpose
Example of Usage

 

onUseBandageMacro
Prototype
function onUseBandageMacro( pSock, targChar, iUsed )
When triggeredWhen pSock uses iUsed on targChar.
NotesThis can be put in the global script (scriptID 0) to handle what should happen when a player attempts to use the Bandage Self macro in the client.
PurposeTo allow greater control of bandage self macro
Example of Usage
function onUseBandageMacro( pSock, targChar, bandageItem )
{
	targChar.TextMessage( "#0" );
	if( pSock && bandageItem && bandageItem.amount >= 1 )
	{
		var pUser = pSock.currentChar;
		TriggerEvent( 4000, "onUseCheckedTriggered", pUser, targChar, bandageItem );
	}
	return true;
}

...then, in scriptID 4000 - skill\healing.js, add this at the top of the file:

function onUseCheckedTriggered( pUser, targChar, iUsed )
{
	pUser.TextMessage( "#1" );
	if( pUser && iUsed && iUsed.isItem )
	{
		pUser.TextMessage( "#2" );

		var socket = pUser.socket;
		if( socket )
		{
			pUser.TextMessage( "#3" );

			if( pUser.skillsused.healing || pUser.skillsused.veterinary )
			{
				pUser.TextMessage( "#4" );
				socket.SysMessage( "You are too busy to do that." );
			}
			else if( socket.GetTimer( 0 ) <= GetCurrentClock() )
			{
				pUser.TextMessage( "#5" );
				socket.tempObj = iUsed;
				socket.SetTimer( 0, 5000 );
				onCallback1( socket, targChar );
			}
			else
			{
				pUser.TextMessage( "#6" );
				socket.SysMessage( GetDictionaryEntry( 473, socket.Language ) );
			}
		}
	}
	return true;
}

 

onUseChecked
Prototype
function onUseChecked( pUser, iUsed )
When triggeredWhen pUser uses iUsed.
Notesif return value from script is true, it continues on executing with hard coded implementation
if return value is false, then no hard code is executed
PurposeTo allow greater customization on using items.
Example of Usage
function onUseChecked( pUser, iUsed )
{
	var trgSock = pUser.socket;
	if(pUser.InRange( iUsed, 8 ))
		pUser.OpenBank(trgSock);
	return false;
}

 

onUseUnChecked
Prototype
function onUseUnChecked( pUser, iUsed )
When triggeredWhen pUser uses iUsed.
NotesUnlike the onUseChecked event this one runs without any hardcoded checks.
PurposeTo allow greater customization on using items.
Example of Usage
function onUseUnChecked( pUser, iUsed )
{
	var trgSock = pUser.socket;
	if(pUser.InRange( iUsed, 8 ))
		pUser.OpenBank(trgSock);
	return false;
}

 

onVirtueGumpPress
Prototype
function onVirtueGumpPress( mChar, tChar, buttonID )
When triggeredWhen Virtue gumps are pressed?
Notes
Purpose
Example of Usage

 

onWeatherChange
Prototype
function onWeatherChange( object, weatherType )
When triggeredTriggers for object (char/item) when weather changes
Notes
PurposeTo allow reactions for characters/items when weather changes
Example of Usage

 

OutOfRange
Prototype
function OutOfRange( pChar, objVanish, objType )
When triggeredWhen objVanish goes out of range of pChar
NotesobjType == 0 indicates objVanish is a character
objType == 1 indicates objVanish is an item
PurposeTo take actions based on when things go out of range. For instance, if you ran out of range of your attacker, you might decide to automatically try and hide.
Example of Usage
©Copyright 2000-2001 WWW.UOX3.NET (Daniel Stratton/Matthew Randall)