- Joined
- Apr 1, 2012
- Messages
- 1,249
- Solutions
- 71
- Reaction score
- 621
- Location
- Hell
- GitHub
- idontreallywolf
Hello, OT Plebs.
I have written a script for taming mounts and I would like to receive some feedback and maybe optimize it [a bit] with your help.
Here's the code:
I have written a script for taming mounts and I would like to receive some feedback and maybe optimize it [a bit] with your help.
Here's the code:
XML:
<action itemid="13307" script="mounts/tame.lua"/>
<action itemid="13538" script="mounts/tame.lua"/>
Lua:
local config = {
["Wailing Widow"] = { mount_id = 1, storage = 20001, tamingItemId = 13307 },
["Panda"] = { mount_id = 19, storage = 20002, tamingItemId = 13538 }
-- ... etc
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- Make sure target is a monster
local targetCreature = Creature(target)
if(targetCreature and not targetCreature:isPlayer()) then
-- confirm existence in config
local mount = config[targetCreature:getName()]
if(mount) then
-- confirm that the player doesn't already possess the mount.
if(player:getStorageValue(mount.storage) <= 0) then
player:setStorageValue(mount.storage, 1)
player:addMount(mount.mount_id)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have received the ".. targetCreature:getName() .." mount.")
player:getPosition():sendMagicEffect(31)
-- Remove tamed monster
target:remove()
-- remove taming item
player:removeItem(mount.tamingItemId, 1)
else
player:sendCancelMessage("You already have this mount.")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
else
player:sendCancelMessage("Invalid target.")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
return true
end
Last edited: