data\actions\scripts
add a script with the name you choose granico.lua
then add this to it.local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
if not getPlayerLearnedInstantSpell(cid, spell) then
doPlayerLearnInstantSpell(cid, spell)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
doRemoveItem(item.uid, 1)
else
doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
end
return true
end
data\actions\actions.xml
add<action itemid="5957" event="script" value="granico.lua"/>
Can you show the current lever script?@M0ustafa
how add this in lever
Lua:doPlayerRemoveItem(cid, 8981, 1) doPlayerRemoveItem(cid, 2157, 20)
Can you show the current lever script?
I don't feel like I've seen the lever script in the past comments.
local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
if not getPlayerLearnedInstantSpell(cid, spell) then
doPlayerLearnInstantSpell(cid, spell)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
else
doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
end
return true
end
doPlayerRemoveItem(cid, 8981, 1)
doPlayerRemoveItem(cid, 2157, 20)
Lua:local spell = "gran ico" function onUse(cid, item, fromPosition, itemEx, toPosition) if not getPlayerLearnedInstantSpell(cid, spell) then doPlayerLearnInstantSpell(cid, spell) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!") doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE) else doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid)) end return true end
Post automatically merged:
How do I add a price using this?
Lua:doPlayerRemoveItem(cid, 8981, 1) doPlayerRemoveItem(cid, 2157, 20)
local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerLearnedInstantSpell(cid, spell) then
doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
return true
end
if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
return true
end
doPlayerRemoveItem(cid, 8981, 1)
doPlayerRemoveItem(cid, 2157, 20)
doPlayerLearnInstantSpell(cid, spell)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
return true
end
Do not give any errors, but lever does not move and does not give anything or any messageLua:local spell = "gran ico" function onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerLearnedInstantSpell(cid, spell) then doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid)) return true end if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid)) return true end doPlayerRemoveItem(cid, 8981, 1) doPlayerRemoveItem(cid, 2157, 20) doPlayerLearnInstantSpell(cid, spell) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!") doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE) return true end
I've added some prints.Do not give any errors, but lever does not move and does not give anything or any message
And if I have this (8981, 1) (2157, 20)
local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
print("onUse function started..")
if getPlayerLearnedInstantSpell(cid, spell) then
doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
print("onUse function finished. Ending 1 -- spell already known")
return true
end
if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
print("onUse function finished. Ending 2 -- required items missing from player")
return true
end
doPlayerRemoveItem(cid, 8981, 1)
doPlayerRemoveItem(cid, 2157, 20)
doPlayerLearnInstantSpell(cid, spell)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
print("onUse function finished. Ending 3 -- Spell has been successfully learned.")
return true
end
Well it really works but it doesn't give any of these messagesI've added some prints.
Check console to find out what is happening, and report back.
(If you don't see anything in console, then the script has likely errored while starting up the server.)
Lua:local spell = "gran ico" function onUse(cid, item, fromPosition, itemEx, toPosition) print("onUse function started..") if getPlayerLearnedInstantSpell(cid, spell) then doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid)) print("onUse function finished. Ending 1 -- spell already known") return true end if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid)) print("onUse function finished. Ending 2 -- required items missing from player") return true end doPlayerRemoveItem(cid, 8981, 1) doPlayerRemoveItem(cid, 2157, 20) doPlayerLearnInstantSpell(cid, spell) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!") doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE) print("onUse function finished. Ending 3 -- Spell has been successfully learned.") return true end
doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
Well it really works but it doesn't give any of these messages
Lua:doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
and how add only vocation id 4,8 can use itLua:doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
local spell = "gran ico"
local vocations = {4, 8}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerLearnedInstantSpell(cid, spell) then
doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1)
return true
end
local voc = getPlayerVocation(cid)
if not isInArray(vocations, voc) then
local text = ""
for i = 1, #vocations do
if text ~= "" then
if i + 1 == #vocations then
text = text .. " and "
else
text = text .. ", "
end
end
text = text .. getVocationInfo(vocations[i]).name .. "'s"
end
doCreatureSay(cid, "Only " .. text .. " can learn this spell.", TALKTYPE_ORANGE_1)
return true
end
if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1)
return true
end
doPlayerRemoveItem(cid, 8981, 1)
doPlayerRemoveItem(cid, 2157, 20)
doPlayerLearnInstantSpell(cid, spell)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
return true
end
ErrorLua:local spell = "gran ico" local vocations = {4, 8} function onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerLearnedInstantSpell(cid, spell) then doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1) return true end local voc = getPlayerVocation(cid) if not isInArray(vocations, voc) local text = "" for i = 1, #vocations do if text ~= "" then if i + 1 == #vocations then text = text .. " and " else text = text .. ", " end end text = text .. getVocationInfo(vocations[i]).name .. "'s" end doCreatureSay(cid, "Only " .. text .. " can learn this spell.", TALKTYPE_ORANGE_1) return true end if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1) return true end doPlayerRemoveItem(cid, 8981, 1) doPlayerRemoveItem(cid, 2157, 20) doPlayerLearnInstantSpell(cid, spell) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!") doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE) return true end
[13:33:58.746] [Error - LuaInterface::loadFile] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
[13:33:58.761] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/shop/hot2.lua)
[13:33:58.761] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
changeError
Code:[13:33:58.746] [Error - LuaInterface::loadFile] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local' [13:33:58.761] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/shop/hot2.lua) [13:33:58.761] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
if not isInArray(vocations, voc)
if not isInArray(vocations, voc) then
Thank you so much!change
toLua:if not isInArray(vocations, voc)
Lua:if not isInArray(vocations, voc) then