Ir para conteúdo
  • 0

-=[TFS - 0.3.6 - 8.60]=- ERRO NPC REVIVE


Muvuka

Pergunta

 

local COIN_ID = 6535 -- DexSoft Coin ID
local COIN_AMOUNT = 1 -- Amount of DexSoft Coins the player will need to revive
local MAGIC_EFFECT_TELEPORT = 65 -- Effect that will appear when the player is teleported

local PLAYER_REBORN_POSITION_X = 66541
local PLAYER_REBORN_POSITION_Y = 66542
local PLAYER_REBORN_POSITION_Z = 66543

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)				
    npcHandler:onCreatureAppear(cid)			
end

function onCreatureDisappear(cid)			
    npcHandler:onCreatureDisappear(cid)			
end

function onCreatureSay(cid, type, msg)			
    npcHandler:onCreatureSay(cid, type, msg)		
end

function onThink()					
    npcHandler:onThink()					
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, 'revive') then
        selfSay('You need ' .. COIN_AMOUNT .. ' DexSoft Coin(s) to resurrect at the location where you recently died.', cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if getPlayerItemCount(cid, COIN_ID) >= COIN_AMOUNT then
            doPlayerRemoveItem(cid, COIN_ID, COIN_AMOUNT)
            if teleportPlayerToPositionReborn(cid) then
                doTeleportThing(cid, {x = PLAYER_REBORN_POSITION_X, y = PLAYER_REBORN_POSITION_Y, z = PLAYER_REBORN_POSITION_Z})
                doSendMagicEffect(getCreaturePosition(cid), MAGIC_EFFECT_TELEPORT)
                selfSay('Ok, you have been resurrected.', cid)
            end
        else
            selfSay('Sorry, but you do not have enough DexSoft Coins.', cid)
        end
        talkState[talkUser] = 0
    elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
        talkState[talkUser] = 0
        selfSay('Ok, goodbye.', cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

function teleportPlayerToPositionReborn(cid)
    local playerRebornPositionX = getPlayerStorageValue(cid, PLAYER_REBORN_POSITION_X)
    local playerRebornPositionY = getPlayerStorageValue(cid, PLAYER_REBORN_POSITION_Y)
    local playerRebornPositionZ = getPlayerStorageValue(cid, PLAYER_REBORN_POSITION_Z)

    if playerRebornPositionX == -1 or playerRebornPositionY == -1 or playerRebornPositionZ == -1 then
        selfSay('You have not died yet.', cid)
        return false
    end

    doTeleportThing(cid, {x = playerRebornPositionX, y = playerRebornPositionY, z = playerRebornPositionZ})
    return true
end

 

 

 

[13/09/2024 14:16:35] [Error - Npc interface] 
[13/09/2024 14:16:35] data/npc/scripts/reviver.lua:onThink
[13/09/2024 14:16:35] Description: 
[13/09/2024 14:16:35] (luaGetCreatureName) Creature not found

[13/09/2024 14:16:35] [Error - Npc interface] 
[13/09/2024 14:16:35] data/npc/scripts/reviver.lua:onThink
[13/09/2024 14:16:35] Description: 
[13/09/2024 14:16:35] data/npc/lib/npcsystem/npchandler.lua:301: bad argument #3 to 'gsub' (string/function/table expected)
[13/09/2024 14:16:35] stack traceback:
[13/09/2024 14:16:35] 	[C]: in function 'gsub'
[13/09/2024 14:16:35] 	data/npc/lib/npcsystem/npchandler.lua:301: in function 'parseMessage'
[13/09/2024 14:16:35] 	data/npc/lib/npcsystem/npchandler.lua:538: in function 'onWalkAway'
[13/09/2024 14:16:35] 	data/npc/lib/npcsystem/npchandler.lua:473: in function 'onThink'
[13/09/2024 14:16:35] 	data/npc/scripts/reviver.lua:26: in function <data/npc/scripts/reviver.lua:25>
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 1

1. Corrigir o erro do gsub:

O erro de gsub ocorre quando o tipo de dado passado para ele não é válido. No caso do erro que você está recebendo, parece que o sistema está esperando uma string, mas recebeu outro tipo de valor.

2. Verificar o erro Creature not found:

Esse erro sugere que o NPC está tentando interagir com uma criatura (cid) que não existe ou foi removida do jogo. Pode ser resolvido verificando se o cid é uma criatura válida antes de tentar interagir com ele.

Sugestões de ajustes no código:

Função teleportPlayerToPositionReborn:
 

function teleportPlayerToPositionReborn(cid)
    if not isCreature(cid) then
        selfSay('Player not found.', cid)
        return false
    end

    local playerRebornPositionX = getPlayerStorageValue(cid, PLAYER_REBORN_POSITION_X)
    local playerRebornPositionY = getPlayerStorageValue(cid, PLAYER_REBORN_POSITION_Y)
    local playerRebornPositionZ = getPlayerStorageValue(cid, PLAYER_REBORN_POSITION_Z)

    if playerRebornPositionX == -1 or playerRebornPositionY == -1 or playerRebornPositionZ == -1 then
        selfSay('You have not died yet.', cid)
        return false
    end

    doTeleportThing(cid, {x = playerRebornPositionX, y = playerRebornPositionY, z = playerRebornPositionZ})
    return true
end
  • isCreature(cid): Verifica se o cid ainda é uma criatura válida antes de tentar acessá-la. Isso ajuda a evitar o erro Creature not found.

Função onThink:

Certifique-se de que o onThink está bem implementado no NPC:
 

function onThink()
    if not npcHandler:isFocused() then
        return false
    end
    npcHandler:onThink()
    return true
end

 

Link para o comentário
Compartilhar em outros sites

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...