• 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!

Solved Get items on level depending on vocation Knight weapons issue!

Lightonia

Lightonia.servegame.com
Joined
Jun 4, 2007
Messages
492
Reaction score
9
I need help with knight weapons when it comes to getting items on level ( different each vocation)

My script is like this
Code:
local c = {
  [{1,5}] = {
  [15] = {items = {{itemid = 2188, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2189, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}, storage = 99965}
  },
  [{2,6}] = {
  [15] = {items = {{itemid = 2185, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2181, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}}, storage = 99965}
  },
  [{3,7}] = {
  [15] = {items = {{itemid = 2389, count = 5}}, storage = 99963},
  [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 99964},
  [60] = {items = {{itemid = 7367, count = 5}}, storage = 99965}
  },
  [{4,8}] = {
  [15] = {items = {{itemid = 2160, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 3}}, storage = 99964},
  [45] = {items = {{itemid = 2160, count = 1}, {itemid = 2160, count = 5}}, storage = 99965}
  }
}

function onAdvance(cid, skill, oldlevel, newlevel)
  if skill ~= SKILL_LEVEL then
  return true
  end

  for voc, x in pairs(c) do
  if isInArray(voc, getPlayerVocation(cid)) then
  for level, z in pairs(x) do
  if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
  local text = ""
  for v = 1, #z.items do
  count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
  local ret = ", "
  if v == 1 then
  ret = ""
  elseif v == #z.items then
  ret = " and "
  end
  text = text .. ret
  text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
  end
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
  setPlayerStorageValue(cid, z.storage, 1)
  end
  end
  end
  end
  return true

And i need knight weapons to be that it differs on wich skill is highest for instance you have 16 in Sword and 14 in Axe, you will get the Fire sword and not Fire axe.

Please tell me if you need me to clarify it.
Thanks!

Bump
 
Last edited by a moderator:
Creature Script

if isSorcerer = Sorcerer get item
if isKnight = Knight get item

Just change To your weapon id

doPlayerAddItem(cid, XXX,1)

and

if (newlevel >= 19

for your wanted level


Code:
function onAdvance(cid, type, oldlevel, newlevel)

if (oldlevel ~= newlevel and type == SKILL__LEVEL) then

    if (newlevel >= 19 and getPlayerStorageValue(cid, 37340) == -1) then
        if isSorcerer(cid) then
            doPlayerAddItem(cid, 2188, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Wand of Decay")
            setPlayerStorageValue(cid, 37340, 1)
        end
        if isDruid(cid) then
            doPlayerAddItem(cid, 2185, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Necrotic Rod")
            setPlayerStorageValue(cid, 37340, 1)
        end
        if isKnight(cid) then
            doPlayerAddItem(cid, 2409, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Serpent Sword")
            setPlayerStorageValue(cid, 37340, 1)
        end
    end
   
    if (newlevel >= 30 and getPlayerStorageValue(cid, 37341) == -1) then
        if isSorcerer(cid) then
            doPlayerAddItem(cid, 2189, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Wand of Cosmic Energy")
            setPlayerStorageValue(cid, 37341, 1)
        end
        if isDruid(cid) then
            doPlayerAddItem(cid, 2183, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Hailstorm Rod")
            setPlayerStorageValue(cid, 37341, 1)
        end
        if isKnight(cid) then
            doPlayerAddItem(cid, 2392, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Fire Sword")
            setPlayerStorageValue(cid, 37341, 1)
        end
    end
   
    if (newlevel >= 50 and getPlayerStorageValue(cid, 37342) == -1) then
        if isSorcerer(cid) then
            doPlayerAddItem(cid, 8920, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Wand of Starstorm")
            setPlayerStorageValue(cid, 37342, 1)
        end
        if isDruid(cid) then
            doPlayerAddItem(cid, 8912, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Springsprout Rod")
            setPlayerStorageValue(cid, 37342, 1)
        end
        if isKnight(cid) then
            doPlayerAddItem(cid, 7384, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You got a: Mystic Blade")
            setPlayerStorageValue(cid, 37342, 1)
        end
    end

   
end

return true
end
 
@Lightonia
You can add the axe and sword weapon in the table, then check for voc knight and remove 1 of the weapons from the table, so players only get 1 of them.
Under: if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
Code:
if isKnight(cid) then
     x = getPlayerSkill(cid, SKILL_SWORD) >= getPlayerSkill(cid, SKILL_AXE) and table.remove(z.items, 2) or table.remove(z.items, 1)
end
Then in the table, first one should be a sword, second one an axe and the table should be under function onAdvance.
 
@Limos
I did this but i get the error;
Code:
 data/creaturescripts/scripts/LevelUpp.lua:2: '{' expected near 'local'

Here is what i did
Code:
function onAdvance
local c = {
  [{1,5}] = {
  [15] = {items = {{itemid = 2188, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2189, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}, storage = 99965}
  },
  [{2,6}] = {
  [15] = {items = {{itemid = 2185, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2181, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}}, storage = 99965}
  },
  [{3,7}] = {
  [15] = {items = {{itemid = 2389, count = 5}}, storage = 99963},
  [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 99964},
  [60] = {items = {{itemid = 7367, count = 5}}, storage = 99965}
  },
  [{4,8}] = {
  [30] = {items = {{itemid = 7408, count = 1}}, storage = 99964},
  [30] = {items = {{itemid = 2430, count = 1}}, storage = 99965}
  }
}

function onAdvance(cid, skill, oldlevel, newlevel)
  if skill ~= SKILL_LEVEL then
  return true
  end

  for voc, x in pairs(c) do
  if isInArray(voc, getPlayerVocation(cid)) then
  for level, z in pairs(x) do
  if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
  if isKnight(cid) then
  x = getPlayerSkill(cid, SKILL_SWORD) >= getPlayerSkill(cid, SKILL_AXE) and table.remove(z.items, 2) or table.remove(z.items, 1)
end
  local text = ""
  for v = 1, #z.items do
  count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
  local ret = ", "
  if v == 1 then
  ret = ""
  elseif v == #z.items then
  ret = " and "
  end
  text = text .. ret
  text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
  end
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
  setPlayerStorageValue(cid, z.storage, 1)
  end
  end
  end
  end
  return true
 
Last edited:
This is function onAdvance in your script.
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
Move the table under that line.
Also add the 2 weapons in the table, first one should be the sword, second one the axe.
Code:
[30] = {items = {{itemid = 2392, count = 1}, {itemid = 2432, count = 1}}, storage = 99964},
 
Here is what i did
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
local c = {
  [{1,5}] = {
  [15] = {items = {{itemid = 2188, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2189, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}, storage = 99965}
  },
  [{2,6}] = {
  [15] = {items = {{itemid = 2185, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2181, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}}, storage = 99965}
  },
  [{3,7}] = {
  [15] = {items = {{itemid = 2389, count = 5}}, storage = 99963},
  [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 99964},
  [60] = {items = {{itemid = 7367, count = 5}}, storage = 99965}
  },
  [{4,8}] = {
  [30] = {items = {{itemid = 7408, count = 1},{itemid = 2430, count = 1}}, storage = 99964}
  }
}
  if skill ~= SKILL_LEVEL then
  return true
  end

  for voc, x in pairs(c) do
  if isInArray(voc, getPlayerVocation(cid)) then
  for level, z in pairs(x) do
  if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
  if isKnight(cid) then
  x = getPlayerSkill(cid, SKILL_SWORD) >= getPlayerSkill(cid, SKILL_AXE) and table.remove(z.items, 2) or table.remove(z.items, 1)
end
  local text = ""
  for v = 1, #z.items do
  count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
  local ret = ", "
  if v == 1 then
  ret = ""
  elseif v == #z.items then
  ret = " and "
  end
  text = text .. ret
  text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
  end
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
  setPlayerStorageValue(cid, z.storage, 1)
  end
  end
  end
  end
  return true

Here is the error i got;
Code:
data/creaturescripts/scripts/LevelUpp.lua:22: '}' exptected <to close '{' at line 2> near 'if'
 
[70] = {items = {{itemid = 2268, count = 50}}, storage = 99965}

Btw, I assume you didn't post the whole script? Because there is also an end missing at the end of the script (under return true).
 
It was the whole script, i added an end.
I won't get any errors now but i don't get any items either at the designated levels

Code:
function onAdvance(cid, skill, oldlevel, newlevel)
local c = {
  [{1,5}] = {
  [15] = {items = {{itemid = 2188, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2189, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}}, storage = 99965}
  },
  [{2,6}] = {
  [15] = {items = {{itemid = 2185, count = 1}}, storage = 99963},
  [30] = {items = {{itemid = 2181, count = 1}}, storage = 99964},
  [70] = {items = {{itemid = 2268, count = 50}}, storage = 99965}
  },
  [{3,7}] = {
  [15] = {items = {{itemid = 2389, count = 5}}, storage = 99963},
  [20] = {items = {{itemid = 2456, count = 1}, {itemid = 2544, count = 100}}, storage = 99964},
  [60] = {items = {{itemid = 7367, count = 5}}, storage = 99965}
  },
  [{4,8}] = {
  [30] = {items = {{itemid = 7408, count = 1},{itemid = 2430, count = 1}}, storage = 99964}
  }
}
  if skill ~= SKILL_LEVEL then
  return true
  end

  for voc, x in pairs(c) do
  if isInArray(voc, getPlayerVocation(cid)) then
  for level, z in pairs(x) do
  if newlevel >= level and getPlayerStorageValue(cid, z.storage) ~= 1 then
  if isKnight(cid) then
  x = getPlayerSkill(cid, SKILL_SWORD) >= getPlayerSkill(cid, SKILL_AXE) and table.remove(z.items, 2) or table.remove(z.items, 1)
end
  local text = ""
  for v = 1, #z.items do
  count, info = z.items[v].count, getItemDescriptions(z.items[v].itemid)
  local ret = ", "
  if v == 1 then
  ret = ""
  elseif v == #z.items then
  ret = " and "
  end
  text = text .. ret
  text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  doPlayerAddItem(cid, z.items[v].itemid, z.items[v].count)
  end
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you reached level "..level.." and received "..text..".")
  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREWORK_YELLOW)
  setPlayerStorageValue(cid, z.storage, 1)
  end
  end
  end
  end
  return true
  end
 
This script is made for TFS 0.2/1.0, to make it work for TFS 0.3/0.4, change SKILL_LEVEL to SKILL__LEVEL and getItemDescriptions to getItemInfo.
 
Thanks a bunch! It worked.
One last question, if i want to add a Club too, is this right?;
Code:
  if isKnight(cid) then
  x = getPlayerSkill(cid, SKILL_SWORD) >= getPlayerSkill(cid, SKILL_AXE) >=getPlayerSkill(cid, SKILL_CLUB) >= and table.remove(z.items, 2) and table.remove(z.items, 1) or table.remove(z.items, 3)
end
 
Back
Top