• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

help modifying this script

kimokimo

Kimo
Joined
Jan 25, 2011
Messages
821
Solutions
6
Reaction score
156
GitHub
karimadnan
PHP:
-- Options for releasing the monster with another item --
local useBreakWithItem = false -- Enable this feature
local breakWithItem = 7428 -- Item to release the monster with.
 
-- Item Options --
local setActionId = 1000 -- Action id that will be set for an used item.
local breakChanse = 80000 -- Break chanse. For example: if breakChanse = 500 then break chanse will be ((CurrentHp/monsterMaxHp)*monsterMaxHp)/500).
 
-- Limits --
local playerLevel = 50 -- Player level needed.
local monsterStatus = "convinced" -- Keep it as "convinced" if you want the monster to be like a pet for the releaser, otherwise make it "wild".
local avalibleMonsters = {"Ninja", "Outlawed Warrior", "Templar Grand Master", "Outlawed Sorcerer", "Outlawed Ranger", "Outlawed Elite Guard"} -- Monsters that is possible to catch. ALWAYS write the name exactly as it is written in the monster files(It maters in this case).
local validVocations = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} -- Vocationids of vocations that are able to use this item.
 
-- Effects --
local breakEffect = CONST_ME_POFF -- This effect will apear on the item when it breakes.
local usedEffect = CONST_ME_POFF -- This effect will apear on the item if it is used.
local successEffect = CONST_ME_FIREWORK_YELLOW -- This effect will apear on the monster when it's catched.
local releaseEffect = CONST_ME_FIREWORK_RED -- This effect will apear when the monster is released.
 
-- Messages --
local emptyDesc = "It\'s empty." -- Description that will be set for the item when the monster is released.
 
local messageColor = TALKTYPE_ORANGE_1
local successMessages = {"You\'ve succefully caught the monster.", "Success!!"} -- Success messages when the creature is caught.
local failureMessages = {"You\'ve failed to catch the monster.", "The monster ran away."} -- Failure messages.
local usedMessages = {"This item is already used", "You\'ve already used this item."} -- One of these messages apears if the item is already used.
local abortMessages = {"You\'ve failed to catch the monster.", "The monster is too strong."} -- Abort messages if the monster is in the ignore list above.
local notOnGroundMessage = {"Please put the item on the ground first.", "You can\'t release the creature in your backpack."} -- These messages apears if the item is not on the ground.
local inOnInvalidGround = {"The item is on a protected zone.", "You can\'t release the monster here."} -- These messages apears if the item is on a protected zone.
local tooLowLevel = {"You are too low level to use this item, you'll need level ".. playerLevel .." or higher."}
local invalidVocation = {"You are not able to use this item."}
 
--------------- END OF CONFIG -------------
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerLevel(cid) < playerLevel then
		sendMessage(cid, tooLowLevel, messageColor)
		return true
	end
 
	if not isInArray(validVocations, getPlayerVocation(cid)) then
		sendMessage(cid, invalidVocation, messageColor)
		return true
	end
 
	if useBreakWithItem then
		if item.itemid == breakWithItem and releaseMonster(cid, itemEx, toPosition) then
			return true
		end
	else
		if releaseMonster(cid, item, toPosition) then
			return true
		end
	end
 
	if item.actionid > 100 then
		if item.actionid ~= setActionId then
			doItemSetAttribute(item.uid, "aid", setActionId)
		end
		sendMessage(cid, usedMessages, messageColor)
		doSendMagicEffect(getCreaturePosition(cid), usedEffect)
		return true
	end
	if isMonster(itemEx.uid) then
		monsterFullHp, monsterHp = getCreatureMaxHealth(itemEx.uid), getCreatureHealth(itemEx.uid)
		formula = (monsterHp/monsterFullHp)*monsterFullHp
		chanse, bchanse = math.random(1, formula), math.floor(formula)
		if (chanse+breakChanse) >= bchanse then
			s = 0
			for i = 1, #avalibleMonsters do
				if getCreatureName(itemEx.uid) ~= avalibleMonsters[i] then
					s = s + 1
				end
			end
			if s == #avalibleMonsters then
				sendMessage(cid, abortMessages, messageColor)
				doSendMagicEffect(getCreaturePosition(cid), breakEffect)
				return true
			end
			doItemSetAttribute(item.uid, "description", "It contains a captured ".. getCreatureName(itemEx.uid) ..".")
			doItemSetAttribute(item.uid, "aid", setActionId)
			doRemoveCreature(itemEx.uid)
			sendMessage(cid, successMessages, messageColor)
			doSendMagicEffect(toPosition, successEffect)
		else
			if getCreatureMaster(itemEx.uid) ~= cid then
				doRemoveItem(item.uid, 1)
			end
			doSendMagicEffect(getCreaturePosition(cid), breakEffect)
			sendMessage(cid, failureMessages, messageColor)
		end
	else
		doSendMagicEffect(getCreaturePosition(cid), breakEffect)
	end
	return true
end
 
function sendMessage(cid, table, color)
	if table[1] == nil then
		return nil
	end
	messageId = math.random(1, #table)
	doCreatureSay(cid, table[messageId], color)
end
 
function releaseMonster(cid, itemEx, toPosition)
	if itemEx.actionid == setActionId then
		for i = 1, #avalibleMonsters do
			desc = getItemDescriptions(itemEx.uid).special
			local fromS, toS = desc:find(avalibleMonsters[i])
			if toS then
				if toPosition.x ~= CONTAINER_POSITION then
					if not getTilePzInfo(getThingPos(itemEx.uid)) then
						monsPar = doCreateMonster(desc:sub(fromS, toS), toPosition)
						if monsterStatus == "convinced" then
							doConvinceCreature(cid, monsPar)
						end
						doItemSetAttribute(itemEx.uid, "description", emptyDesc)
						doSendMagicEffect(getCreaturePosition(monsPar), releaseEffect)
					else
						sendMessage(cid, inOnInvalidGround, messageColor)
						doSendMagicEffect(getCreaturePosition(cid), breakEffect)
					end
					return true
				else
					sendMessage(cid, notOnGroundMessage, messageColor)
					doSendMagicEffect(getCreaturePosition(cid), breakEffect)
				end
				break
			end
		end
	end
	return false
end


this is catch monster from otfans but when i catch the monster and release the monster will be like my pet but i need to catch it again to call it back can anyone modify it so when i click on the item it relase the monster and when i click again call it back anyone ? :D
 
Back
Top