<action itemid="xxxx" event="script" value="genderchange.lua"/>
function onUse(cid, item, fromPosition, itemEx, toPosition)
local firstaction = 11985 -- actionid which begins charges chain
local limit = 5 -- charges of item
setConditionParam(exhaust, CONDITION_PARAM_TICKS, exhausttime * 60 * 1000)
if (item.actionid < limit + firstaction) then
doPlayerSetSex(cid, getPlayerSex(cid) == PLAYERSEX_FEMALE and PLAYERSEX_MALE or PLAYERSEX_FEMALE)
if item.actionid < firstaction then
doSetItemActionId(item.uid, firstaction + 2)
if limit - 1 == 1 then
plural = ''
else
plural = 's'
end
doCreatureSay(cid, 'You have changed your gender. The item has ' .. limit - 1 .. ' charge' .. plural .. ' left.', TALKTYPE_ORANGE_1)
doSetItemSpecialDescription(item.uid, 'It has ' .. limit -1 ..' charge' .. plural .. ' left.')
else
doSetItemActionId(item.uid, item.actionid + 1)
if ((firstaction + limit) - item.actionid) == 1 then
plural = ''
else
plural = 's'
end
doCreatureSay(cid, 'You have changed your gender. The item has ' .. ((firstaction + limit) - item.actionid) .. ' charge'.. plural ..' left.', TALKTYPE_ORANGE_1)
doSetItemSpecialDescription(item.uid, 'It has ' .. (firstaction + limit) - item.actionid ..' charge'.. plural ..' left.')
end
else
doPlayerSetSex(cid, getPlayerSex(cid) == PLAYERSEX_FEMALE and PLAYERSEX_MALE or PLAYERSEX_FEMALE)
doRemoveItem(item.uid, 1)
doCreatureSay(cid, 'You have changed your gender. The item is out of charges.', TALKTYPE_ORANGE_1)
end
return true
end
Edit: removed old script, it's not what author requested
I'm almost done with new one and I'll edit this post within 30 minutes
working on addEvent to make exhaust
Edit2: done
actions.xml:
xxxx is your itemidXML:<action itemid="xxxx" event="script" value="genderchange.lua"/>
genderchange.lua:
Edit3: works if player doesn't log out, if he does addevent returns console error and makes his status pernament exhausted, I have no idea how to fix it, tried with exhaust condition, but it poisons player instead
here is script without exhaustion:
LUA:function onUse(cid, item, fromPosition, itemEx, toPosition) local firstaction = 11985 -- actionid which begins charges chain local limit = 5 -- charges of item setConditionParam(exhaust, CONDITION_PARAM_TICKS, exhausttime * 60 * 1000) if (item.actionid < limit + firstaction) then doPlayerSetSex(cid, getPlayerSex(cid) == PLAYERSEX_FEMALE and PLAYERSEX_MALE or PLAYERSEX_FEMALE) if item.actionid < firstaction then doSetItemActionId(item.uid, firstaction + 2) if limit - 1 == 1 then plural = '' else plural = 's' end doCreatureSay(cid, 'You have changed your gender. The item has ' .. limit - 1 .. ' charge' .. plural .. ' left.', TALKTYPE_ORANGE_1) doSetItemSpecialDescription(item.uid, 'It has ' .. limit -1 ..' charge' .. plural .. ' left.') else doSetItemActionId(item.uid, item.actionid + 1) if ((firstaction + limit) - item.actionid) == 1 then plural = '' else plural = 's' end doCreatureSay(cid, 'You have changed your gender. The item has ' .. ((firstaction + limit) - item.actionid) .. ' charge'.. plural ..' left.', TALKTYPE_ORANGE_1) doSetItemSpecialDescription(item.uid, 'It has ' .. (firstaction + limit) - item.actionid ..' charge'.. plural ..' left.') end else doPlayerSetSex(cid, getPlayerSex(cid) == PLAYERSEX_FEMALE and PLAYERSEX_MALE or PLAYERSEX_FEMALE) doRemoveItem(item.uid, 1) doCreatureSay(cid, 'You have changed your gender. The item is out of charges.', TALKTYPE_ORANGE_1) end return true end
if exhaustion.check(cid, 1000) then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "You need to wait "..exhaustion.get(cid, 1000).." seconds before you can use it again.")
return true
end
exhaustion.set(cid, 1000, 60)
any console errors?
[error - Action interface]
data/actions/scripts/genderchange.lua:onUse
Description:
Data/actions/scripts/genderchange.lua:4: attempt to preform arithmetic on global 'exhausttime' <a nill value>
stack trackback:
data/actions/scripts/genderchange.lua:4 in function <data/actions/scripts/genderchange.lua:1>
For 0.3 and 0.4 you can use this for exhaustion
LUA:if exhaustion.check(cid, 1000) then doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) doPlayerSendCancel(cid, "You need to wait "..exhaustion.get(cid, 1000).." before you can use it again.") return true end exhaustion.set(cid, 1000, 60)