Olá, @Vodkart e @Kemmlly! Muito obrigado pela resposta... Pelo o que eu entendi, sempre que eu pedi informação pela query eu devo checar se alguma data retornou.
Por isso usa o
if (resulta:getID ~= -1)
porque se não tiver valor ele continua o script para obter um valor, não é isso?
Eu andei especulando um pouco e meu movement ficou assim
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if isPlayer(cid) then
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
if item.actionid == 2518 then
if getPlayerGuildId(cid) ~= 0 then
if getPlayerGuildName(cid) == guild:getDataString("guild") then
doTeleportThing(cid, {x=2526,y=1525,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
else
doTeleportThing(cid, {x=2526,y=1548,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
end
else
doTeleportThing(cid, {x=1430,y=1240,z=9})
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa fazer parte de uma guild para poder participar desse evento.")
doSendMagicEffect(getCreaturePosition(cid), 10)
end
elseif item.actionid == 50093 then
if getPlayerStorageValue(cid, 50093) > os.time() then
doTeleportThing(cid, {x=2526,y=1525,z=7})
doSendMagicEffect({x=2526,y=1525,z=7}, 13)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
else
doTeleportThing(cid, {x=2486,y=1508,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
end
elseif item.actionid == 50094 then
if getPlayerStorageValue(cid, 50093) > os.time() then
doTeleportThing(cid, {x=2526,y=1548,z=7})
doSendMagicEffect({x=2526,y=1548,z=7}, 13)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Você precisa esperar " .. (getPlayerStorageValue(cid, 50093)-os.time()) .. " segundos para poder voltar.")
else
doTeleportThing(cid, {x=2483,y=1550,z=7})
doSendMagicEffect(getCreaturePosition(cid), 10)
end
elseif item.actionid == 50095 then
local posEntrando = {
{x=1488,y=1201,z=7},
{x=1489,y=1201,z=7},
{x=1490,y=1201,z=7},
{x=1491,y=1201,z=7},
{x=1536,y=1232,z=6},
{x=1537,y=1232,z=6}
}
local posSaindo = {
{x=1488,y=1203,z=7},
{x=1489,y=1203,z=7},
{x=1490,y=1203,z=7},
{x=1491,y=1203,z=7},
{x=1534,y=1234,z=6},
{x=1535,y=1234,z=6},
{x=1536,y=1234,z=6},
{x=1537,y=1234,z=6}
}
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
if getPlayerStorageValue(cid, 50095) < os.time() then
for t=1,#posEntrando do
if (fromPosition.x == posEntrando[t].x and fromPosition.y == posEntrando[t].y and fromPosition.z == posEntrando[t].z) then
if guild:getID() ~= -1 and guild:getDataString("guild") ~= "" then
doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Bem vindo à cidade de Agniter, controlada pela guild "..guild:getDataString("guild")..".")
doPlayerSetStorageValue(cid, 50095, os.time() + 60)
end
end
end
for t=1,#posSaindo do
if (fromPosition.x == posSaindo[t].x and fromPosition.y == posSaindo[t].y and fromPosition.z == posSaindo[t].z) then
if guild:getID() ~= -1 and guild:getDataString("guild") ~= "" then
doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,"Você está deixando Agniter, cidade controlada pela guild "..guild:getDataString("guild")..".")
doPlayerSetStorageValue(cid, 50095, os.time() + 60)
end
end
end
end
end
end
return true
end
Os erros pararam... poreeem, eu me dei conta de que para eu testar se o script está funcionando ou não eu preciso tambem arrumar os scripts do creaturescript... Eles ocorrem quando eu tento atacar o "king", e tentar arrumar eles fugiu da minha capacidade... apesar de ser a mesma lógica, eu acho... Vocês podem me ajudar?
Castle-war.lua
function onStatsChange(cid, attacker, type, combat, value)
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
if combat == COMBAT_HEALING then
return true
end
if getCreatureName(cid) == "King" then
if isPlayer(attacker) then
if getPlayerGuildName(attacker) == guild:getDataString("guild") then
return false
else
local gid = getPlayerGuildId(attacker)
local result = db.getResult("SELECT * FROM castles_war WHERE guild_id="..gid.." AND time="..getGlobalStorageValue(50094)..";")
if(result:getID() ~= -1) then
db.executeQuery("UPDATE `castles_war` SET `damage`=`damage`+"..value.." WHERE `guild_id`="..getPlayerGuildId(attacker).." AND `time`="..getGlobalStorageValue(50094)..";")
else
db.executeQuery("INSERT INTO `castles_war` (`castle_id` ,`guild_id` ,`damage` ,`time`)VALUES ('1', '"..gid.."', '0', '"..getGlobalStorageValue(50094).."');")
end
end
end
end
return true
end
Castle-wars2.lua
function onKill(cid, target, lastHit)
local pt = getPlayerStorageValue(cid, 50097)
if getCreatureName(target) == "King" then
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
local resulta = db.getResult("SELECT * FROM `castles_war` WHERE `time`="..getGlobalStorageValue(50094).." ORDER BY `damage` DESC LIMIT 1;")
local winnerteam = resulta:getDataInt("guild_id")
local result2 = db.getResult("SELECT * FROM guilds WHERE id="..winnerteam..";")
local name = result2:getDataString("name")
broadcastMessage("A guild "..name.." conquistou o castelo e agora precisa defender este por 10 minutos!", MESSAGE_EVENT_ADVANCE)
db.executeQuery("UPDATE castle_wars SET guild=\""..name.."\" WHERE id=1;")
setGlobalStorageValue(50094, os.time())
secondtime()
end
return true
end
function secondtime()
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
local ArenaGW1 = { frompos = {x=2471,y=1504,z=6}, topos = {x=2529,y=1560,z=7} }
addEvent(checa, 10*60*1000, guild:getDataString("guild"), getGlobalStorageValue(50094))
doCreateMonster('Castle King', {x=2486,y=1510,z=7},false,true)
for _, player in ipairs(getPlayersOnline()) do
if isInRange(getCreaturePosition(player), ArenaGW1.frompos, ArenaGW1.topos) then
if getPlayerGuildName(player) == guild:getDataString("guild") then
doTeleportThing(player, {x=2486,y=1509,z=7})
doSendMagicEffect({x=2486,y=1509,z=7}, 10)
doRemoveConditions(player)
else
doTeleportThing(player, {x=2526,y=1548,z=7})
doSendMagicEffect({x=2526,y=1548,z=7}, 10)
doRemoveConditions(player)
doPlayerSetStorageValue(player, 50093, os.time() + 30)
end
end
end
end
function checa(guild1,ostime)
local id = getThingfromPos({x=1445,y=1273,z=7,stackpos=0}).actionid - 50000
local guild = db.getResult("SELECT `guild` FROM `castle_wars` WHERE `id` = " .. id .." ORDER BY `id` DESC;")
local king = getThingfromPos({x=2486,y=1510,z=7,stackpos=STACKPOS_TOP_CREATURE})
if guild1 == guild:getDataString("guild") and ostime == getGlobalStorageValue(50094) then
broadcastMessage("O Castle Wars acabou! A guild "..guild:getDataString("guild").." conseguiu conquistar o castelo! Todos os jogadores serão teleportados para fora do evento em 30 minutos, ou poderão sair a qualquer hora pelos teleports no castelo.", MESSAGE_EVENT_ADVANCE)
doRemoveCreature(king.uid)
addEvent(cleanp, 30*60*1000)
end
end
function cleanp()
local ArenaGW1 = { frompos = {x=2471,y=1504,z=6}, topos = {x=2529,y=1560,z=7} }
local temple = {x=1447,y=1252,z=7}
doCreateItem(3708, {x=1433,y=1241,z=9,stackpos=1})
for _, player in ipairs(getPlayersOnline()) do
if isInRange(getCreaturePosition(player), ArenaGW1.frompos, ArenaGW1.topos) then
doTeleportThing(player, temple)
doSendMagicEffect(temple, 10)
end
end
end
erro que retorna ao atacar:
[Error - CreatureScript Interface]
data/creaturescripts/scripts/efferus/castle-wars.lua:onStatsChange
Description:
data/lib/004-database.lua:82: [Result:getDataString] Result not set!
stack traceback:
[C]: in function 'error'
data/lib/004-database.lua:82: in function 'getDataString'
data/creaturescripts/scripts/efferus/castle-wars.lua:9: in function <data/creaturescripts/scripts/efferus/castle-wars.lua:1>
Muito obrigado denovo pelo suporte à comunidade =)