• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Request] Special Food Spell

MarkSmartRemark

Lua-Noob in Training :D
Joined
Jan 27, 2010
Messages
139
Reaction score
3
Hi,

Im looking for a code that does the following:

  1. Player casts spell and adds 20 of an item into his backpack. (spell)
  2. Example If he has 89 of these in backpack the spell will only add 11 to his backpack.(part of spell)
  3. If he already has 100 in backpack, spell will not work.



EDIT: Spell is working perfectly.

Code:
--.::.CONFIG.::.--
local item = 2677      --- Item ID number
local cast_amount = 20 --- How many will spell create
local max_item = 100    --- Maximum allowed in BP
--.::.CONFIG.::.--



function onCastSpell(cid, var)
local difference = (max_item - cast_amount)
    if  getPlayerItemCount(cid, item) <= difference then
        doPlayerAddItem(cid, item, cast_amount, true)
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
    elseif getPlayerItemCount(cid, item) > difference and getPlayerItemCount(cid, item) < max_item then
            doPlayerAddItem(cid, item,(max_item - getPlayerItemCount(cid, item)))
            doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
        elseif getPlayerItemCount(cid, item) >= max_item then
            doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
            doPlayerSendCancel(cid, "You've reached your limit of "..max_item.." "..getItemNameById(item)..".")
  end
  return true
end

will be reposted on spells section with credits to those who helped and myself, Thanks alot!!
 
Last edited:
-- Player casts spell and adds 20 of an item into his backpack. (spell)--


local FOODS = {XXXX} -- Here put the ID of the food item/s--

function onCastSpell(cid, var)
if getPlayerItemById(cid, FOODS) <= 80 then
doPlayerAddItem(uid, FOODS, 20, 1 canDropOnMap)
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
else
doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados [FOODS]", 1)
end
end


That should do, but it's my first time with spells, i don't have a way to know if works or not, in any case gladly apreciated will be if you gave me feed back

If work, tell me

If doesn't work, tell me either and why

BTW, i don't know how to do than it gaves the exactly difference when he must bring less than 20 breads, so he can't do the spell if he need less than 20. :D

Hope it helps!

PS: Gave me feedback, maybie when i return i'll gave it a second turn.
 
-- Player casts spell and adds 20 of an item into his backpack. (spell)--


local FOODS = {XXXX} -- Here put the ID of the food item/s--

function onCastSpell(cid, var)
if getPlayerItemById(cid, FOODS) <= 80 then
doPlayerAddItem(uid, FOODS, 20, 1 canDropOnMap)
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
else
doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados [FOODS]", 1)
end
end


That should do, but it's my first time with spells, i don't have a way to know if works or not, in any case gladly apreciated will be if you gave me feed back

If work, tell me

If doesn't work, tell me either and why

BTW, i don't know how to do than it gaves the exactly difference when he must bring less than 20 breads, so he can't do the spell if he need less than 20. :D

Hope it helps!

PS: Gave me feedback, maybie when i return i'll gave it a second turn.


heyy thanks for trying bro, it gave me this error first time i used without changing anything

Code:
[19/02/2014 20:57:22] [Error - LuaScriptInterface::loadFile] data/spells/scripts/Mage/New/Conjure Refreshment.lua:5: ')' expected near 'canDropOnMap'
[19/02/2014 20:57:22] [Warning - Event::loadScript] Cannot load script (data/spells/scripts/Mage/New/Conjure Refreshment.lua)
[19/02/2014 20:57:22] data/spells/scripts/Mage/New/Conjure Refreshment.lua:5: ')' expected near 'canDropOnMap'
[19/02/2014 20:57:23] [Notice - Game::reloadInfo] Reload type does not work.

so i added the ) a couple of times around that line and erased the 1 and tried to change it but still nothing, then it gave me this error

Code:
[19/02/2014 20:58:15] [Error - Spell Interface]
[19/02/2014 20:58:15] data/spells/scripts/Mage/New/Conjure Refreshment.lua:onCastSpell
[19/02/2014 20:58:15] Description:
[19/02/2014 20:58:15] data/spells/scripts/Mage/New/Conjure Refreshment.lua:4: attempt to compare table with number
[19/02/2014 20:58:15] stack traceback:
[19/02/2014 20:58:15]    data/spells/scripts/Mage/New/Conjure Refreshment.lua:4: in function <data/spells/scripts/Mage/New/Conjure Refreshment.lua:3>

The idea to start the script seems to be right though! :D
 
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--

function onCastSpell(cid, var)
   if getPlayerItemById(cid, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
         doPlayerAddItem(uid, FOODS[1][, 20[, canDropOnMap = true]])
         doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
         doPlayerAddItem(uid, FOODS[2][, 20[, canDropOnMap = true]])
         doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
   else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes         demaciados", 1)
   end
end

Try this,
If doesn't work, just tell me
but before telling me, try, if doesn't work, to remove the "[]"
doPlayerAddItem(uid, FOODS[, 20, canDropOnMap = true])
and if that doesn't work, leave it this way
doPlayerAddItem(uid, FOODS, 20, canDropOnMap = true)

If all three fail, tell me what it seems in the log & i'll try to fix it.
;)

PS: i add the "BONUS STUFF" than you ask it. ;)
 
Last edited:
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--

function onCastSpell(cid, var)
   if getPlayerItemById(cid, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
         doPlayerAddItem(uid, FOODS[1][, 20[, canDropOnMap = true]])
         doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
         doPlayerAddItem(uid, FOODS[2][, 20[, canDropOnMap = true]])
         doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
   else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes         demaciados", 1)
   end
end

Try this,
If doesn't work, just tell me
but before telling me, try, if doesn't work, to remove the "[]"

and if that doesn't work, leave it this way


If all three fail, tell me what it seems in the log & i'll try to fix it.
;)

PS: i add the "BONUS STUFF" than you ask it. ;)


Heyy it gave me this error now : / the first time i did it with parenthesis it gave me the same error and then i took off the [] and it gave me this..

Code:
[19/02/2014 23:26:25] [Error - Spell Interface]
[19/02/2014 23:26:25] data/spells/scripts/Mage/New/Conjure Refreshment.lua:onCastSpell
[19/02/2014 23:26:25] Description:
[19/02/2014 23:26:25] (luaGetPlayerItemById) Player not found

[19/02/2014 23:26:25] [Error - Spell Interface]
[19/02/2014 23:26:25] data/spells/scripts/Mage/New/Conjure Refreshment.lua:onCastSpell
[19/02/2014 23:26:25] Description:
[19/02/2014 23:26:25] data/spells/scripts/Mage/New/Conjure Refreshment.lua:4: attempt to compare table with number
[19/02/2014 23:26:25] stack traceback:
[19/02/2014 23:26:25]    data/spells/scripts/Mage/New/Conjure Refreshment.lua:4: in function <data/spells/scripts/Mage/New/Conjure Refreshment.lua:3>
^^ this is basically whats messing me up, the FOODS is supposed to be somewhere else.. im not sure where though

Hope someone can help with this please! And thank you for trying anyways @Obsdark !
 
Last edited:
This one

Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)

function onCastSpell(cid, var)
 
  if getPlayerItemCount(cid, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
        doPlayerAddItem(uid, FOODS[1][, 20[, canDropOnMap = true]])
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid, FOODS[2][, 20[, canDropOnMap = true]])
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
  else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
end

Ok,

if this doesn't work try with this one:


Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)

function onCastSpell(cid, var)
 
  if getPlayerItemCount(get, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
        doPlayerAddItem(uid, FOODS[1][, 20[, canDropOnMap = true]])
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid, FOODS[2][, 20[, canDropOnMap = true]])
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
  else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
end

If none of them work
just tell me and send me the log info again ;)

If one of them work and the other doesn't, also tell me, and tell me which one does, if the log shows something, also post it. ;)
 
Last edited:
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)

function onCastSpell(cid, var)
  if getPlayerItemCount(get, FOODS) <= 80 then
  if getPlayerLevel(cid) <= 20 then
  doPlayerAddItem(uid, FOODS[1], 20)
  doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
  elseif getPlayerLevel(cid) > 20 then
  doPlayerAddItem(uid, FOODS[2], 20)
  doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
  else
  doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
  end
  return true
end
 
Stop Copying From:http://otland.net/threads/scripting-guide.74030/

I Am Joking Bro :) you can copy but when you copy something like this
Code:
doPlayerAddItem(uid, itemid[, count/subtype[, canDropOnMap = true]])
the parameters between [ ] are extra. and they show you what you should write here
so it will be like this if you want to full them all
Code:
doPlayerAddItem(uid, itemid,20,true)
 
For been honest, is the first time
i use that command at all. ;)


Thanks a lot!

@MarkSmart

Try this one, this should do all you wanted in the original one

Code:
-- Player casts spell and adds 20 of an item into his backpack. (spell)--


local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)

function onCastSpell(cid, var)
  
  if getPlayerItemCount(cid, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
        doPlayerAddItem(uid, FOODS[1], 20, true)
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid, FOODS[2], 20, true)
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
    elseif getPlayerItemCount(cid, FOODS) > 80 and getPlayerLevel(cid) <= 20 then
            doPlayerAddItem(uid,FOODS[1](getPlayerItemCount(cid, FOODS[1]) - 100)
    elseif getPlayerItemCount(cid, FOODS) > 80 and getPlayerLevel(cid) > 20 then
            doPlayerAddItem(uid,FOODS[2](getPlayerItemCount(cid, FOODS[2]) - 100)      
    else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demasiados", 1)
  end
end

However, you should send me the log i just ask before, & this one if doesn't work.
;)
 
Code:
doPlayerAddItem(uid,FOODS[2](getPlayerItemCount(cid, FOODS[2]) - 100)
if the player have 82 food.it is going to do 82-100 = -18 :p
Reverse it to 100-getPlayerItemCount(cid, FOODS[2])
And Add the " , "to Be
Code:
doPlayerAddItem(uid,FOODS[2], 100-getPlayerItemCount(cid, FOODS[2]))
 
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)

function onCastSpell(cid, var)
  if getPlayerItemCount(get, FOODS) <= 80 then
  if getPlayerLevel(cid) <= 20 then
  doPlayerAddItem(uid, FOODS[1], 20)
  doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
  elseif getPlayerLevel(cid) > 20 then
  doPlayerAddItem(uid, FOODS[2], 20)
  doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
  else
  doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
  end
  return true
end

I posted as is, and got these errors.. i went fixing the first "(" errors but then it gave me that last one.. i also tried using the local "get" and put into the function but still the same error..

Code:
[20/02/2014 10:06:16] [Error - LuaScriptInterface::loadFile] data/spells/scripts/Mage/New/Conjure Refreshment.lua:15: ')' expected (to close '(' at line 14) near 'elseif'
[20/02/2014 10:06:16] [Warning - Event::loadScript] Cannot load script (data/spells/scripts/Mage/New/Conjure Refreshment.lua)
[20/02/2014 10:06:16] data/spells/scripts/Mage/New/Conjure Refreshment.lua:15: ')' expected (to close '(' at line 14) near 'elseif'
[20/02/2014 10:06:17] Reloaded spells.
[20/02/2014 10:07:26] [Error - LuaScriptInterface::loadFile] data/spells/scripts/Mage/New/Conjure Refreshment.lua:17: ')' expected (to close '(' at line 16) near 'else'
[20/02/2014 10:07:26] [Warning - Event::loadScript] Cannot load script (data/spells/scripts/Mage/New/Conjure Refreshment.lua)
[20/02/2014 10:07:26] data/spells/scripts/Mage/New/Conjure Refreshment.lua:17: ')' expected (to close '(' at line 16) near 'else'
[20/02/2014 10:07:27] Reloaded spells.
[20/02/2014 10:07:39] [Error - LuaScriptInterface::loadFile] data/spells/scripts/Mage/New/Conjure Refreshment.lua:20: 'end' expected (to close 'function' at line 4) near '<eof>'
[20/02/2014 10:07:39] [Warning - Event::loadScript] Cannot load script (data/spells/scripts/Mage/New/Conjure Refreshment.lua)
[20/02/2014 10:07:39] data/spells/scripts/Mage/New/Conjure Refreshment.lua:20: 'end' expected (to close 'function' at line 4) near '<eof>'
[20/02/2014 10:07:40] Reloaded spells.

[20/02/2014 10:07:53] [Error - Spell Interface]
[20/02/2014 10:07:53] data/spells/scripts/Mage/New/Conjure Refreshment.lua
[20/02/2014 10:07:53] Description:
[20/02/2014 10:07:53] (luaGetThingPosition) Thing not found
[20/02/2014 10:07:54] Reloaded spells.

any suggestions? :p

EDIT: @tetra20 i tested party loot on 0.3.6 and it worked perfectly :) gj
 
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--

function onCastSpell(cid, var)
local get = getPlayerPosition(cid)
  if getPlayerItemCount(cid, FOODS) <= 80 then
  if getPlayerLevel(cid) <= 20 then
  doPlayerAddItem(uid, FOODS[1], 20)
  doSendMagicEffect(get, CONST_ME_MAGIC_GREEN)
  elseif getPlayerLevel(cid) > 20 then
  doPlayerAddItem(uid, FOODS[2], 20)
  doSendMagicEffect(get, CONST_ME_MAGIC_GREEN)
  else
  doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
  end
  return true
end

Thanks For testing Pt Loot
 
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)

function onCastSpell(cid, var)
  if getPlayerItemCount(cid, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
        doPlayerAddItem(uid, FOODS[1], 20, true)
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid, FOODS[2], 20, true)
      end
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
    elseif getPlayerItemCount(cid, FOODS) > 80 and getPlayerLevel(cid) <= 20 then
            doPlayerAddItem(uid,FOODS[1],(100 - getPlayerItemCount(cid, FOODS[1]))
        end
    elseif getPlayerItemCount(cid, FOODS) > 80 and getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid,FOODS[2],(100 - getPlayerItemCount(cid, FOODS[2]))
        end
    else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
return true
end

This should work

Besides include the one Feature than i can't added before, the one of "What if must add less than 20" stuff

@tetra20 yeah, you are right about numbers, thanks

EDIT: Now i fix the "," issue
 
Last edited:
The Same Mistake :p
Won't Add code tags for you to see the place of mistake
doPlayerAddItem(uid,FOODS[2] , (100 - getPlayerItemCount(cid, FOODS[2]))
 
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--

function onCastSpell(cid, var)
local get = getPlayerPosition(cid)
  if getPlayerItemCount(cid, FOODS) <= 80 then
  if getPlayerLevel(cid) <= 20 then
  doPlayerAddItem(uid, FOODS[1], 20)
  doSendMagicEffect(get, CONST_ME_MAGIC_GREEN)
  elseif getPlayerLevel(cid) > 20 then
  doPlayerAddItem(uid, FOODS[2], 20)
  doSendMagicEffect(get, CONST_ME_MAGIC_GREEN)
  else
  doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
  end
  return true
end

Thanks For testing Pt Loot


Ok, so when i tried this, all the parts where it says uid gave me error, so i changed to cid and it worked..

Code:
[20/02/2014 10:29:29] [Error - Spell Interface]
[20/02/2014 10:29:29] data/spells/scripts/Mage/New/Conjure Refreshment.lua:onCastSpell
[20/02/2014 10:29:29] Description:
[20/02/2014 10:29:29] (luaDoPlayerAddItem) Player not found

I also had to change
Code:
if getPlayerItemCount(cid, FOODS) <= 80 then

to this

Code:
if getPlayerItemCount(cid, FOODS[1]) <= 80 then
^ so it can know which food to check for, i dont know why but it doesnt check all with that one command.. it just keeps adding.. when i added [1] it checked. But now i will have to add this with [2] for second part of the function

Also, the cancel message does not work.. If i have 90 and cast the spell, it will just cast spell and do nothing.. i want the msg to appear to warn the player they have too much food already..

Thank you!

and Im testing second script from @obs right now......
 
Code:
local FOODS = {XXXX, YYYY} -- Here put the ID of the food item/s--
local get = getPlayerPosition(cid)
local fot = if getPlayerLevel(cid) <= 20 then
                local fot = FOODS[1]
            elseif getPlayerLevel(cid) > 20 then
                local fot = FOODS[2]
            end
function onCastSpell(cid, var)
  if getPlayerItemCount(cid, FOODS) <= 80 then
      if getPlayerLevel(cid) <= 20 then
        doPlayerAddItem(uid, FOODS[1], 20, true)
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
      elseif getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid, FOODS[2], 20, true)
      end
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
    elseif getPlayerItemCount(cid, fot) > 80 and getPlayerLevel(cid) <= 20 then
        doPlayerAddItem(uid,FOODS[1],(100 - getPlayerItemCount(cid, FOODS[1])))
    elseif getPlayerItemCount(cid, fot) > 80 and getPlayerLevel(cid) > 20 then
        doPlayerAddItem(uid,FOODS[2],(100 - getPlayerItemCount(cid, FOODS[2])))
    else
      doSendAnimatedText(getPlayerPosition(cid), "El Hechizo no funciona, al parecer ya tienes demaciados", 1)
  end
  return true
end

You can try this one if you want.

@tetra20 i know is a little redundant, but if works then i filter it a little, you'll never can be so sure ;)
 
Back
Top