• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Why it don't work? [Creaturescript]

debouas

New Member
Joined
Aug 14, 2015
Messages
44
Reaction score
0
Why this creaturescript don't work?

When advanced X ml show Y spell... Why?

Code:
local spells = {
  [1] = { --sorcerer
  level = {
  [10] = "1spell", "spell1",
  [20] = "2spell", "spell2"
  }
  },

  [2] = { --druid
  level = {
  [1] = "spell", "spell",
  [5] = "spell", "spell"
  }
  },
  [3] = { --paladin
  level = {
  [1] = "spell", "spell",
  [5] = "spell", "spell"
  }
  },

  [4] = { --knight
  level = {
  [1] = "1spell", "spell1",
  [5] = "2spell", "spell2"
  }
  }
}
local array_sorc = {"Sorcerer", "Master Sorcerer"}
local array_druid = {"Druid", "Elder Druid"}
local array_paladin = {"Paladin", "Royal Paladin"}
local array_knight = {"Knight", "Elite Knight"}
local text = ""
function onAdvance(cid, skill, oldLevel, newLevel)
if skill == SKILL__MAGLEVEL then
  player = Player(cid)
  if isInArray(array_sorc, player:getVocation()) then
  CONFIG = spells[1]
  elseif isInArray(array_druid, player:getVocation()) then
  CONFIG = spells[2]
  elseif isInArray(array_paladin, player:getVocation()) then
  CONFIG = spells[3]
  elseif isInArray(array_knight, player:getVocation()) then
  CONFIG = spells[4]
  end
  if not CONFIG then return false end
  EVENT = CONFIG.level[player:getMagLevel()]
  if not EVENT then
  return false
  end
  for i, v in ipairs(EVENT) do
  text = text..""..i..", "
  end
  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "New spells: "..text.."")
  end
  return true
end
 
Not all code is universal even with a compat.lua file, this is why people need to stop thinking this method of writing code is the correct method or they will wake up one day and find the compat file gone.

Some might think that using a direct access method to a metatable is an intelligent way to code, its not, this is why classes & libraries were created and implemented into a language.

I'll give you an example Jquery; if classes or libraries didn't exist then neither would Jquery, because all it is, is a library, its core language is javascript (with a little html, css, xml), meaning every time you wanted to do something fancy with the page you would have to write an excessively large amount of code.

@topic if your not using 1.x that code won't even execute let alone work.
Use this instead, its written in pure lua no tfs required, you can run it in a lua interpreter while saved in the root directory of your server (where the config.lua file is )
This will create a file called spells.lua, you will need to adjust the vocs table to that of correct vocations as the script isn't perfect, you can do 1 of 2 things with the file, you can leave it as is and just use require in your script and the path to the file or you can continue to add to the script in the same file.
https://otland.net/threads/lua-spells-parser-complete.236308/
 
Back
Top