X
Xikini
Guest
TFS 0.3.7
Generally the script below was asked to be created in private.
It's not a very hard script by any means, however I was wondering if anyone has an idea to make the script shorter / more compact.
It's pretty much the same stuff over and over.. but checking and accessing the table slightly differently each time.
If a server has 16 vocations, this would become a knightmare. (oh yes. I did.)
Script checks for item being used, (in this case a statue), If you are the correct vocation, it will 'convert' 1 item into another.
Nice and simple.. yet I feel it's way too long for such a simple script.
Is there a way to shorten it?
Cheers,
Xikini
Generally the script below was asked to be created in private.
It's not a very hard script by any means, however I was wondering if anyone has an idea to make the script shorter / more compact.
It's pretty much the same stuff over and over.. but checking and accessing the table slightly differently each time.
If a server has 16 vocations, this would become a knightmare. (oh yes. I did.)
Script checks for item being used, (in this case a statue), If you are the correct vocation, it will 'convert' 1 item into another.
Nice and simple.. yet I feel it's way too long for such a simple script.
Is there a way to shorten it?
Cheers,
Xikini
Code:
local config = {
sorcerer = { itemRequired = 1111, itemRequiredAmount = 1, itemGiven = 1111, itemGivenAmount = 1, statueID = 8834},
druid = { itemRequired = 1111, itemRequiredAmount = 1, itemGiven = 1111, itemGivenAmount = 1, statueID = 8422},
knight = { itemRequired = 1111, itemRequiredAmount = 1, itemGiven = 1111, itemGivenAmount = 1, statueID = 8836},
paladin = { itemRequired = 1111, itemRequiredAmount = 1, itemGiven = 1111, itemGivenAmount = 1, statueID = 3739}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
-- Sorcerers
if item.itemid == config.sorcerer.statueID then
if getPlayerVocationName(cid):lower() == "sorcerer" or getPlayerVocationName(cid):lower() == "master sorcerer" then
if getPlayerItemCount(cid, config.sorcerer.itemRequired) >= config.sorcerer.itemRequiredAmount then
doPlayerRemoveItem(cid, config.sorcerer.itemRequired, config.sorcerer.itemRequiredAmount)
doPlayerAddItem(cid, config.sorcerer.itemGiven, config.sorcerer.itemGivenAmount, true)
doCreatureSay(cid, "Removed ".. config.sorcerer.itemRequiredAmount .." ".. getItemNameById(config.sorcerer.itemRequired) ..". You received ".. config.sorcerer.itemGivenAmount .." ".. getItemNameById(config.sorcerer.itemGiven) ..".", TALKTYPE_ORANGE_1)
else
return doPlayerSendCancel(cid, "You require ".. config.sorcerer.itemRequiredAmount .." ".. getItemNameById(config.sorcerer.itemRequired) .." to receive ".. config.sorcerer.itemGivenAmount .." ".. getItemNameById(config.sorcerer.itemGiven) ..".")
end
else
return doPlayerSendCancel(cid, "Only sorcerers may use this statue.")
end
-- Druids
elseif item.itemid == config.druid.statueID then
if getPlayerVocationName(cid):lower() == "druid" or getPlayerVocationName(cid):lower() == "elder druid" then
if getPlayerItemCount(cid, config.druid.itemRequired) >= config.druid.itemRequiredAmount then
doPlayerRemoveItem(cid, config.druid.itemRequired, config.druid.itemRequiredAmount)
doPlayerAddItem(cid, config.druid.itemGiven, config.druid.itemGivenAmount, true)
doCreatureSay(cid, "Removed ".. config.druid.itemRequiredAmount .." ".. getItemNameById(config.druid.itemRequired) ..". You received ".. config.druid.itemGivenAmount .." ".. getItemNameById(config.druid.itemGiven) ..".", TALKTYPE_ORANGE_1)
else
return doPlayerSendCancel(cid, "You require ".. config.druid.itemRequiredAmount .." ".. getItemNameById(config.druid.itemRequired) .." to receive ".. config.druid.itemGivenAmount .." ".. getItemNameById(config.druid.itemGiven) ..".")
end
else
return doPlayerSendCancel(cid, "Only druids may use this statue.")
end
-- Knights
elseif item.itemid == config.knight.statueID then
if getPlayerVocationName(cid):lower() == "knight" or getPlayerVocationName(cid):lower() == "elite knight" then
if getPlayerItemCount(cid, config.knight.itemRequired) >= config.knight.itemRequiredAmount then
doPlayerRemoveItem(cid, config.knight.itemRequired, config.knight.itemRequiredAmount)
doPlayerAddItem(cid, config.knight.itemGiven, config.knight.itemGivenAmount, true)
doCreatureSay(cid, "Removed ".. config.knight.itemRequiredAmount .." ".. getItemNameById(config.knight.itemRequired) ..". You received ".. config.knight.itemGivenAmount .." ".. getItemNameById(config.knight.itemGiven) ..".", TALKTYPE_ORANGE_1)
else
return doPlayerSendCancel(cid, "You require ".. config.knight.itemRequiredAmount .." ".. getItemNameById(config.knight.itemRequired) .." to receive ".. config.knight.itemGivenAmount .." ".. getItemNameById(config.knight.itemGiven) ..".")
end
else
return doPlayerSendCancel(cid, "Only knights may use this statue.")
end
-- Paladins
elseif item.itemid == config.paladin.statueID then
if getPlayerVocationName(cid):lower() == "paladin" or getPlayerVocationName(cid):lower() == "royal paladin" then
if getPlayerItemCount(cid, config.paladin.itemRequired) >= config.paladin.itemRequiredAmount then
doPlayerRemoveItem(cid, config.paladin.itemRequired, config.paladin.itemRequiredAmount)
doPlayerAddItem(cid, config.paladin.itemGiven, config.paladin.itemGivenAmount, true)
doCreatureSay(cid, "Removed ".. config.paladin.itemRequiredAmount .." ".. getItemNameById(config.paladin.itemRequired) ..". You received ".. config.paladin.itemGivenAmount .." ".. getItemNameById(config.paladin.itemGiven) ..".", TALKTYPE_ORANGE_1)
else
return doPlayerSendCancel(cid, "You require ".. config.paladin.itemRequiredAmount .." ".. getItemNameById(config.paladin.itemRequired) .." to receive ".. config.paladin.itemGivenAmount .." ".. getItemNameById(config.paladin.itemGiven) ..".")
end
else
return doPlayerSendCancel(cid, "Only paladins may use this statue.")
end
else
return doPlayerSendCancel(cid, "ERROR: itemID used is incorrect. Contact Administration that script is not functioning as intended.")
-- If you receive this error then the itemID is incorrect. Check the statues being used.
end
return true
end
Last edited by a moderator: