UPDATE Phase 3
1. Fixed Players Death Script
2. Added some range and invis checks to arena board
3. Monsters will auto in-gage in combat now.
UPDATE Phase 2
1. Added npc corpse will auto delete now if you win the fight.
2. Added Rounds Challenge.
3. Added If Player Dies him and his corpse will be teleported to the score board.
4. Added If Player Dies the Npc he is fighting will be deleted, and the hole arena is reset for next fighter.
5. Added at the top of the script you can set up the fights with the npcs of your choice. system comes with default setup.
6. Added Region Name is added to the gump where you setup the score board.
You need to add the score board to you dfn files then you need to add the two java script files.
I used Numbers 22402, 22403 and 22405 for this system so just use same numbers. there unused in uox3.
Now to setup it up you need to go in game and add the Arena Score Board, Double click it. click Settings and set the X Y Z of Player and then Set the X Y Z of Monster. this will control where monster spawns and where the player teleports to inside the arena. Only gms and Admin characters can see the settings button.
Once that is all set, register your character, once registered click single fight and click okay.
No one else can fight until the first player is done fighting.
Points are based on min hp and max hp this all can be changed to your liking.
[ArenaScoreBoard]
{
get=base_item
name=Arena Score Board
id=0x1E5E
COLOUR=1161
SCRIPT=22402
decay=0
}
{
get=base_item
name=Arena Score Board
id=0x1E5E
COLOUR=1161
SCRIPT=22402
decay=0
}
const npcListSingle = "weakundeadlist";
const npcRoundOne = "chicken";
const npcRoundTwo = "dog";
const npcRoundThree = "cat";
const npcRoundFour = "bird";
const npcRoundFive = "horse";
const npcRoundFinal = "sheep";
function onUseChecked( pUser, iUsed )
{
var pSock = pUser.socket;
// Check Make sure user is not invisible.
if( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
}
//Check if user is in range of Arena board
if( !iUsed.InRange( pUser, 2 ))
{
pUser.SysMessage( GetDictionaryEntry( 482, pSock.language )); //You need to be closer to use that.
return false;
}
ArenaRegisterGump( pUser, iUsed );
}
function ArenaRegisterGump( pUser, iUsed )
{
var socket = pUser.socket;
socket.tempObj = iUsed;
var scoreGump = new Gump;
var parentChar = iUsed.GetTag( "parentpUserSerial" + ( pUser.serial ).toString() );
var Fight = iUsed.GetTag( "FightinProgress" );
var pLocX = parseInt(iUsed.GetTag( "pLocX" ));
var pLocY = parseInt(iUsed.GetTag( "pLocY" ));
var mLocX = parseInt(iUsed.GetTag( "mLocX" ));
var mLocY = parseInt(iUsed.GetTag( "mLocY" ));
scoreGump.AddPage( 0 );
scoreGump.AddBackground( 0, 0, 455, 400, 9380 );
scoreGump.AddGump( 89, 38, 5578 );
scoreGump.AddGump( 286, 38, 5578 );
scoreGump.AddText( 158, 47, 0, iUsed.region.name );
scoreGump.AddText( 178, 67, 0, "Grand Arena" );
scoreGump.AddText( 150, 202, 0, "Single Fight" );
scoreGump.AddText( 150, 260, 0, "Challange Game" );
scoreGump.AddText( 150, 314, 0, "PVP" );
scoreGump.AddPageButton( 118, 203, 0xFB7, 0xFB9, 1 );
scoreGump.AddPageButton( 118, 260, 0xFB7, 0xFB9, 2 );
scoreGump.AddPageButton( 118, 314, 0xFB7, 0xFB9, 3 );
scoreGump.AddPicture( 60, 190, 8330 );
scoreGump.AddPicture( 60, 305, 9104 );
scoreGump.AddPicture( 60, 247, 8344 );
scoreGump.AddButton( 270, 203, 0xFB7, 0xFB9, 1, 0, 4 ); // Score Board
scoreGump.AddText( 305, 203, 0, "Score Board" );
if( pUser.isGM )
{
scoreGump.AddButton( 270, 230, 0xFB7, 0xFB9, 1, 0, 7 ); // Admin Gump
scoreGump.AddText( 305, 230, 0, "Settings" );
}
if( parseInt( parentChar ) != pUser.serial )
{
scoreGump.AddButton( 270, 260, 0xFB7, 0xFB9, 1, 0, 6 ); // Register
scoreGump.AddText( 305, 260, 0, "Register" );
}
scoreGump.AddButton( 346, 324, 241, 242, 1, 0, 0 ); // Cancel Button
if( pLocX == 0 && pLocY == 0 || mLocX == 0 && mLocY == 0 || pLocX == null && pLocY == null || mLocX == null && mLocY == null )
{
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "Arena has not been setup yet, Please page a gm to setup the Arena." );
}
else if( Fight == true )
{
scoreGump.AddHTMLGump(36, 111, 381, 64, false, false, "There is currenlty a fight in Progress" );
}
else
{
scoreGump.AddPage( 1 );
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "Test your skill vs a single monster. Right now the opponent is a random one." );
scoreGump.AddButton( 269, 324, 247, 248, 1, 0, 1 ); // Single Fight
scoreGump.AddText( 270, 290, 0, "Do you wish to accept?" );
scoreGump.AddPage( 2 );
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "In the challange game, you will fight through a series of monsters with progression in difficulty. Your score is based on how far you go along the chain." );
scoreGump.AddButton( 269, 324, 247, 248, 1, 0, 2 ); // Rounds
scoreGump.AddText( 270, 290, 0, "Do you wish to accept?" );
scoreGump.AddPage( 3 );
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "Fighting with another player is on a consensual base. Please target another player to invite him/her for a duel. Once he accepts your challange, you can start your fight inside the arena." );
scoreGump.AddButton( 269, 324, 247, 248, 1, 0, 0 ); // Player
scoreGump.AddText( 270, 290, 0, "Do you wish to accept?" );
}
scoreGump.Send( pUser );
scoreGump.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var pUser = pSock.currentChar;
var iUsed = pSock.tempObj;
var playerslocx = gumpData.getEdit(0);
var playerslocy = gumpData.getEdit(1);
var playerslocz = gumpData.getEdit(2);
var monstersslocx = gumpData.getEdit(3);
var monstersslocy = gumpData.getEdit(4);
var monstersslocz = gumpData.getEdit(5);
var pLocX = parseInt(iUsed.GetTag( "pLocX" ));
var pLocY = parseInt(iUsed.GetTag( "pLocY" ));
var pLocZ = parseInt(iUsed.GetTag( "pLocZ" ));
var mLocX = parseInt(iUsed.GetTag( "mLocX" ));
var mLocY = parseInt(iUsed.GetTag( "mLocY" ));
var mLocZ = parseInt(iUsed.GetTag( "mLocZ" ));
switch(pButton)
{
case 0:
break;
case 1: // Single Fight
if( pLocX == 0 && pLocY == 0 || mLocX == 0 && mLocY == 0 || pLocX == null && pLocY == null || mLocX == null && mLocY == null )
{
pUser.TextMessage("Arena has not been Setup" );
break;
}
else
{
iUsed.SetTag( "FightinProgress", true );
TeleportinArena( pUser, pLocX, pLocY, pLocZ );
SingleFight( pUser, iUsed, mLocX, mLocY, mLocZ );
break;
}
case 2: // Rounds
if( pLocX == 0 && pLocY == 0 || mLocX == 0 && mLocY == 0 || pLocX == null && pLocY == null || mLocX == null && mLocY == null )
{
pUser.TextMessage("Arena has not been Setup" );
break;
}
else
{
iUsed.SetTag( "FightinProgress", true );
iUsed.SetTag( "Levels", 1 );
iUsed.SetTag( "Rounds", true );
TeleportinArena( pUser, pLocX, pLocY, pLocZ );
RoundsFight( pUser, iUsed, mLocX, mLocY, mLocZ );
break;
}
case 3:
break;
case 4:
ArenaScoreBoardGump( pUser, iUsed );
break;
case 5:
ArenaRegisterGump( pUser, iUsed );
break;
case 6:
iUsed.SetTag( "parentpUserSerial" + ( pUser.serial ).toString(), ( pUser.serial ).toString() );
var newScoreEntry = ( pUser.serial ).toString() + "," + pUser.name.toString() + "," + "0";
SaveNewPlayerToScoreFile( pSock, iUsed, newScoreEntry );
ArenaRegisterGump( pUser, iUsed );
pUser.TextMessage("You are now Registered to Fight" );
iUsed.SetTag( "ArenaWins" + ( pUser.serial ).toString(), 0);
break;
case 7:
SettingsGump( pUser, iUsed );
break;
case 8:
iUsed.SetTag( "pLocX", playerslocx );
iUsed.SetTag( "pLocY", playerslocy );
iUsed.SetTag( "pLocZ", playerslocz );
iUsed.SetTag( "mLocX", monstersslocx );
iUsed.SetTag( "mLocY", monstersslocy );
iUsed.SetTag( "mLocZ", monstersslocz );
pUser.TextMessage("All Locations have been set." );
ArenaRegisterGump( pUser, iUsed );
break;
}
}
function LoadArenaScoresFromFile( socket, iUsed )
{
var mFile = new UOXCFile();
var fileName = "arena_score_data_" + ( iUsed.serial ).toString() + ".jsdata";
// Open arena score data file contained in arenascores subfolder of js/jsdata/ (true flag)
mFile.Open( fileName, "r", "arenascores", true );
if( mFile && mFile.Length() >= 0 )
{
// Read until we reach end of the file
while( !mFile.EOF() )
{
// Read a line of text from the file
var line = mFile.ReadUntil( "\n" );
if( line.length <= 1 || line == "" )
{
continue;
}
// Add each line to the array of arena score data stored on socket
socket.arenaScoreData.push( line );
}
// Close file and free up memory allocated by file object
mFile.Close();
// Free memory allocated by file object
mFile.Free();
return true;
}
// No file was loaded, return false
return false;
}
function SaveNewPlayerToScoreFile( pSock, iUsed, newScoreEntry )
{
var mFile = new UOXCFile();
var fileName = "arena_score_data_" + ( iUsed.serial ).toString() + ".jsdata";
// Open arena score data file contained in arenascores subfolder of js/jsdata/ (true flag) in Append mode ("a")
mFile.Open( fileName, "a", "arenascores", true );
if( mFile != null )
{
// Save new score entry to end of file
mFile.Write( newScoreEntry + "\n" );
mFile.Close();
mFile.Free();
return true;
}
// No file was saved, return false
return false;
}
function SaveArenaScoresToFile( socket, iUsed )
{
var mFile = new UOXCFile();
var fileName = "arena_score_data_" + ( iUsed.serial ).toString() + ".jsdata";
// Open arena score data file contained in arenascores subfolder of js/jsdata/ (true flag)
mFile.Open( fileName, "w", "arenascores", true );
if( mFile != null )
{
var scoreArray = socket.arenaScoreData;
var arrayLength = scoreArray.length;
for( var i = 0; i < arrayLength; i++ )
{
mFile.Write( scoreArray[i] + "\n" );
}
// Close file and free up memory allocated by file object
mFile.Close();
// Free memory allocated by file object
mFile.Free();
return true;
}
// No file was saved, return false
return false;
}
function SettingsGump( pUser, iUsed )
{
var socket = pUser.socket;
var scoreGump = new Gump;
scoreGump.AddPage(0);
scoreGump.AddBackground(0, 0, 340, 240, 9200);
scoreGump.AddText(5, 5, 152, "Settings of the Arena Please Enter All");
scoreGump.AddText(5, 20, 152, "Coords before hitting Okay");
scoreGump.AddCheckerTrans(90, 45, 201, 19); // Players Loc X
scoreGump.AddCheckerTrans(90, 75, 201, 19); // Players Loc Y
scoreGump.AddCheckerTrans(90, 105, 201, 19); // Players Loc Z
scoreGump.AddCheckerTrans(90, 150, 201, 19); // Monster Loc X
scoreGump.AddCheckerTrans(90, 180, 201, 19); // Monster Loc Y
scoreGump.AddCheckerTrans(90, 210, 201, 19); // Monster Loc Z
scoreGump.AddText(0, 45, 0, "Players Loc X");
scoreGump.AddText(0, 75, 0, "Players Loc Y");
scoreGump.AddText(0, 105, 0, "Players Loc Z");
scoreGump.AddText(0, 150, 0, "Monster Loc X");
scoreGump.AddText(0, 180, 0, "Monster Loc Y");
scoreGump.AddText(0, 210, 0, "Monster Loc Z");
scoreGump.AddTextEntry(90, 45, 200, 20, 2727, 0, 8, "0"); // Players Loc X
scoreGump.AddTextEntry(90, 75, 200, 20, 2727, 0, 9, "0"); // Players Loc Y
scoreGump.AddTextEntry(90, 105, 200, 20, 2727, 0, 10, "0"); // Players Loc Z
scoreGump.AddTextEntry(90, 150, 200, 20, 2727, 0, 11, "0"); // Monster Loc X
scoreGump.AddTextEntry(90, 180, 200, 20, 2727, 0, 12, "0"); // Monster Loc Y
scoreGump.AddTextEntry(90, 210, 200, 20, 2727, 0, 13, "0"); // Monster Loc Z
scoreGump.AddButton(293, 210, 2143, 2142, 1, 0, 8);
scoreGump.Send(pUser);
scoreGump.Free();
}
function SingleFight( pUser, iUsed, x, y, z )
{
if( !ValidateObject( pUser ) || !pUser.isChar || pUser.npc )
return false;
var useNpcList = true;
var spawnedFighter = SpawnNPC( npcListSingle, x, y, z, 0, 0, useNpcList );
spawnedFighter.SetTag( "parentItemSerial", ( iUsed.serial ).toString() );
spawnedFighter.SetTag( "parentpUserSerial", ( pUser.serial ).toString() );
spawnedFighter.fleeAt = 1;
spawnedFighter.reAttackAt = 1;
spawnedFighter.InitiateCombat( pUser );
spawnedFighter.AddScriptTrigger( 22403 );
// Death of Player info needs set.
pUser.SetTag( "parentItemSerial", ( iUsed.serial ).toString() );
pUser.AddScriptTrigger( 22405 );
}
function RoundsFight( pUser, iUsed, x, y, z )
{
if( !ValidateObject( pUser ) || !pUser.isChar || pUser.npc )
return false;
var iRound = iUsed.GetTag( "Rounds" );
var iLevel = iUsed.GetTag( "Levels" );
if( iRound == true )
{
switch(iLevel)
{
case 1:
var spawnedFighter = SpawnNPC( npcRoundOne, x, y, z, 0, 0 );
break;
case 2:
var spawnedFighter = SpawnNPC( npcRoundTwo, x, y, z, 0, 0 );
break;
case 3:
var spawnedFighter = SpawnNPC( npcRoundThree, x, y, z, 0, 0 );
break;
case 4:
var spawnedFighter = SpawnNPC( npcRoundFour, x, y, z, 0, 0 );
break;
case 5:
var spawnedFighter = SpawnNPC( npcRoundFive, x, y, z, 0, 0 );
break;
case 6:// Final round
var spawnedFighter = SpawnNPC( npcRoundFinal, x, y, z, 0, 0 );
break;
}
spawnedFighter.SetTag( "parentItemSerial", ( iUsed.serial ).toString() );
spawnedFighter.SetTag( "parentpUserSerial", ( pUser.serial ).toString() );
spawnedFighter.fleeAt = 1;
spawnedFighter.reAttackAt = 1;
spawnedFighter.InitiateCombat( pUser );
spawnedFighter.AddScriptTrigger( 22403 );
}
}
function TeleportinArena( pUser, x, y, z )
{
// Teleport player's pets to Arena
var petList = pUser.GetPetList();
for( var i = 0; i < petList.length; i++ )
{
var tempPet = petList[i];
if( ValidateObject( tempPet ) && tempPet.InRange( pUser, 24 ))
{
tempPet.Teleport( x, y, z );
tempPet.Follow( pUser );
}
}
// Teleport player to Arena
pUser.Teleport( x, y, z );
}
function ArenaScoreBoardGump( pUser, iUsed )
{
var socket = pUser.socket;
var scoreGump = new Gump;
var y = 45;
scoreGump.AddPage(0);
scoreGump.AddBackground(0, 0, 340, 240, 9200);
scoreGump.AddText(80, 10, 152, "Arena Score Board (Top 5)");
scoreGump.AddText(60, y, 0, "Player Name");
scoreGump.AddText(190, y, 0, "Score");
var arenaWins = iUsed.GetTag( "ArenaWins" + ( pUser.serial ).toString() );
var newScore = arenaWins; // This would be gotten from elsewhere, of course
socket.arenaScoreData = new Array(); // Store temporary array on socket
if( LoadArenaScoresFromFile( socket, iUsed ))
{
// Handle score data here, modify score, etc
for( var i = 0; i < socket.arenaScoreData.length; i++ )
{
// If first column of array matches player's serial...
var arrayData = socket.arenaScoreData[i].split( "," );
if( arrayData[0] && arrayData[0] == pUser.serial )
{
// ...then update second column with player's new score
arrayData[2] = newScore;
socket.arenaScoreData[i] = arrayData[0] + "," + arrayData[1] + "," + arrayData[2];
break;
}
}
// Write score data back to file
SaveArenaScoresToFile( socket, iUsed );
// Next sort the scoreArray array by highest score
socket.arenaScoreData.sort( CompareSecondColumn );
// Then loop through the SORTED array again, to and pop out the names of top 5 players in gump
var topPlayers = 5;
var hue = 0
for( var i = 0; i < topPlayers ; i++ )
{
if( !socket.arenaScoreData[i] )
break
var arrayTopData = socket.arenaScoreData[i].split( "," );
if( arrayTopData[0] )
{
var myPlayerName = arrayTopData[1];
var myScore = arrayTopData[2];
if(i == 0)
{
hue = 1161;
}
else
{
hue = 0x480;
}
y += 25;
scoreGump.AddText(60, y + i, hue, myPlayerName.toString() );
scoreGump.AddText(190, y + i, hue, myScore.toString() );
}
}
}
else
{
pUser.TextMessage("Page a Gm this is a error");
}
scoreGump.AddButton(280, 210, 2143, 2142, 1, 0, 5);
scoreGump.Send(pUser);
scoreGump.Free();
}
function CompareSecondColumn( a, b )
{
if( a.split(",")[2] === b.split(",")[2] )
{
return 0;
}
else
{
return ( a.split(",")[2] > b.split(",")[2]) ? -1 : 1;
}
}
const npcRoundOne = "chicken";
const npcRoundTwo = "dog";
const npcRoundThree = "cat";
const npcRoundFour = "bird";
const npcRoundFive = "horse";
const npcRoundFinal = "sheep";
function onUseChecked( pUser, iUsed )
{
var pSock = pUser.socket;
// Check Make sure user is not invisible.
if( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
}
//Check if user is in range of Arena board
if( !iUsed.InRange( pUser, 2 ))
{
pUser.SysMessage( GetDictionaryEntry( 482, pSock.language )); //You need to be closer to use that.
return false;
}
ArenaRegisterGump( pUser, iUsed );
}
function ArenaRegisterGump( pUser, iUsed )
{
var socket = pUser.socket;
socket.tempObj = iUsed;
var scoreGump = new Gump;
var parentChar = iUsed.GetTag( "parentpUserSerial" + ( pUser.serial ).toString() );
var Fight = iUsed.GetTag( "FightinProgress" );
var pLocX = parseInt(iUsed.GetTag( "pLocX" ));
var pLocY = parseInt(iUsed.GetTag( "pLocY" ));
var mLocX = parseInt(iUsed.GetTag( "mLocX" ));
var mLocY = parseInt(iUsed.GetTag( "mLocY" ));
scoreGump.AddPage( 0 );
scoreGump.AddBackground( 0, 0, 455, 400, 9380 );
scoreGump.AddGump( 89, 38, 5578 );
scoreGump.AddGump( 286, 38, 5578 );
scoreGump.AddText( 158, 47, 0, iUsed.region.name );
scoreGump.AddText( 178, 67, 0, "Grand Arena" );
scoreGump.AddText( 150, 202, 0, "Single Fight" );
scoreGump.AddText( 150, 260, 0, "Challange Game" );
scoreGump.AddText( 150, 314, 0, "PVP" );
scoreGump.AddPageButton( 118, 203, 0xFB7, 0xFB9, 1 );
scoreGump.AddPageButton( 118, 260, 0xFB7, 0xFB9, 2 );
scoreGump.AddPageButton( 118, 314, 0xFB7, 0xFB9, 3 );
scoreGump.AddPicture( 60, 190, 8330 );
scoreGump.AddPicture( 60, 305, 9104 );
scoreGump.AddPicture( 60, 247, 8344 );
scoreGump.AddButton( 270, 203, 0xFB7, 0xFB9, 1, 0, 4 ); // Score Board
scoreGump.AddText( 305, 203, 0, "Score Board" );
if( pUser.isGM )
{
scoreGump.AddButton( 270, 230, 0xFB7, 0xFB9, 1, 0, 7 ); // Admin Gump
scoreGump.AddText( 305, 230, 0, "Settings" );
}
if( parseInt( parentChar ) != pUser.serial )
{
scoreGump.AddButton( 270, 260, 0xFB7, 0xFB9, 1, 0, 6 ); // Register
scoreGump.AddText( 305, 260, 0, "Register" );
}
scoreGump.AddButton( 346, 324, 241, 242, 1, 0, 0 ); // Cancel Button
if( pLocX == 0 && pLocY == 0 || mLocX == 0 && mLocY == 0 || pLocX == null && pLocY == null || mLocX == null && mLocY == null )
{
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "Arena has not been setup yet, Please page a gm to setup the Arena." );
}
else if( Fight == true )
{
scoreGump.AddHTMLGump(36, 111, 381, 64, false, false, "There is currenlty a fight in Progress" );
}
else
{
scoreGump.AddPage( 1 );
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "Test your skill vs a single monster. Right now the opponent is a random one." );
scoreGump.AddButton( 269, 324, 247, 248, 1, 0, 1 ); // Single Fight
scoreGump.AddText( 270, 290, 0, "Do you wish to accept?" );
scoreGump.AddPage( 2 );
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "In the challange game, you will fight through a series of monsters with progression in difficulty. Your score is based on how far you go along the chain." );
scoreGump.AddButton( 269, 324, 247, 248, 1, 0, 2 ); // Rounds
scoreGump.AddText( 270, 290, 0, "Do you wish to accept?" );
scoreGump.AddPage( 3 );
scoreGump.AddHTMLGump( 36, 111, 381, 64, false, false, "Fighting with another player is on a consensual base. Please target another player to invite him/her for a duel. Once he accepts your challange, you can start your fight inside the arena." );
scoreGump.AddButton( 269, 324, 247, 248, 1, 0, 0 ); // Player
scoreGump.AddText( 270, 290, 0, "Do you wish to accept?" );
}
scoreGump.Send( pUser );
scoreGump.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var pUser = pSock.currentChar;
var iUsed = pSock.tempObj;
var playerslocx = gumpData.getEdit(0);
var playerslocy = gumpData.getEdit(1);
var playerslocz = gumpData.getEdit(2);
var monstersslocx = gumpData.getEdit(3);
var monstersslocy = gumpData.getEdit(4);
var monstersslocz = gumpData.getEdit(5);
var pLocX = parseInt(iUsed.GetTag( "pLocX" ));
var pLocY = parseInt(iUsed.GetTag( "pLocY" ));
var pLocZ = parseInt(iUsed.GetTag( "pLocZ" ));
var mLocX = parseInt(iUsed.GetTag( "mLocX" ));
var mLocY = parseInt(iUsed.GetTag( "mLocY" ));
var mLocZ = parseInt(iUsed.GetTag( "mLocZ" ));
switch(pButton)
{
case 0:
break;
case 1: // Single Fight
if( pLocX == 0 && pLocY == 0 || mLocX == 0 && mLocY == 0 || pLocX == null && pLocY == null || mLocX == null && mLocY == null )
{
pUser.TextMessage("Arena has not been Setup" );
break;
}
else
{
iUsed.SetTag( "FightinProgress", true );
TeleportinArena( pUser, pLocX, pLocY, pLocZ );
SingleFight( pUser, iUsed, mLocX, mLocY, mLocZ );
break;
}
case 2: // Rounds
if( pLocX == 0 && pLocY == 0 || mLocX == 0 && mLocY == 0 || pLocX == null && pLocY == null || mLocX == null && mLocY == null )
{
pUser.TextMessage("Arena has not been Setup" );
break;
}
else
{
iUsed.SetTag( "FightinProgress", true );
iUsed.SetTag( "Levels", 1 );
iUsed.SetTag( "Rounds", true );
TeleportinArena( pUser, pLocX, pLocY, pLocZ );
RoundsFight( pUser, iUsed, mLocX, mLocY, mLocZ );
break;
}
case 3:
break;
case 4:
ArenaScoreBoardGump( pUser, iUsed );
break;
case 5:
ArenaRegisterGump( pUser, iUsed );
break;
case 6:
iUsed.SetTag( "parentpUserSerial" + ( pUser.serial ).toString(), ( pUser.serial ).toString() );
var newScoreEntry = ( pUser.serial ).toString() + "," + pUser.name.toString() + "," + "0";
SaveNewPlayerToScoreFile( pSock, iUsed, newScoreEntry );
ArenaRegisterGump( pUser, iUsed );
pUser.TextMessage("You are now Registered to Fight" );
iUsed.SetTag( "ArenaWins" + ( pUser.serial ).toString(), 0);
break;
case 7:
SettingsGump( pUser, iUsed );
break;
case 8:
iUsed.SetTag( "pLocX", playerslocx );
iUsed.SetTag( "pLocY", playerslocy );
iUsed.SetTag( "pLocZ", playerslocz );
iUsed.SetTag( "mLocX", monstersslocx );
iUsed.SetTag( "mLocY", monstersslocy );
iUsed.SetTag( "mLocZ", monstersslocz );
pUser.TextMessage("All Locations have been set." );
ArenaRegisterGump( pUser, iUsed );
break;
}
}
function LoadArenaScoresFromFile( socket, iUsed )
{
var mFile = new UOXCFile();
var fileName = "arena_score_data_" + ( iUsed.serial ).toString() + ".jsdata";
// Open arena score data file contained in arenascores subfolder of js/jsdata/ (true flag)
mFile.Open( fileName, "r", "arenascores", true );
if( mFile && mFile.Length() >= 0 )
{
// Read until we reach end of the file
while( !mFile.EOF() )
{
// Read a line of text from the file
var line = mFile.ReadUntil( "\n" );
if( line.length <= 1 || line == "" )
{
continue;
}
// Add each line to the array of arena score data stored on socket
socket.arenaScoreData.push( line );
}
// Close file and free up memory allocated by file object
mFile.Close();
// Free memory allocated by file object
mFile.Free();
return true;
}
// No file was loaded, return false
return false;
}
function SaveNewPlayerToScoreFile( pSock, iUsed, newScoreEntry )
{
var mFile = new UOXCFile();
var fileName = "arena_score_data_" + ( iUsed.serial ).toString() + ".jsdata";
// Open arena score data file contained in arenascores subfolder of js/jsdata/ (true flag) in Append mode ("a")
mFile.Open( fileName, "a", "arenascores", true );
if( mFile != null )
{
// Save new score entry to end of file
mFile.Write( newScoreEntry + "\n" );
mFile.Close();
mFile.Free();
return true;
}
// No file was saved, return false
return false;
}
function SaveArenaScoresToFile( socket, iUsed )
{
var mFile = new UOXCFile();
var fileName = "arena_score_data_" + ( iUsed.serial ).toString() + ".jsdata";
// Open arena score data file contained in arenascores subfolder of js/jsdata/ (true flag)
mFile.Open( fileName, "w", "arenascores", true );
if( mFile != null )
{
var scoreArray = socket.arenaScoreData;
var arrayLength = scoreArray.length;
for( var i = 0; i < arrayLength; i++ )
{
mFile.Write( scoreArray[i] + "\n" );
}
// Close file and free up memory allocated by file object
mFile.Close();
// Free memory allocated by file object
mFile.Free();
return true;
}
// No file was saved, return false
return false;
}
function SettingsGump( pUser, iUsed )
{
var socket = pUser.socket;
var scoreGump = new Gump;
scoreGump.AddPage(0);
scoreGump.AddBackground(0, 0, 340, 240, 9200);
scoreGump.AddText(5, 5, 152, "Settings of the Arena Please Enter All");
scoreGump.AddText(5, 20, 152, "Coords before hitting Okay");
scoreGump.AddCheckerTrans(90, 45, 201, 19); // Players Loc X
scoreGump.AddCheckerTrans(90, 75, 201, 19); // Players Loc Y
scoreGump.AddCheckerTrans(90, 105, 201, 19); // Players Loc Z
scoreGump.AddCheckerTrans(90, 150, 201, 19); // Monster Loc X
scoreGump.AddCheckerTrans(90, 180, 201, 19); // Monster Loc Y
scoreGump.AddCheckerTrans(90, 210, 201, 19); // Monster Loc Z
scoreGump.AddText(0, 45, 0, "Players Loc X");
scoreGump.AddText(0, 75, 0, "Players Loc Y");
scoreGump.AddText(0, 105, 0, "Players Loc Z");
scoreGump.AddText(0, 150, 0, "Monster Loc X");
scoreGump.AddText(0, 180, 0, "Monster Loc Y");
scoreGump.AddText(0, 210, 0, "Monster Loc Z");
scoreGump.AddTextEntry(90, 45, 200, 20, 2727, 0, 8, "0"); // Players Loc X
scoreGump.AddTextEntry(90, 75, 200, 20, 2727, 0, 9, "0"); // Players Loc Y
scoreGump.AddTextEntry(90, 105, 200, 20, 2727, 0, 10, "0"); // Players Loc Z
scoreGump.AddTextEntry(90, 150, 200, 20, 2727, 0, 11, "0"); // Monster Loc X
scoreGump.AddTextEntry(90, 180, 200, 20, 2727, 0, 12, "0"); // Monster Loc Y
scoreGump.AddTextEntry(90, 210, 200, 20, 2727, 0, 13, "0"); // Monster Loc Z
scoreGump.AddButton(293, 210, 2143, 2142, 1, 0, 8);
scoreGump.Send(pUser);
scoreGump.Free();
}
function SingleFight( pUser, iUsed, x, y, z )
{
if( !ValidateObject( pUser ) || !pUser.isChar || pUser.npc )
return false;
var useNpcList = true;
var spawnedFighter = SpawnNPC( npcListSingle, x, y, z, 0, 0, useNpcList );
spawnedFighter.SetTag( "parentItemSerial", ( iUsed.serial ).toString() );
spawnedFighter.SetTag( "parentpUserSerial", ( pUser.serial ).toString() );
spawnedFighter.fleeAt = 1;
spawnedFighter.reAttackAt = 1;
spawnedFighter.InitiateCombat( pUser );
spawnedFighter.AddScriptTrigger( 22403 );
// Death of Player info needs set.
pUser.SetTag( "parentItemSerial", ( iUsed.serial ).toString() );
pUser.AddScriptTrigger( 22405 );
}
function RoundsFight( pUser, iUsed, x, y, z )
{
if( !ValidateObject( pUser ) || !pUser.isChar || pUser.npc )
return false;
var iRound = iUsed.GetTag( "Rounds" );
var iLevel = iUsed.GetTag( "Levels" );
if( iRound == true )
{
switch(iLevel)
{
case 1:
var spawnedFighter = SpawnNPC( npcRoundOne, x, y, z, 0, 0 );
break;
case 2:
var spawnedFighter = SpawnNPC( npcRoundTwo, x, y, z, 0, 0 );
break;
case 3:
var spawnedFighter = SpawnNPC( npcRoundThree, x, y, z, 0, 0 );
break;
case 4:
var spawnedFighter = SpawnNPC( npcRoundFour, x, y, z, 0, 0 );
break;
case 5:
var spawnedFighter = SpawnNPC( npcRoundFive, x, y, z, 0, 0 );
break;
case 6:// Final round
var spawnedFighter = SpawnNPC( npcRoundFinal, x, y, z, 0, 0 );
break;
}
spawnedFighter.SetTag( "parentItemSerial", ( iUsed.serial ).toString() );
spawnedFighter.SetTag( "parentpUserSerial", ( pUser.serial ).toString() );
spawnedFighter.fleeAt = 1;
spawnedFighter.reAttackAt = 1;
spawnedFighter.InitiateCombat( pUser );
spawnedFighter.AddScriptTrigger( 22403 );
}
}
function TeleportinArena( pUser, x, y, z )
{
// Teleport player's pets to Arena
var petList = pUser.GetPetList();
for( var i = 0; i < petList.length; i++ )
{
var tempPet = petList[i];
if( ValidateObject( tempPet ) && tempPet.InRange( pUser, 24 ))
{
tempPet.Teleport( x, y, z );
tempPet.Follow( pUser );
}
}
// Teleport player to Arena
pUser.Teleport( x, y, z );
}
function ArenaScoreBoardGump( pUser, iUsed )
{
var socket = pUser.socket;
var scoreGump = new Gump;
var y = 45;
scoreGump.AddPage(0);
scoreGump.AddBackground(0, 0, 340, 240, 9200);
scoreGump.AddText(80, 10, 152, "Arena Score Board (Top 5)");
scoreGump.AddText(60, y, 0, "Player Name");
scoreGump.AddText(190, y, 0, "Score");
var arenaWins = iUsed.GetTag( "ArenaWins" + ( pUser.serial ).toString() );
var newScore = arenaWins; // This would be gotten from elsewhere, of course
socket.arenaScoreData = new Array(); // Store temporary array on socket
if( LoadArenaScoresFromFile( socket, iUsed ))
{
// Handle score data here, modify score, etc
for( var i = 0; i < socket.arenaScoreData.length; i++ )
{
// If first column of array matches player's serial...
var arrayData = socket.arenaScoreData[i].split( "," );
if( arrayData[0] && arrayData[0] == pUser.serial )
{
// ...then update second column with player's new score
arrayData[2] = newScore;
socket.arenaScoreData[i] = arrayData[0] + "," + arrayData[1] + "," + arrayData[2];
break;
}
}
// Write score data back to file
SaveArenaScoresToFile( socket, iUsed );
// Next sort the scoreArray array by highest score
socket.arenaScoreData.sort( CompareSecondColumn );
// Then loop through the SORTED array again, to and pop out the names of top 5 players in gump
var topPlayers = 5;
var hue = 0
for( var i = 0; i < topPlayers ; i++ )
{
if( !socket.arenaScoreData[i] )
break
var arrayTopData = socket.arenaScoreData[i].split( "," );
if( arrayTopData[0] )
{
var myPlayerName = arrayTopData[1];
var myScore = arrayTopData[2];
if(i == 0)
{
hue = 1161;
}
else
{
hue = 0x480;
}
y += 25;
scoreGump.AddText(60, y + i, hue, myPlayerName.toString() );
scoreGump.AddText(190, y + i, hue, myScore.toString() );
}
}
}
else
{
pUser.TextMessage("Page a Gm this is a error");
}
scoreGump.AddButton(280, 210, 2143, 2142, 1, 0, 5);
scoreGump.Send(pUser);
scoreGump.Free();
}
function CompareSecondColumn( a, b )
{
if( a.split(",")[2] === b.split(",")[2] )
{
return 0;
}
else
{
return ( a.split(",")[2] > b.split(",")[2]) ? -1 : 1;
}
}
function onDeath( myNPC, iCorpse)
{
var parentItem = CalcItemFromSer( parseInt( myNPC.GetTag( "parentItemSerial" )));
var parentChar = CalcCharFromSer( parseInt( myNPC.GetTag( "parentpUserSerial" )));
var arenaWins = parentItem.GetTag( "ArenaWins" + ( parentChar.serial ).toString() );
var pointgainmin = Math.min(myNPC.maxhp * 2);
var pointgainmax = Math.max(myNPC.maxhp * 4);
var pointsgain = RandomNumber(pointgainmin, pointgainmax);
var iRound = parentItem.GetTag( "Rounds" );
var iLevel = parentItem.GetTag( "Levels" );
var mLocX = parseInt(parentItem.GetTag( "mLocX" ));
var mLocY = parseInt(parentItem.GetTag( "mLocY" ));
var mLocZ = parseInt(parentItem.GetTag( "mLocZ" ));
if( ValidateObject( parentItem ))
{
parentItem.SetTag( "ArenaWins" + ( parentChar.serial ).toString(), arenaWins + pointsgain );
parentChar.TextMessage( "You scored " + pointsgain + " points and won the fight." );
if( iRound == true )
{
switch(iLevel)
{
case 1:
parentItem.SetTag( "Levels", iLevel + 1);
parentChar.SysMessage( "You Moved to the next Round" );
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 2:
parentChar.SysMessage( "ROUND 2" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 3:
parentChar.SysMessage( "ROUND 3" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 4:
parentChar.SysMessage( "ROUND 4" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 5:
parentChar.SysMessage( "FINAL ROUND" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 6:
parentItem.SetTag( "Levels", 0);
parentItem.SetTag( "Rounds", false);
parentItem.SetTag( "FightinProgress", false );
parentChar.SysMessage( "You been teleported back to the Arena Board." );
parentChar.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
parentChar.SetTag( "parentItemSerial", null );
parentChar.RemoveScriptTrigger( 22405 );
iCorpse.Delete();
break;
}
}
else
{
parentItem.SetTag( "FightinProgress", false );
parentChar.SysMessage( "You been teleported back to the Arena Board." );
parentChar.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
parentChar.SetTag( "parentItemSerial", null );
parentChar.RemoveScriptTrigger( 22405 );
iCorpse.Delete();
}
}
}
{
var parentItem = CalcItemFromSer( parseInt( myNPC.GetTag( "parentItemSerial" )));
var parentChar = CalcCharFromSer( parseInt( myNPC.GetTag( "parentpUserSerial" )));
var arenaWins = parentItem.GetTag( "ArenaWins" + ( parentChar.serial ).toString() );
var pointgainmin = Math.min(myNPC.maxhp * 2);
var pointgainmax = Math.max(myNPC.maxhp * 4);
var pointsgain = RandomNumber(pointgainmin, pointgainmax);
var iRound = parentItem.GetTag( "Rounds" );
var iLevel = parentItem.GetTag( "Levels" );
var mLocX = parseInt(parentItem.GetTag( "mLocX" ));
var mLocY = parseInt(parentItem.GetTag( "mLocY" ));
var mLocZ = parseInt(parentItem.GetTag( "mLocZ" ));
if( ValidateObject( parentItem ))
{
parentItem.SetTag( "ArenaWins" + ( parentChar.serial ).toString(), arenaWins + pointsgain );
parentChar.TextMessage( "You scored " + pointsgain + " points and won the fight." );
if( iRound == true )
{
switch(iLevel)
{
case 1:
parentItem.SetTag( "Levels", iLevel + 1);
parentChar.SysMessage( "You Moved to the next Round" );
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 2:
parentChar.SysMessage( "ROUND 2" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 3:
parentChar.SysMessage( "ROUND 3" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 4:
parentChar.SysMessage( "ROUND 4" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 5:
parentChar.SysMessage( "FINAL ROUND" );
parentItem.SetTag( "Levels", iLevel + 1);
TriggerEvent( 22402, "RoundsFight", parentChar, parentItem, mLocX, mLocY, mLocZ );
iCorpse.Delete();
break;
case 6:
parentItem.SetTag( "Levels", 0);
parentItem.SetTag( "Rounds", false);
parentItem.SetTag( "FightinProgress", false );
parentChar.SysMessage( "You been teleported back to the Arena Board." );
parentChar.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
parentChar.SetTag( "parentItemSerial", null );
parentChar.RemoveScriptTrigger( 22405 );
iCorpse.Delete();
break;
}
}
else
{
parentItem.SetTag( "FightinProgress", false );
parentChar.SysMessage( "You been teleported back to the Arena Board." );
parentChar.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
parentChar.SetTag( "parentItemSerial", null );
parentChar.RemoveScriptTrigger( 22405 );
iCorpse.Delete();
}
}
}
function onDeath( myPlayer, iCorpse)
{
var parentItem = CalcItemFromSer( parseInt( myPlayer.GetTag( "parentItemSerial" )));
if( ValidateObject( parentItem ))
{
myPlayer.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
myPlayer.SysMessage( "Your corpse and you has been teleported to score board" );
iCorpse.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
parentItem.SetTag( "FightinProgress", false );
parentItem.SetTag( "Levels", 0);
parentItem.SetTag( "Rounds", false);
myPlayer.SetTag( "parentItemSerial", null );
myPlayer.RemoveScriptTrigger( 22405 );
myPlayer.Refresh();
}
}
function onDeathBlow( pDead, pKiller )
{
if( ValidateObject( pKiller ))
{
// Deletes the npc after you die.
pKiller.Delete();
return true;
}
}
{
var parentItem = CalcItemFromSer( parseInt( myPlayer.GetTag( "parentItemSerial" )));
if( ValidateObject( parentItem ))
{
myPlayer.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
myPlayer.SysMessage( "Your corpse and you has been teleported to score board" );
iCorpse.Teleport( parentItem.x, parentItem.y + 1, parentItem.z );
parentItem.SetTag( "FightinProgress", false );
parentItem.SetTag( "Levels", 0);
parentItem.SetTag( "Rounds", false);
myPlayer.SetTag( "parentItemSerial", null );
myPlayer.RemoveScriptTrigger( 22405 );
myPlayer.Refresh();
}
}
function onDeathBlow( pDead, pKiller )
{
if( ValidateObject( pKiller ))
{
// Deletes the npc after you die.
pKiller.Delete();
return true;
}
}