• 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 tried it to fix my second question, but not work

Code:
[16:17:36.127] [Error - CreatureScript Interface]
[16:17:36.127] data/creaturescripts/scripts/GOT/placas.lua:onLook
[16:17:36.127] Description:
[16:17:36.127] data/lib/004-database.lua:76: [Result:getDataString] Result not set!
[16:17:36.127] stack traceback:
[16:17:36.127]    [C]: in function 'error'
[16:17:36.127]    data/lib/004-database.lua:76: in function 'getDataString'
[16:17:36.127]    data/lib/GOTlib.lua:32: in function 'getGuildName'
[16:17:36.127]    data/creaturescripts/scripts/GOT/placas.lua:3: in function <data/creaturescripts/scripts/GOT/placas.lua:1>

Have you tried modifying getGuildName or OnLook to print out the value of guild_id or getGlobalStorageValue(2391 + DEFAULT_STORAGE)?
I suspect you don't use a valid guild_id.

Also the following won't solve your problem, but at least fix some logic:

Code:
local ret = query:getID() == -1 and false or query:getDataString("name")
on line 32 of data/lib/GOTlib.lua, is flawed.

That is even if (query:getID() == -1) evalutes to true, the "and false" can never be satisfied because false is obviously evaluated as false. Thus query:getDataString("name") is always called.

A workaround is reordering like this:
Code:
local ret = query:getID() ~= -1 and query:getDataString("name") or false
 
Finally somebody know something about it! Ty to your answer so much!!!!!!!!!!!!!!

I've tried to change my lib like you said
Code:
DEFAULT_STORAGE = 49198
function setGuildExperience(guildId, exp)
  for _, pid in pairs(getPlayersOnline()) do
  if getPlayerGuildId(pid) == guildId then
  doPlayerSetExperienceRate(pid, exp)
  end
  end
end
function getGuildExpRate(guildId)
  for _, pid in pairs(getPlayersOnline()) do
  local playerRate = getPlayerRates(pid)[8]
  if getPlayerGuildId(pid) == guildId and playerRate > 1 then
  return playerRate
  end
  end
  return 1.0
end
function getGuildName(guild_id)  --Omega
  local query = db.getResult("SELECT name FROM guilds WHERE id = "..guild_id)
  local ret = query:getID() ~= -1 and query:getDataString("name") or false
   print(query:getDataString("name"))
  query:free()
  return ret
end

Not work, onlook:
Code:
[15:25:38.106] [Error - CreatureScript Interface]
[15:25:38.106] data/creaturescripts/scripts/GOT/placas.lua:onLook
[15:25:38.106] Description:
[15:25:38.106] data/lib/004-database.lua:76: [Result:getDataString] Result not set!
[15:25:38.106] stack traceback:
[15:25:38.106]    [C]: in function 'error'
[15:25:38.106]    data/lib/004-database.lua:76: in function 'getDataString'
[15:25:38.106]    data/lib/GOTlib.lua:33: in function 'getGuildName'
[15:25:38.106]    data/creaturescripts/scripts/GOT/placas.lua:3: in function <data/creaturescripts/scripts/GOT/placas.lua:1>
 
Obviously you get the same error (just on a line below) because you are trying to call it anyway with:
Code:
print(query:getDataString("name"))

I'd like to see you change that to something like
Code:
print("[getGuildName] guild_id: ".. guild_id)

And then post what it outputs. I suspect that the number it prints out is not a valid guild id.

Looking at your code I do believe that you are using the wrong way to calculate the storage key.
For instance if we look at tile_acess_members_of_throne.lua:
Code:
  local guildId = getGlobalStorageValue(guilds[item.actionid] + DEFAULT_STORAGE)

Here guilds is the table:
Code:
local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1,
  [2392] = 2,
  [2393] = 3,
  [2394] = 4,
  [2395] = 5,
  [2396] = 6,
  [2397] = 7,
  [2398] = 8,
}

