-- using a table keeps the script orginized and easy to trouble shoot errors that will arise
-- use comments to show how the data is stored or excuted
local c = { -- c short for config
-- use names for properties of variables/tables which make sense
itemType = 2160,
amount = 20,
outfitStorage = 18000
}
-- 0 for female, 1 for male
local outfits = {
[0] = { -- female, 0 corresponds to the sex of the player as female
-- the index of the table below corresponds to vocation of the player
[1] = { -- sorcerer,
lookType = 243,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
},
[2] = { -- druid
lookType = 11,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
},
[3] = { -- paladin
lookType = 345,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
},
[4] = { -- knight
lookType = 306,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
}
},
[1] = { -- male, 1 corresponds to the sex of the player as male
-- the index of the table below corresponds to vocation of the player
[1] = { -- sorcerer
lookType = 243,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
},
[2] = { -- druid
lookType = 11,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
},
[3] = { -- paladin
lookType = 345,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
},
[4] = { -- knight
lookType = 306,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0
}
}
}
function onEquip(cid, item, slot)
-- onEquip executes more then once, this is just a preventive measure
local slots = getPlayerSlotItem(cid, slot)
if slots then
if slots.itemid ~= item.itemid then
return false
end
else
local cost = getPlayerItemCount(cid, c.itemType)
-- 1st thing is 1st lets make sure they have enough money in this case to use this item
if cost >= c.amount then
-- then lets check if they have outfit already assigned to the player
if getPlayerStorageValue(c.outfitStorage) < 1 then
-- if not then lets get their vocation & sex, important because will use this later
local vocation = getPlayerVocation(cid)
local sex = getPlayerSex(cid)
-- for now we are just testing the waters... lets just see if we can change the players outfit based on its sex and vocation
-- so we take our outfits table and apply sex and vocation to the corresponding table indexes
doSetCreatureOutfit(cid, outfits[sex][vocation], -1)
-- The setting value you assign to the storage is optional, any number greater then 0
-- however I like to use the vocation as its value
setPlayerStorageValue(c.outfitStorage, vocation)
-- remove the item amount from the player
doPlayerRemoveItem(cid, c.itemType, c.amount)
-- this table will be used later for the rest of the functionality of your script
local p = {cid = cid, item = item, slot = slot, sex = sex, id = vocation}
end
end
end
return true
end
function onDeEquip(cid, item, slot)
-- check to make sure the player has an outfit condition assigned to them, by checking the storage value
if getPlayerStorageValue(c.outfitStorage) > 0 then
-- if they do remove the outfit condition
doRemoveCondition(cid, CONDITION_OUTFIT)
-- set the storage value to 0
setPlayerStorageValue(c.outfitStorage, 0)
end
return true
end