UO New Lagacy Taming Addition
Posted: Tue Aug 27, 2024 2:02 am
Firs you need to open your jse_fileassocation.scp and add this two lines
50300=custom/TamingKnowledge.js
50301=custom/BestiaryBooks.js
Now in the custom folder add these two scripts
Now Open your taming.js file that is in the skills folder
before the function function onCallback0( pSock, ourObj )
add this code
Find this line of code
else if (!hasBeenOwner && skillToTame > pUser.skills.taming)
{
pSock.SysMessage(GetDictionaryEntry(2398, pLanguage)); // You are not skilled enough to tame that creature
return;
}
Under that add this line of code
save and close it.
open your animallorejs file
find this line of code
if( pUser.CheckSkill( 2, 0, 1000 ))
{
add this after the {
now go down just a hair and find this line of code
AnimalLoreGump.AddGump( 40, 258, 0x82B );
and add this
Now add this to your dfn files
All you have to do is list the npc sectionID in the taming list and it will look to see if that npc requires knowledge if it is listed if you do not list it will not require knowledge.
and now the book to tame dragons is setup
there is right now just 5 books you can create but if you know what your doing you could make more.
50300=custom/TamingKnowledge.js
50301=custom/BestiaryBooks.js
Now in the custom folder add these two scripts
function AddTamingKnowledge(pUser, iUsed, knowledgeID, bestiaryBookSectionID )
{
var name = "";
switch (knowledgeID)
{
case 1: name = "Dragons"; break;
case 2: name = "Drakes"; break;
case 3: name = "Fire Steeds"; break;
case 4: name = "White Wyrms"; break;
case 5: name = "Nightmares"; break;
}
// Read knowledgeI
var myData = TriggerEvent(50300, "ReadTamingKnowledgeID", pUser );
for( let i = 0; i < myData.length; i++ )
{
var myRecipeData = myData[i].split(",");
if (myRecipeData[0] == knowledgeID )
{
pUser.SysMessage( "You already have the knowledge to tame this type of animal!" );
return;
}
}
pUser.SysMessage("You feel a surge of knowledge as the bestiary teaches you how to tame " + name);// You feel a surge of knowledge as the bestiary teaches you how to tame ~1_type~!
// Ok, if id wasn't found in the array, store id in the knowledgeID we selected earlier and bestiaryBookSectionID
myData.push(knowledgeID.toString() + "," + bestiaryBookSectionID );
TriggerEvent(50300, "WriteTamingKnowledgeID", pUser, myData )
iUsed.Delete();
}
function NeedTamingKnowledge(pSock, knowledgeID)
{
var pUser = pSock.currentChar;
// Read id
var myData = TriggerEvent(50300, "ReadTamingKnowledgeID", pUser);
if (myData && myData.length > 0)
{
for (let i = 0; i < myData.length; i++)
{
var myRecipeData = myData[i].split(",");
// Check if the knowledgeID is found and not equal to 0
if (myRecipeData[0] == knowledgeID && myRecipeData[0] !== "0")
{
return true; // Player has the required knowledge
}
}
}
// If the loop completes without finding the recipe, display a message
pSock.SysMessage("You lack the knowledge required to tame this creature.");
return false; // Return false to stop the taming process
}
// Write Recipe back to file
function WriteTamingKnowledgeID( pUser, myData )
{
// Create a new file object
var mFile = new UOXCFile();
var userSerial = pUser.serial.toString();
var fileName = "TamingKnowledge" + userSerial +".jsdata";
mFile.Open(fileName, "w", "TamingKnowledge" ); // Open file for Writing
if( mFile != null )
{
// Loop through each entry in myData and save it to a new line
for( var i = 0; i < myData.length; i++ )
{
mFile.Write( myData[i] + "\n" );
}
// Close and free the file
mFile.Close()
mFile.Free();
return true;
}
return false;
}
// Read contents of Recipe
function ReadTamingKnowledgeID( pUser )
{
// Create a new file object
var mFile = new UOXCFile();
var userSerial = pUser.serial;
var fileName = "TamingKnowledge" + userSerial + ".jsdata";
// Create an array variable to store contents of Recipe
var myArray = [];
mFile.Open(fileName, "r", "TamingKnowledge" );
if( mFile && mFile.Length() >= 0 )
{
// Read until we reach the end of the file, or until we find a match for the recipe
while( !mFile.EOF() )
{
// Read a line of text from the file
var line = mFile.ReadUntil( "\n" );
if( line.length <= 1 || line == "" )
{
continue;
}
// Store each line from file in myArray
myArray.push( line );
}
mFile.Close();
// Frees memory allocated by file object
mFile.Free();
}
//pUser.SysMessage(myArray.length)
return myArray;
}
function TamingKnowledgeCheck(pSock, knowledgeID)
{
if (knowledgeID != 0)
{
var results = TriggerEvent(50300, "NeedTamingKnowledge", pSock, knowledgeID);
if (results == false)
return false;
}
return true; // Return true if knowledge check passes or knowledgeID is 0
}
function _restorecontext_() {}
{
var name = "";
switch (knowledgeID)
{
case 1: name = "Dragons"; break;
case 2: name = "Drakes"; break;
case 3: name = "Fire Steeds"; break;
case 4: name = "White Wyrms"; break;
case 5: name = "Nightmares"; break;
}
// Read knowledgeI
var myData = TriggerEvent(50300, "ReadTamingKnowledgeID", pUser );
for( let i = 0; i < myData.length; i++ )
{
var myRecipeData = myData[i].split(",");
if (myRecipeData[0] == knowledgeID )
{
pUser.SysMessage( "You already have the knowledge to tame this type of animal!" );
return;
}
}
pUser.SysMessage("You feel a surge of knowledge as the bestiary teaches you how to tame " + name);// You feel a surge of knowledge as the bestiary teaches you how to tame ~1_type~!
// Ok, if id wasn't found in the array, store id in the knowledgeID we selected earlier and bestiaryBookSectionID
myData.push(knowledgeID.toString() + "," + bestiaryBookSectionID );
TriggerEvent(50300, "WriteTamingKnowledgeID", pUser, myData )
iUsed.Delete();
}
function NeedTamingKnowledge(pSock, knowledgeID)
{
var pUser = pSock.currentChar;
// Read id
var myData = TriggerEvent(50300, "ReadTamingKnowledgeID", pUser);
if (myData && myData.length > 0)
{
for (let i = 0; i < myData.length; i++)
{
var myRecipeData = myData[i].split(",");
// Check if the knowledgeID is found and not equal to 0
if (myRecipeData[0] == knowledgeID && myRecipeData[0] !== "0")
{
return true; // Player has the required knowledge
}
}
}
// If the loop completes without finding the recipe, display a message
pSock.SysMessage("You lack the knowledge required to tame this creature.");
return false; // Return false to stop the taming process
}
// Write Recipe back to file
function WriteTamingKnowledgeID( pUser, myData )
{
// Create a new file object
var mFile = new UOXCFile();
var userSerial = pUser.serial.toString();
var fileName = "TamingKnowledge" + userSerial +".jsdata";
mFile.Open(fileName, "w", "TamingKnowledge" ); // Open file for Writing
if( mFile != null )
{
// Loop through each entry in myData and save it to a new line
for( var i = 0; i < myData.length; i++ )
{
mFile.Write( myData[i] + "\n" );
}
// Close and free the file
mFile.Close()
mFile.Free();
return true;
}
return false;
}
// Read contents of Recipe
function ReadTamingKnowledgeID( pUser )
{
// Create a new file object
var mFile = new UOXCFile();
var userSerial = pUser.serial;
var fileName = "TamingKnowledge" + userSerial + ".jsdata";
// Create an array variable to store contents of Recipe
var myArray = [];
mFile.Open(fileName, "r", "TamingKnowledge" );
if( mFile && mFile.Length() >= 0 )
{
// Read until we reach the end of the file, or until we find a match for the recipe
while( !mFile.EOF() )
{
// Read a line of text from the file
var line = mFile.ReadUntil( "\n" );
if( line.length <= 1 || line == "" )
{
continue;
}
// Store each line from file in myArray
myArray.push( line );
}
mFile.Close();
// Frees memory allocated by file object
mFile.Free();
}
//pUser.SysMessage(myArray.length)
return myArray;
}
function TamingKnowledgeCheck(pSock, knowledgeID)
{
if (knowledgeID != 0)
{
var results = TriggerEvent(50300, "NeedTamingKnowledge", pSock, knowledgeID);
if (results == false)
return false;
}
return true; // Return true if knowledge check passes or knowledgeID is 0
}
function _restorecontext_() {}
function onUseChecked( pUser, iUsed )
{
var knowledgeID = iUsed.GetTag( "KnowledgeID" )
if (!knowledgeID )
return false;
var bestiaryBookSectionID = iUsed.sectionID;
TriggerEvent(50300, "AddTamingKnowledge", pUser, iUsed, knowledgeID, bestiaryBookSectionID );
return false;
}
function onTooltip( book, pSocket )
{
var tooltipText = "Teaches Advanced Taming Knowledge";
return tooltipText;
}
{
var knowledgeID = iUsed.GetTag( "KnowledgeID" )
if (!knowledgeID )
return false;
var bestiaryBookSectionID = iUsed.sectionID;
TriggerEvent(50300, "AddTamingKnowledge", pUser, iUsed, knowledgeID, bestiaryBookSectionID );
return false;
}
function onTooltip( book, pSocket )
{
var tooltipText = "Teaches Advanced Taming Knowledge";
return tooltipText;
}
before the function function onCallback0( pSock, ourObj )
add this code
function BestiaryInfo()
{
var bestiaryGroups = {
1: ["graydragon", "reddragon"],
2: ["graydrake", "reddrake"],
3: ["firesteed"],
4: ["whitewyrm"],
5: ["nightmare", "darknightmare", "manenightmare", "purenightmare"],
// Add more groups as needed
};
var sectionIDToBestiaryID = {};
for (var bestiaryID in bestiaryGroups)
{
if (bestiaryGroups.hasOwnProperty(bestiaryID))
{
var sectionIDs = bestiaryGroups[bestiaryID];
for (var i = 0; i < sectionIDs.length; i++)
{
sectionIDToBestiaryID[sectionIDs[i]] = parseInt(bestiaryID);
}
}
}
return sectionIDToBestiaryID;
}
{
var bestiaryGroups = {
1: ["graydragon", "reddragon"],
2: ["graydrake", "reddrake"],
3: ["firesteed"],
4: ["whitewyrm"],
5: ["nightmare", "darknightmare", "manenightmare", "purenightmare"],
// Add more groups as needed
};
var sectionIDToBestiaryID = {};
for (var bestiaryID in bestiaryGroups)
{
if (bestiaryGroups.hasOwnProperty(bestiaryID))
{
var sectionIDs = bestiaryGroups[bestiaryID];
for (var i = 0; i < sectionIDs.length; i++)
{
sectionIDToBestiaryID[sectionIDs[i]] = parseInt(bestiaryID);
}
}
}
return sectionIDToBestiaryID;
}
else if (!hasBeenOwner && skillToTame > pUser.skills.taming)
{
pSock.SysMessage(GetDictionaryEntry(2398, pLanguage)); // You are not skilled enough to tame that creature
return;
}
Under that add this line of code
var sectionIDToBestiaryID = BestiaryInfo();
var sectionID = ourObj.sectionID; // Get the section ID from the object
var BestiaryID = sectionIDToBestiaryID[sectionID] || 0; // Look up the Bestiary ID, default to 0 if not found
if (!TriggerEvent(50300, "TamingKnowledgeCheck", pSock, BestiaryID))
return false;
var sectionID = ourObj.sectionID; // Get the section ID from the object
var BestiaryID = sectionIDToBestiaryID[sectionID] || 0; // Look up the Bestiary ID, default to 0 if not found
if (!TriggerEvent(50300, "TamingKnowledgeCheck", pSock, BestiaryID))
return false;
open your animallorejs file
find this line of code
if( pUser.CheckSkill( 2, 0, 1000 ))
{
add this after the {
var bestiaryID = ourObj.GetTag("BestiaryID");
var name = "";
switch (bestiaryID)
{
case 1: name = "Dragons"; break;
case 2: name = "Drakes"; break;
case 3: name = "Fire Steeds"; break;
case 4: name = "White Wyrms"; break;
case 5: name = "Nightmares"; break;
}
var name = "";
switch (bestiaryID)
{
case 1: name = "Dragons"; break;
case 2: name = "Drakes"; break;
case 3: name = "Fire Steeds"; break;
case 4: name = "White Wyrms"; break;
case 5: name = "Nightmares"; break;
}
AnimalLoreGump.AddGump( 40, 258, 0x82B );
and add this
AnimalLoreGump.AddGump(28, 266, 0x826);
AnimalLoreGump.AddHTMLGump(47, 266, 210, 18, false, false, "<basefont color=#0000C8>Special Taming Requirements</basefont>");
if (bestiaryID != null)
{
AnimalLoreGump.AddHTMLGump(53, 284, 210, 18, false, false, "<basefont color=#33310b>Knowledge of " + name + "</basefont>");
}
AnimalLoreGump.AddHTMLGump(47, 266, 210, 18, false, false, "<basefont color=#0000C8>Special Taming Requirements</basefont>");
if (bestiaryID != null)
{
AnimalLoreGump.AddHTMLGump(53, 284, 210, 18, false, false, "<basefont color=#33310b>Knowledge of " + name + "</basefont>");
}
[BestiaryonDragons]
{
get=base_item
NAME=Bestiary On Dragons
ID=0x1E22
weight=100
SCRIPT=50301
custominttag=KnowledgeID 1
}
{
get=base_item
NAME=Bestiary On Dragons
ID=0x1E22
weight=100
SCRIPT=50301
custominttag=KnowledgeID 1
}
and now the book to tame dragons is setup
there is right now just 5 books you can create but if you know what your doing you could make more.