And thus the used storage key is the sum of a number from 1-8 and the value of "DEFAULT_STORAGE".
This does not coincide with yours in placas.lua:
Code:
local guildName = getGuildName(getGlobalStorageValue(2391 + DEFAULT_STORAGE))

Thus I would suggest trying
Code:
local guildName = getGuildName(getGlobalStorageValue(guilds[2391] + DEFAULT_STORAGE))
 
Obviously you get the same error (just on a line below) because you are trying to call it anyway with:
Code:
print(query:getDataString("name"))

I'd like to see you change that to something like
Code:
print("[getGuildName] guild_id: ".. guild_id)

And then post what it outputs. I suspect that the number it prints out is not a valid guild id.

Looking at your code I do believe that you are using the wrong way to calculate the storage key.
For instance if we look at tile_acess_members_of_throne.lua:
Code:
  local guildId = getGlobalStorageValue(guilds[item.actionid] + DEFAULT_STORAGE)

Here guilds is the table:
Code:
local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1,
  [2392] = 2,
  [2393] = 3,
  [2394] = 4,
  [2395] = 5,
  [2396] = 6,
  [2397] = 7,
  [2398] = 8,
}

And thus the used storage key is the sum of a number from 1-8 and the value of "DEFAULT_STORAGE".
This does not coincide with yours in placas.lua:
Code:
local guildName = getGuildName(getGlobalStorageValue(2391 + DEFAULT_STORAGE))

Thus I would suggest trying
Code:
local guildName = getGuildName(getGlobalStorageValue(guilds[2391] + DEFAULT_STORAGE))

Ty so mcuh, dont let me alone, i just need it to finish my server
I think im using the worng values

Because there is 3 things not work
1 Stop attack if have a throne owned
Code:
  actionid = 2391
  default_storage = 49198
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
  return true
  end
  actionid = actionid + 1
  end

2 Stop enter if have a throne owned
Code:
  local actid = 2391
  local default_storage = 49198
  local idguild = 0
  for i=1,8,1 do
  local city = 2391 + i
  idguild = getGlobalStorageValue(city + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == idguild 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
  end

3 And this read signs, i tried what u said, but not work
Code:
function onLook(cid, thing, position, lookDistance)
   if (thing.actionid == 3391) then
     local guildName = getGuildName(getGlobalStorageValue(guilds[2391] + DEFAULT_STORAGE))
    doSetItemSpecialDescription(thing.uid, "Carlin throne dominated by guild: " .. guildName .. " .")
   end
   return true
end

Errors
Code:
[14:5:30.369] [Error - CreatureScript Interface]
[14:5:30.369] data/creaturescripts/scripts/GOT/placas.lua:onLook
[14:5:30.369] Description:
[14:5:30.369] data/creaturescripts/scripts/GOT/placas.lua:3: attempt to index global 'guilds' (a nil value)
[14:5:30.369] stack traceback:
[14:5:30.369]    data/creaturescripts/scripts/GOT/placas.lua:3: in function <data/creaturescripts/scripts/GOT/placas.lua:1>

And ty so much to try help me, i really need it
 
Yeah, forgive me, for some reason I thought the guilds table was in lib. Anyway you could move it there (would recommend changing the name to something more specific then), or you could copy it to placas.

That is copy:
Code:
local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1,
  [2392] = 2,
  [2393] = 3,
  [2394] = 4,
  [2395] = 5,
  [2396] = 6,
  [2397] = 7,
  [2398] = 8,
}

and insert at the top of placas.lua
 
I've tried
Code:
local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1,
  [2392] = 2,
  [2393] = 3,
   [2394] = 4,
   [2395] = 5,
   [2396] = 6,
   [2397] = 7,
   [2398] = 8,
  [2399] = 10,
}

function onLook(cid, thing, position, lookDistance)
   if (thing.actionid == 3391) then
     local guildName = getGuildName(getGlobalStorageValue(guilds[2391] + DEFAULT_STORAGE))
    doSetItemSpecialDescription(thing.uid, "Carlin throne dominated by guild: " .. guildName .. " .")
   end
   return true
end

But when look:
Code:
[6:6:12.165] [Error - CreatureScript Interface]
[6:6:12.165] data/creaturescripts/scripts/GOT/placas.lua:onLook
[6:6:12.165] Description:
[6:6:12.165] data/creaturescripts/scripts/GOT/placas.lua:17: attempt to call global 'doSetItemSpecialDescription' (a nil value)
[6:6:12.166] stack traceback:
[6:6:12.166]    data/creaturescripts/scripts/GOT/placas.lua:17: in function <data/creaturescripts/scripts/GOT/placas.lua:14>


Tile acess if have owned thron IS WORKING \/
Code:
local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1,
  [2392] = 2,
  [2393] = 3,
  [2394] = 4,
  [2395] = 5,
  [2396] = 6,
  [2397] = 7,
  [2398] = 8,
  [2399] = 10,
}
   
function onStepIn(cid, item, position, fromPosition)
  if not isPlayer(cid) then return true end
  local guildId = getGlobalStorageValue(guilds[item.actionid] + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) ~= guildId then
  doTeleportThing(cid, fromPosition)
     doPlayerSendCancel(cid, 'This territory is not of your Guild')
  end
  return true
end

But it not work:
Code:
  -- check if have a throne owned
  local actid = 2391
  local default_storage = 49198
  local idguild = 0
  for i=1,8,1 do
  local city = 2391 + i
  idguild = getGlobalStorageValue(city + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == idguild 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
  end

From this script
Code:
local config = {
  level = 50,
  count = 1,
  messages = {
  [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.",

  [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-Rook]The guild %s is entering the castle.",
  [12019] = "[GOT-Rook]The guild %s is already inside the castle.",
  [12020] = "[GOT-Rook]The guild %s is close to conquer the castle.",

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

  [12024] = "[GOT-Dawnport]The guild %s is entering the castle.",
  [12025] = "[GOT-Dawnport]The guild %s is already inside the castle.",
  [12026] = "[GOT-Dawnport]The guild %s is close to conquer the castle."
  },
  actionId = {12000, 12026, 4819}
}

local guilds = {
  --[actionid] = número da cidade configurado em cityMonsters,
  [2391] = 1,
  [2392] = 2,
  [2393] = 3,
  [2394] = 4,
  [2395] = 5,
  [2396] = 6,
  [2397] = 7,
  [2398] = 8,
  [2399] = 10,
}

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
  end

  -- check if have a throne owned
  local actid = 2391
  local default_storage = 49198
  local idguild = 0
  for i=1,8,1 do
  local city = 2391 + i
  idguild = getGlobalStorageValue(city + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == idguild 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
  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


And this part not work too
Code:
  actionid = 2391
  default_storage = 49198
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
  return true
  end
  actionid = actionid + 1
  end

From this script
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] = 10, -- Dawnport
}

function onTarget(cid, target)   
  actionid = 2391
  default_storage = 49198
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
  return true
  end
  actionid = actionid + 1
  end

  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
  return getGlobalStorageValue(DEFAULT_STORAGE + m) ~= playerGuild
  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

Idk why, but Chanceler Carlin is stoping attack but dont show:
doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')

But the others still attacking


:( :(

Ty so much to your help!!! Dont let me alone xD
 
It looks like your engine doesn't have the doSetItemSpecialDescription function.
By looking at the sources in the link you provided I was able to find this function:

Code:
doItemSetAttribute(uid, key, value)

Thus you can try to replace:
Code:
doSetItemSpecialDescription(thing.uid, "Carlin throne dominated by guild: " .. guildName .. " .")
with
Code:
doItemSetAttribute(thing.uid, "description", "Carlin throne dominated by guild: " .. guildName .. " .")

I'm a little conflicted on your method of setting this attribute each time onLook is triggered, but I guess it would do for now.

Futhermore you should replace:

Code:
  -- check if have a throne owned
  local actid = 2391
  local default_storage = 49198
  local idguild = 0
  for i=1,8,1 do
  local city = 2391 + i
  idguild = getGlobalStorageValue(city + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == idguild 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
  end

with

Code:
  -- check if have a throne owned
  for i=1,8,1 do
    local idguild = getGlobalStorageValue(i + DEFAULT_STORAGE)
      if getPlayerGuildId(cid) == idguild 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
  end

And also:

Code:
  actionid = 2391
  default_storage = 49198
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
  return true
  end
  actionid = actionid + 1
  end

with

Code:
  for i=1,8,1 do
    local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
    if getPlayerGuildId(cid) == guildId then
      doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
      return false
    end
  end
 
when you fix, tell me... i want use it too
It's almost finish...

It looks like your engine doesn't have the doSetItemSpecialDescription function.
By looking at the sources in the link you provided I was able to find this function:

Code:
doItemSetAttribute(uid, key, value)

Thus you can try to replace:
Code:
doSetItemSpecialDescription(thing.uid, "Carlin throne dominated by guild: " .. guildName .. " .")
with
Code:
doItemSetAttribute(thing.uid, "description", "Carlin throne dominated by guild: " .. guildName .. " .")

I'm a little conflicted on your method of setting this attribute each time onLook is triggered, but I guess it would do for now.

Futhermore you should replace:

Code:
  -- check if have a throne owned
  local actid = 2391
  local default_storage = 49198
  local idguild = 0
  for i=1,8,1 do
  local city = 2391 + i
  idguild = getGlobalStorageValue(city + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == idguild 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
  end

with

Code:
  -- check if have a throne owned
  for i=1,8,1 do
    local idguild = getGlobalStorageValue(i + DEFAULT_STORAGE)
      if getPlayerGuildId(cid) == idguild 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
  end

And also:

Code:
  actionid = 2391
  default_storage = 49198
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(actionid + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
  return true
  end
  actionid = actionid + 1
  end

with

Code:
  for i=1,8,1 do
    local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
    if getPlayerGuildId(cid) == guildId then
      doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
      return false
    end
  end

TYYYYYYYYYYYYYY man so much, just fix 2 little problems

1- When i look at a flag... why its print in console?

10:58 You see a castle flag.
Carlin throne dominated by guild: Dark Side .
ItemID: [1436], ActionID: [3391].

print on console
Code:
Dark Side
Dark Side
Dark Side
Dark Side

2- Remove target to every monster

Did u know how to remove target only to monsters:
Chanceler Carlin, Chanceler AB, Guard?

Code:
function onTarget(cid, target)   
  for i=1,8,1 do
  local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
  if getPlayerGuildId(cid) == guildId then
  doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
  return false
  end
  end
 
For number 1: I'm guessing you haven't removed:

Code:
print(query:getDataString("name"))

from /lib/GOTlib.lua (in the function getGuildName, should be around line 33)

And for number 2:

In expbonus_got.lua.. I assume the onTarget function now looks something like this:
Code:
function onTarget(cid, target)
  for i=1,8,1 do
    local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
    if getPlayerGuildId(cid) == guildId then
      doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
      return false
    end
  end
  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
  return getGlobalStorageValue(DEFAULT_STORAGE + m) ~= playerGuild
  end
  return true
end

Replace it with this:
Code:
function onTarget(cid, target)
  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 attack a chanceler! You have own a throne!')
        return false
      end
    end
  end

  return true
end
 
For number 1: I'm guessing you haven't removed:

Code:
print(query:getDataString("name"))

from /lib/GOTlib.lua (in the function getGuildName, should be around line 33)

And for number 2:

In expbonus_got.lua.. I assume the onTarget function now looks something like this:
Code:
function onTarget(cid, target)
  for i=1,8,1 do
    local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
    if getPlayerGuildId(cid) == guildId then
      doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
      return false
    end
  end
  local m, playerGuild = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid)
  if isPlayer(cid) and isMonster(target) and m and playerGuild > 0 then
  return getGlobalStorageValue(DEFAULT_STORAGE + m) ~= playerGuild
  end
  return true
end

Replace it with this:
Code:
function onTarget(cid, target)
  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 attack a chanceler! You have own a throne!')
        return false
      end
    end
  end

  return true
end

You really save me... Ty so much...

Just one thing last, ontarget
Code:
function onTarget(cid, target)
  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 attack a chanceler! You have own a throne!')
  return false
  end
  end
  end

  return true
end

How to block target to monsters: 'Guard' and 'Guard Rook'
 
I'm not sure if you want the exact same behaviour on guards as on chandelers (can't attack if you own a throne), but if so then you can replace the onTarget function with this:

Code:
local guardMonsters = {
  ["Guard Rook Carlin"] = 1,
  ["Guard Carlin"] = 1,


  ["Guard Venore"] = 2,
  ["Guard Rook Venore"] = 2,

  ["Guard Thais"] = 3,
  ["Guard Rook Thais"] = 3,

  ["Guard Darashia"] = 4,
  ["Guard Rook Darashia"] = 4,

  ["Guard Ankrahmun"] = 5,
  ["Guard Rook Ankrahmun"] = 5,

  ["Guard Edron"] = 6,
  ["Guard Rook Edron"] = 6,

  ["Guard Rookgaard"] = 7,
  ["Guard Rook Rookgaard"] = 7,

  ["Guard Svargrond"] = 8,
  ["Guard Rook Svargrond"] = 8,

}

function onTarget(cid, target)
  local m, playerGuild, mg = cityMonsters[getCreatureName(target)], getPlayerGuildId(cid), guardMonsters[getCreatureName(target)]
  if isPlayer(cid) and isMonster(target) and playerGuild > 0 then
    if m or mg then
      local canAttack = true

      --- Check if you own a throne
      for i=1,8,1 do
        local guildId = getGlobalStorageValue(i + DEFAULT_STORAGE)
        if playerGuild == guildId then
          canAttack = false
          break
        end
      end

      --- Give appropriate message if you do own a throne.
      if not canAttack then
        if m then
          doPlayerPopupFYI(cid, 'You cannot attack a chanceler! You have own a throne!')
          return false
        else
          doPlayerPopupFYI(cid, 'You cannot attack a guard! You have own a throne!')
          return false
        end
      end 
    end
  end


  return true
end
 
Last edited:
If you are fine with it using the same message on all monsters, i.e "You cannot attack a chanceler! You have own a throne!", and also the guards have different names from each city:

Look at the file /lib/GOTlib.lua, you can edit the table:
Code:
cityMonsters = {
  --["monster_name"] = recomendo número anterior + 1,
  ["Chanceler Carlin"] = 1,
  ["Chanceler Venore"] = 2,
  ["Chanceler Thais"] = 3,
  ["Chanceler Darashia"] = 4,
  ["Chanceler Ankrahmun"] = 5,
  ["Chanceler Edron"] = 6,
  ["Chanceler Rookgaard"] = 7,
  ["Chanceler Svargrond"] = 8,
  --etc
}

Say to something like this:
Code:
cityMonsters = {
  --["monster_name"] = recomendo número anterior + 1,
  ["Chanceler Carlin"] = 1,
  ["Guard Carlin"] = 1,
  ["Guard Rook Carlin"] = 1,

  ["Chanceler Venore"] = 2,
  ["Guard Venore"] = 2,
  ["Guard Rook Venore"] = 2,

  ["Chanceler Thais"] = 3,
  ["Guard Thais"] = 3,
  ["Guard Rook Thais"] = 3,

  ["Chanceler Darashia"] = 4,
  ["Guard Darashia"] = 4,
  ["Guard Rook Darashia"] = 4,

  ["Chanceler Ankrahmun"] = 5,
  ["Guard Ankrahmun"] = 5,
  ["Guard Rook Ankrahmun"] = 5,

  ["Chanceler Edron"] = 6,
  ["Guard Edron"] = 6,
  ["Guard Rook Edron"] = 6,

  ["Chanceler Rookgaard"] = 7,
  ["Guard Rookgaard"] = 7,
  ["Guard Rook Rookgaard"] = 7,

  ["Chanceler Svargrond"] = 8,
  ["Guard Svargrond"] = 8,
  ["Guard Rook Svargrond"] = 8,
  --etc
}

You can obviously change the names to something else.

So i need to change:
local playerRate = getPlayerRates(pid)[9] (to add darashia)

And to guards i could make something like this? When killl a guard i dont will capture the city... Right?
Code:
cityMonsters = {
  --["monster_name"] = recomendo número anterior + 1,
  ["Chanceler Carlin"] = 1,
  ["Chanceler Kazz"] = 2,
  ["Chanceler Ab"] = 3,
  ["Chanceler Edron"] = 4,
  ["Chanceler Ankrahmun"] = 5,
  ["Chanceler Tiquanda"] = 6,
  ["Chanceler Rookgaard"] = 7,
  ["Chanceler Svargrond"] = 8,
  ["Chanceler Darashia"] = 9,
  ["Guard"] = 10,
  ["Guard Rook"] = 11,
  --etc
}

I need to change in monsters.xml
and add this mDeath thing?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Guard Rook" nameDescription="Guard Rook" race="blood" experience="0" speed="0" manacost="0">
   <health now="500" max="500"/>
   <look type="131" head="0" body="0" legs="0" feet="0" addons="3" corpse="6080"/>
   <flags>
     <flag summonable="0"/>
     <flag attackable="1"/>
     <flag hostile="1"/>
     <flag illusionable="0"/>
     <flag convinceable="0"/>
     <flag pushable="0"/>
     <flag canpushitems="1"/>
     <flag canpushcreatures="1"/>
     <flag targetdistance="1"/>
   </flags>
   <attacks>
     <attack name="melee" interval="2000" skill="30" attack="40"/>
     <attack name="physical" interval="1000" chance="7" range="3" min="-10" max="-25">
       <attribute key="shootEffect" value="spear"/>
     </attack>
   </attacks>
   <defenses armor="9" defense="11">
     <defense name="healing" interval="1000" chance="9" min="40" max="80">
       <attribute key="areaEffect" value="blueshimmer"/>
     </defense>
     <defense name="healing" interval="1000" chance="17" min="20" max="40">
       <attribute key="areaEffect" value="blueshimmer"/>
     </defense>
   </defenses>
   <immunities>
     <immunity lifedrain="1"/>
     <immunity paralyze="1"/>
     <immunity invisible="1"/>
   </immunities>
   <voices interval="5000" chance="10">
     <voice sentence="Attack!" yell="1"/>
   </voices>
  <script>
  <event name="mDeath"/>
  </script>
</monster>
 
Full code:
Code:
cityMonsters = {
  --["monster_name"] = recomendo número anterior + 1,
  ["Chanceler Carlin"] = 1,
  ["Chanceler Kazz"] = 2,
  ["Chanceler Ab"] = 3,
  ["Chanceler Edron"] = 4,
  ["Chanceler Ankrahmun"] = 5,
  ["Chanceler Tiquanda"] = 6,
  ["Chanceler Rookgaard"] = 7,
  ["Chanceler Svargrond"] = 8,
  ["Chanceler Darashia"] = 9,
  ["Guard"] = 10,
  ["Guard Rook"] = 11,
  --etc
}
DEFAULT_STORAGE = 49198
function setGuildExperience(guildId, exp)
  for _, pid in pairs(getPlayersOnline()) do
  if getPlayerGuildId(pid) == guildId then
  doPlayerSetExperienceRate(pid, exp)
  end
  end
end
function getGuildExpRate(guildId)
  for _, pid in pairs(getPlayersOnline()) do
  local playerRate = getPlayerRates(pid)[9]
  if getPlayerGuildId(pid) == guildId and playerRate > 1 then
  return playerRate
  end
  end
  return 1.0
end
function getGuildName(guild_id)  --Omega
  local query = db.getResult("SELECT name FROM guilds WHERE id = "..guild_id)
  local ret = query:getID() ~= -1 and query:getDataString("name") or false
  query:free()
  return ret
end
 
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.
 
Last edited:
Back
Top