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

Lua [GOT] Help me to make 2 things

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I have a game of throne system, i found in other forum made by: Zipster98

But i need a help to change 2 things

I really need some help... Its much thing to me im trapped in it in 2 weeks, idk what to do now...

1- 1 guild per throne... 1 guild can get only 1 throne (max)...
I've tried:
Changes on movements (tile acess to start enter in castle)...
I added it
Code:
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerSendCancel(cid, "Your guild already has a throne dominated! Only one per guild.")
  doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  doTeleportThing(cid, fromPosition, true)
  return true
  end
  actionid = actionid + 1
  end

Full throne_capturing.lua:
Code:
local config = {
  level = 50,
  count = 1,
  messages = {
  [12003] = "[GOT-Kazz]The guild %s is entering the castle.",
  [12004] = "[GOT-Kazz]The guild %s is already inside the castle.",
  [12005] = "[GOT-Kazz]The guild %s is close to conquer the castle.",

  [12006] = "[GOT-Ab]The guild %s is entering the castle.",
  [12007] = "[GOT-Ab]The guild %s is already inside the castle.",
  [12008] = "[GOT-Ab]The guild %s is close to conquer the castle.",

  [12009] = "[GOT-Edron]The guild %s is entering the castle.",
  [12010] = "[GOT-Edron]The guild %s is already inside the castle.",
  [12011] = "[GOT-Edron]The guild %s is close to conquer the castle.",

  [12012] = "[GOT-Ankrahmun]The guild %s is entering the castle.",
  [12013] = "[GOT-Ankrahmun]The guild %s is already inside the castle.",
  [12014] = "[GOT-Ankrahmun]The guild %s is close to conquer the castle.",

  [12015] = "[GOT-Tiquanda]The guild %s is entering the castle.",
  [12016] = "[GOT-Tiquanda]The guild %s is already inside the castle.",
  [12017] = "[GOT-Tiquanda]The guild %s is close to conquer the castle.",

  [12018] = "[GOT-Rookgaard]The guild %s is entering the castle.",
  [12019] = "[GOT-Rookgaard]The guild %s is already inside the castle.",
  [12020] = "[GOT-Rookgaard]The guild %s is close to conquer the castle.",

  [12021] = "[GOT-Okolnir]The guild %s is entering the castle.",
  [12022] = "[GOT-Okolnir]The guild %s is already inside the castle.",
  [12023] = "[GOT-Okolnir]The guild %s is close to conquer the castle.",

  [12000] = "[GOT-Carlin]The guild %s is entering the castle.",
  [12001] = "[GOT-Carlin]The guild %s is already inside the castle.",
  [12002] = "[GOT-Carlin]The guild %s is close to conquer the castle."
  },
  actionId = {12000, 12023, 4819}
}

function tableInsert(table, value)
  -- technically this doesn't need to be #table + 1, it can just be #table
  table[#table + 1] = value
end

function onStepIn(cid, item, position, fromPosition)

  local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

  local function getGuildOnlineMembers(guildId)

  for _, cid in pairs(getPlayersOnline()) do  
  if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
  tableInsert(pid, cid)
  tableInsert(ip, getPlayerIp(cid))
  end
  end
  return pid
  end

  if not isPlayer(cid) then
  return true
  end

  if (item.actionid >= config.actionId[1] and item.actionid <= config.actionId[2]) then
  -- check if have players online (necessary)
  if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
  doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
  doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  doTeleportThing(cid, fromPosition, true)
  return true
  end
  -- check if have a throne owned
  actionid = 2391
  default_storage = 49198
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerSendCancel(cid, "Your guild already has a throne dominated! Only one per guild.")
  doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  doTeleportThing(cid, fromPosition, true)
  return true
  end
  actionid = actionid + 1
  end
  end

  if getGlobalStorageValue(item.actionid + config.actionId[3]) < os.time() then
  broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
  setGlobalStorageValue(item.actionid + config.actionId[3], os.time() + 60)
  end
  doCreatureSetSkullType(cid, 3)
  return true
end

But not work! i think i using worng values


2- A sign(ITEMID: 1429) in front the castles show which guild own the city
I've tried:
creaturescripts.xml
Code:
<event type="look" name="got_placas" event="script" value="GOT/placas.lua"/>

login.lua
Code:
registerCreatureEvent(cid, "got_placas")

GOT/placas.lua
Code:
function onLook(cid, thing, position, lookDistance)
  if (item.actionid == 3391) then
  local guildName = getGuildName(getGlobalStorageValue(2391 + DEFAULT_STORAGE))
  doPlayerSetSpecialDescription(item.actionid, "Carlin throne dominated by guild: " .. guildName .. " .")
  end
  return true
end

Not work... Errors on console:
Code:
[4:30:59.534] [Error - CreatureScript Interface]
[4:30:59.534] data/creaturescripts/scripts/GOT/placas.lua:onLook
[4:30:59.534] Description:
[4:30:59.534] data/creaturescripts/scripts/GOT/placas.lua:2: attempt to index global 'item' (a nil value)
[4:30:59.534] stack traceback:
[4:30:59.534]  data/creaturescripts/scripts/GOT/placas.lua:2: in function <data/creaturescripts/scripts/GOT/placas.lua:1>


FULL Code:
===========================================================
LIBs
===========================================================
/lib/GOTlib.lua
http://hastebin.com/emavetagoc.lua

===========================================================
Monsters
===========================================================
Code:
<monstername="Chanceler Carlin"file="GOT/chanceler carlin.xml"/>

chanceler carlin.xml
http://hastebin.com/piwobonawu.xml

===========================================================
Movemments
===========================================================
Code:
<movevent type="StepIn" actionid="12000-12100" event="script" value="GOT/throne_capturing.lua"/>
<movevent type="StepIn" actionid="2391-2398" event="script" value="GOT/tile_acess_members_of_throne.lua"/>

throne_capturing.lua
http://hastebin.com/atizibitim.lua

tile_acess_members_of_throne.lua
http://hastebin.com/icolesapel.lua

===========================================================
Creaturescripts
===========================================================
Code:
  <!-- Guild own throne +25%de exp -->
  <event type="death" name="mDeath" event="script" value="GOT/expbonus_got.lua"/>
  <event type="statschange" name="mStatsChange" event="script" value="GOT/expbonus_got.lua"/>
  <event type="target" name="mTarget" event="script" value="GOT/expbonus_got.lua"/>
  <event type="login" name="mLogin" event="script" value="GOT/expbonus_got.lua"/>

expbonus_got.lua
http://hastebin.com/ogabuyudid.lua
 
I overlooked the fact that cityMonsters are used other places as a means of checking if you killed a chanceler. I've edited my post.

Edit: The numbers in the "guardMonsters" table don't really matter. You can do
Code:
local guardMonsters = {
  ["Guard Rook"] = 1,
  ["Guard"] = 1,
}

If you want.

What i made worng to cancel attack if dont have members online and if no have guild (like is in movemments)
Code:
local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1, -- Carlin
  [2392] = 2, -- Kazz
  [2393] = 3, -- Ab
  [2394] = 4, -- Edron
  [2395] = 5, -- Ankrahmun
  [2396] = 6, -- Tiquanda
  [2397] = 7, -- Rookgaard
  [2398] = 8, -- Svargrond
  [2399] = 9, -- Dawnport
}

local config = {
  level = 50,
  count = 1
}

function onTarget(cid, target)
  local function getGuildOnlineMembers(guildId)
  for _, cid in pairs(getPlayersOnline()) do 
  if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
  tableInsert(pid, cid)
  tableInsert(ip, getPlayerIp(cid))
  end
  end
  return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
  if playerGuild == guildId then
  doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
  return false
  end
  end
  if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
  doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
  return false
  end
  end

  return true
end

function onStatsChange(cid, attacker, type, combat, value)
  if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
  local m, playerGuild = cityMonsters[getCreatureName(cid)], getPlayerGuildId(attacker)
  if m and playerGuild > 0 then
  return getGlobalStorageValue(DEFAULT_STORAGE + m) ~= playerGuild
  end
  end
  return true
end
function onLogin(cid)
  local guildId = getPlayerGuildId(cid)
  if guildId > 0 and getGuildExpRate(guildId) > 1 then
  doPlayerSetExperienceRate(cid, getGuildExpRate(guildId))
  end
  registerCreatureEvent(cid, "mTarget")
  registerCreatureEvent(cid, "mStatsChange")
  return true
end 
function onDeath(cid, corpse, deathList)
  local killer, m = deathList[1], cityMonsters[getCreatureName(cid)]
  if killer and isPlayer(killer) and m then
  local atualGuild, playerGuild = getPlayerStorageValue(cid, DEFAULT_STORAGE + m), getPlayerGuildId(killer)
  if playerGuild > 0 and atualGuild ~= playerGuild then
  if atualGuild > -1 then
  setGuildExperience(atualGuild, getGuildExpRate(atualGuild) - 0.25)
  end
  setGuildExperience(playerGuild, getGuildExpRate(playerGuild) + 0.25)
  setGlobalStorageValue(DEFAULT_STORAGE + m, playerGuild)
  broadcastMessage("The guild "..getPlayerGuildName(killer).." just dominate the throne of "..getCreatureName(cid):explode(" ")[2].."!")
  end
  end
  return true
end







==================================================


And what is this number?
Code:
local playerRate = getPlayerRates(pid)[8]

8


===================================================

Code:
[12:39:53.401] [Error - CreatureScript Interface]
[12:39:53.401] data/creaturescripts/scripts/GOT/placas.lua:onLook
[12:39:53.402] Description:
[12:39:53.402] data/lib/004-database.lua:100: [Result:free] Result not set!
[12:39:53.402] stack traceback:
[12:39:53.402]    [C]: in function 'error'
[12:39:53.402]    data/lib/004-database.lua:100: in function 'free'
[12:39:53.402]    data/lib/GOTlib.lua:37: in function 'getGuildName'
[12:39:53.402]    data/creaturescripts/scripts/GOT/placas.lua:22: in function <data/creaturescripts/scripts/GOT/placas.lua:14>

When don't have guild... It's can fix?
 
Last edited:
For 1.
I can't say I like the implementation, but to keep it simple and in the same fashion as onStepIn

Replace
Code:
function onTarget(cid, target)
  local function getGuildOnlineMembers(guildId)
  for _, cid in pairs(getPlayersOnline()) do
  if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
  tableInsert(pid, cid)
  tableInsert(ip, getPlayerIp(cid))
  end
  end
  return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
  if playerGuild == guildId then
  doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
  return false
  end
  end
  if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
  doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
  return false
  end
  end

  return true
end

with
Code:
function tableInsert(table, value)
  -- technically this doesn't need to be #table + 1, it can just be #table
  table[#table + 1] = value
end

function onTarget(cid, target)

  local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

  local function getGuildOnlineMembers(guildId)
    for _, cid in pairs(getPlayersOnline()) do
      if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
        tableInsert(pid, cid)
        tableInsert(ip, getPlayerIp(cid))
      end
    end
    return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
    for i=1,8,1 do
      local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
      if playerGuild == guildId then
        doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
        return false
      end
    end

    if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
      doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
      return false
    end
  end

  return true
end

For 2.
Looking at the sources it looks like
Code:
getPlayerRates(pid)[8]
gets the player rate for level. It might be something like stamina exp rate, because it does not look like it is the global stage exp table.

For 3.
Replace the getGuildName function in /lib/GOTlib.lua with:
Code:
function getGuildName(guild_id)  --Omega
  local query = db.getResult("SELECT name FROM guilds WHERE id = "..guild_id)
 
  if query:getID() ~= -1 then
    local ret = query:getDataString("name")
    query:free()
    return ret
  end
 
  return false
end
 
For 1.
I can't say I like the implementation, but to keep it simple and in the same fashion as onStepIn

Replace
Code:
function onTarget(cid, target)
  local function getGuildOnlineMembers(guildId)
  for _, cid in pairs(getPlayersOnline()) do
  if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
  tableInsert(pid, cid)
  tableInsert(ip, getPlayerIp(cid))
  end
  end
  return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
  if playerGuild == guildId then
  doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
  return false
  end
  end
  if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
  doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
  return false
  end
  end

  return true
end

with
Code:
function tableInsert(table, value)
  -- technically this doesn't need to be #table + 1, it can just be #table
  table[#table + 1] = value
end

function onTarget(cid, target)

  local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

  local function getGuildOnlineMembers(guildId)
    for _, cid in pairs(getPlayersOnline()) do
      if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
        tableInsert(pid, cid)
        tableInsert(ip, getPlayerIp(cid))
      end
    end
    return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
    for i=1,8,1 do
      local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
      if playerGuild == guildId then
        doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
        return false
      end
    end

    if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
      doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
      return false
    end
  end

  return true
end

For 2.
Looking at the sources it looks like
Code:
getPlayerRates(pid)[8]
gets the player rate for level. It might be something like stamina exp rate, because it does not look like it is the global stage exp table.

For 3.
Replace the getGuildName function in /lib/GOTlib.lua with:
Code:
function getGuildName(guild_id)  --Omega
  local query = db.getResult("SELECT name FROM guilds WHERE id = "..guild_id)

  if query:getID() ~= -1 then
    local ret = query:getDataString("name")
    query:free()
    return ret
  end

  return false
end

Ty again...

When look:
Code:
[23:38:18.736] [Error - CreatureScript Interface]
[23:38:18.736] data/creaturescripts/scripts/GOT/placas.lua:onLook
[23:38:18.736] Description:
[23:38:18.736] data/creaturescripts/scripts/GOT/placas.lua:41: attempt to concatenate local 'guildName' (a boolean value)
[23:38:18.736] stack traceback:
[23:38:18.736]    data/creaturescripts/scripts/GOT/placas.lua:41: in function <data/creaturescripts/scripts/GOT/placas.lua:14>


And when attack don't show nothing and don't stop attack (attacking with no guild)
 
onLook should be replace to something like this:
Code:
function onLook(cid, thing, position, lookDistance)
   if (thing.actionid == 3391) then
      local guildName = getGuildName(getGlobalStorageValue(guilds[2391] + DEFAULT_STORAGE))
      if guildName then
         doItemSetAttribute(thing.uid, "description", "Carlin throne dominated by guild: " .. guildName .. " .")
      else
         doItemSetAttribute(thing.uid, "description", "Carlin throne not dominated by any guild.")
      end
   end
   return true
end


Also onTarget:
Code:
function onTarget(cid, target)

  local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

  local function getGuildOnlineMembers(guildId)
    for _, cid in pairs(getPlayersOnline()) do
      if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
        tableInsert(pid, cid)
        tableInsert(ip, getPlayerIp(cid))
      end
    end
    return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m then
    if playerGuild > 0 then
      for i=1,8,1 do
        local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
        if playerGuild == guildId then
          doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
          return false
        end
      end
    end

    if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
      doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
      return false
    end
  end

  return true
end
 
onLook should be replace to something like this:
Code:
function onLook(cid, thing, position, lookDistance)
   if (thing.actionid == 3391) then
      local guildName = getGuildName(getGlobalStorageValue(guilds[2391] + DEFAULT_STORAGE))
      if guildName then
         doItemSetAttribute(thing.uid, "description", "Carlin throne dominated by guild: " .. guildName .. " .")
      else
         doItemSetAttribute(thing.uid, "description", "Carlin throne not dominated by any guild.")
      end
   end
   return true
end


Also onTarget:
Code:
function onTarget(cid, target)

  local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

  local function getGuildOnlineMembers(guildId)
    for _, cid in pairs(getPlayersOnline()) do
      if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
        tableInsert(pid, cid)
        tableInsert(ip, getPlayerIp(cid))
      end
    end
    return pid
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m then
    if playerGuild > 0 then
      for i=1,8,1 do
        local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
        if playerGuild == guildId then
          doPlayerPopupFYI(cid, 'You cannot start a throne war! Your guild have own a throne!')
          return false
        end
      end
    end

    if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
      doPlayerSendCancel(cid, "You need to be on guild or your guild must have at least "..config.count.." players level "..config.level.." or more.")
      return false
    end
  end

  return true
end


Everything was fixed thanks to you...
Thank you SO MUCH!
 
Back
Top