Hello,
I have error in transform script.
When time is out maxhp=1 and maxmana=0 if i dead in next login i'm dead : \
Please repair this script or write new but with same functions
(Sorry, My english is easy)
Script :
creaturescrpits\login.lua
Creaturescripts\Transform.lua
Talkactions\talkactions.xml
Talkactions\transform.lua
lib\000-constant (configurations)
I have error in transform script.
When time is out maxhp=1 and maxmana=0 if i dead in next login i'm dead : \
Please repair this script or write new but with same functions
(Sorry, My english is easy)
Script :
creaturescrpits\login.lua
Code:
registerCreatureEvent(cid, "transform")
Creaturescripts\Transform.lua
Code:
local function loadOutfit(cid)
local outfit = {lookAddons = 0, lookType = 0, lookHead = 0, lookTypeEx = 0, lookLegs = 0, lookBody = 0, lookFeet = 0}
outfit.lookType = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit + 1) -- I know its ugly but really there is no other way to load outfit xd
outfit.lookTypeEx = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit + 3)
outfit.lookHead = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit + 2)
outfit.lookBody = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit + 5)
outfit.lookLegs = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit + 4)
outfit.lookFeet = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit + 6)
outfit.lookAddons = getPlayerStorageValue(cid, Transform_config.storageSaveOutfit)
return outfit
end
function onThink(cid, interval)
local oldvoc = getPlayerStorageValue(cid, Transform_config.storageSaveOldVocation)
local transform = transforms[oldvoc]
if(not transform) then
return true
end
if(getPlayerStorageValue(cid, Transform_config.timeSaveStorage) < os.time()) then
-- revert
doPlayerSetVocation(cid, oldvoc)
if(transform.gainHealth) then setCreatureMaxHealth(cid, getCreatureMaxHealth(cid) - transform.gainHealth) end
if(transform.gainMana) then setCreatureMaxMana(cid, getCreatureMaxMana(cid) - transform.gainMana) end
if(transform.outfit) then doCreatureChangeOutfit(cid, loadOutfit(cid)) end
if(type(unregisterCreatureEvent) == "function") then -- I have no idea whether it is this function in earlier versions =]
unregisterCreatureEvent(cid, "transform")
else
registerCreatureEvent(cid, "transform") -- in older versions this function works the same way like unregisterCreatureEvent
end
doCreatureAddHealth(cid, 1)
return true
end
if(transform.effect) then doSendMagicEffect(getThingPos(cid), transform.effect) end
if(transform.manaCost) then doCreatureAddMana(cid, -transform.manaCost) end
if(transform.soulCost) then doPlayerAddSoul(cid, -transform.soulCost) end
if(getCreatureOutfit(cid).lookType ~= transform.outfit.lookType) then doCreatureChangeOutfit(cid, transform.outfit) end
return true
end
Talkactions\talkactions.xml
Code:
<talkaction words="/transform" event="script" value="transform.lua"/>
Talkactions\transform.lua
Code:
function onSay(cid, words, param, channel)
local voc = getPlayerVocation(cid)
local transform = transforms[voc]
if(not transform) then
doPlayerSendCancel(cid, Transform_config.messages["wrong_vocation"])
return true
end
if(Transform_config.checkingLevel and getPlayerLevel(cid) < transform.level) then
doPlayerSendCancel(cid, string.format(Transform_config.messages["low_level"], transform.level))
return true
end
if(Transform_config.checkingMana and getPlayerMana(cid) < transform.firstManaCost) then
doPlayerSendCancel(cid, string.format(Transform_config.messages["not_have_mana"], transform.firstManaCost))
return true
end
doCreatureAddMana(cid, -transform.firstManaCost)
setPlayerStorageValue(cid, Transform_config.timeSaveStorage, os.time() + transform.time)
setPlayerStorageValue(cid, Transform_config.storageSaveOldVocation, voc)
registerCreatureEvent(cid, "transform")
doPlayerSetVocation(cid, transform.newVocation)
if(transform.firstSoulCost) then doPlayerAddSoul(cid, -transform.firstSoulCost) end
if(transform.firstEffect) then doSendMagicEffect(getThingPos(cid), transform.firstEffect) end
if(transform.gainHealth) then setCreatureMaxHealth(cid, getCreatureMaxHealth(cid) + transform.gainHealth) end
if(transform.gainMana) then setCreatureMaxMana(cid, getCreatureMaxMana(cid) + transform.gainMana) end
if(transform.text) then doCreatureSay(cid, transform.text, transform.textSayType) end
if(Transform_config.healTransformedPlayer) then
doCreatureAddHealth(cid, math.abs(getCreatureMaxHealth(cid) - getCreatureHealth(cid)))
doCreatureAddMana(cid, math.abs(getCreatureMaxMana(cid) - getCreatureMana(cid)))
else
doCreatureAddHealth(cid, 1) -- we need to send stats to client :D otherwise player will not see any changes in health. setCreatureMaxHealtht aren't send stats :\
end
if(transform.outfit) then
-- saving old outfit to storages.
local i = 0
for k, v in pairs(getCreatureOutfit(cid)) do
i = i + 1
setPlayerStorageValue(cid, Transform_config.storageSaveOutfit + i - 1, v)
end
doCreatureChangeOutfit(cid, transform.outfit)
end
return true
end
lib\000-constant (configurations)
Code:
transforms =
{
[5] = {outfit = {lookType = 59, lookTypeEx = 0, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookAddons = 0}, firstManaCost = 1000, text = "Yo yeah men, I'm evoluting#@#!", textSayType = TALKTYPE_SAY, manaCost = 0, level = 40, gainMana = 1000, gainHealth = 1000, firstSoulCost = 1, soulCost = 0, time = 20, newVocation = 9, effect = CONST_ME_MAGIC_RED, firstEffect = nil},
[6] = {outfit = {lookType = 12, lookTypeEx = 0, lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookAddons = 0}, firstManaCost = 1000, text = "Ha yoh ! I'm have superpowers!", textSayType = TALKTYPE_MONSTER, manaCost = 0, level = 5, gainMana = 1000, gainHealth = 1000, firstSoulCost = 1, soulCost = 0, time = 60, newVocation = 10, effect = CONST_ME_MAGIC_GREEN, firstEffect = CONST_ME_HOLYDAMAGE}
}
Transform_config =
{
checkingLevel = true,
checkingMana = true,
timeSaveStorage = 9750,
storageSaveOutfit = 9751, -- this storage value and six more must been unused.
storageSaveOldVocation = 9758,
healTransformedPlayer = true,
messages =
{
["wrong_vocation"] = "Your vocation hasn't any transformations.",
["low_level"] = "You need level %i at least to transformation.",
["not_have_mana"] = "You need %i manapoints to transformation."
}
}
Last edited: