• 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:
Code:
if getPlayerLevel(cid) <= 20 then
     doPlayerAddItem(uid,fot,(Total_Max - getPlayerItemCount(cid, FOODS[1])))
     doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
elseif getPlayerLevel(cid) > 20 then
     doPlayerAddItem(uid,fot,(Total_Max - getPlayerItemCount(cid, FOODS[2])))
     doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
end
Is the same, but shorter:
Code:
if getPlayerLevel(cid) <= 20 then
     doPlayerAddItem(uid,fot,(Total_Max - getPlayerItemCount(cid, FOODS[1])))
elseif getPlayerLevel(cid) > 20 then
     doPlayerAddItem(uid,fot,(Total_Max - getPlayerItemCount(cid, FOODS[2])))
end
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_GREEN)
 
Back
Top