• 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 NPC script not work perfect

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Reaction score
9
Location
NYC
Hey here is a part of my code of NPC:

Lua:
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
  
    -- Bruce lutará novamente o jogador que o derrotar? [true/false]
    local fight_again = false  
  
    if msgcontains(msg, "challenge") then
        if fight_again and getPlayerStorageValue(cid, 692) < os.time() then
            selfSay("So you want to fight? Get ready to die!")
            local pos = getThingPos(getNpcCid())
            local summonName = getCreatureName(getNpcCid())
            local lookdir = getCreatureLookDirection(cid)
            doRemoveCreature(getNpcCid())
            local summonCid = doCreateMonster(summonName, pos)
            doCreatureSetLookDirection(summonCid, lookdir)
            addEvent(checkForBruce, 5000, summonName)
        else
            selfSay("Oh, I can not fight with you anymore", cid)
        end
    end
    return true  
end

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

function checkForBruce(name)
    local Bruce = isCreature(getCreatureByName("Mecha Frieza")) and getCreatureByName("Mecha Frieza") or false
    if isNpc(Bruce) then
        return false
    end
    if not Bruce then
        Bruce = isCreature(getCreatureByName("Mecha Frieza_evolved")) and getCreatureByName("Mecha Frieza_evolved") or Bruce
    end
    if isCreature(getCreatureTarget(Bruce)) then
        addEvent(checkForBruce, 5000, name)
        return true
    else
        local pos = getThingPos(Bruce)
        doRemoveCreature(Bruce)
        doCreateNpc(name, pos)
    end
end

The problem is, that everytime i'm getting "selfSay("Oh, I can not fight with you anymore", cid)" please help me guys!

#EDIT It's working when I change from false to true the fight_again
 
Last edited:
If you only get ("Oh, I can not fight with you anymore", cid)"

the problem is here =

local fight_again = false

if fight_again and getPlayerStorageValue(cid, 692) < os.time() then

fight = false.
then if fight = false return the message=
"Oh, I can not fight with you anymore"

Set local fight_again = true
 
If you only get ("Oh, I can not fight with you anymore", cid)"

the problem is here =

local fight_again = false

if fight_again and getPlayerStorageValue(cid, 692) < os.time() then

fight = false.
then if fight = false return the message=
"Oh, I can not fight with you anymore"

Set local fight_again = true
Yes but i don't want to fight with him again. Just one time
 
Yes but i don't want to fight with him again. Just one time
Try this =
Code:
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
    -- Bruce lutará novamente o jogador que o derrotar? [true/false]
    local fight_again = false 
    if msgcontains(msg, "challenge") and fight_again == false then
        if (getPlayerStorageValue(cid, 15321) == -1) and getPlayerStorageValue(cid, 692) < os.time() then
            setPlayerStorageValue(cid, 15321 == 0)
            selfSay("So you want to fight? Get ready to die!")
            local pos = getThingPos(getNpcCid())
            local summonName = getCreatureName(getNpcCid())
            local lookdir = getCreatureLookDirection(cid)
            doRemoveCreature(getNpcCid())
            local summonCid = doCreateMonster(summonName, pos)
            doCreatureSetLookDirection(summonCid, lookdir)
            addEvent(checkForBruce, 5000, summonName)
        else
            selfSay("Oh, I can not fight with you anymore", cid)
        end
    end
   
        if msgcontains(msg, "challenge") and fight_again == true then
        if getPlayerStorageValue(cid, 692) < os.time() then
            selfSay("So you want to fight? Get ready to die!")
            local pos = getThingPos(getNpcCid())
            local summonName = getCreatureName(getNpcCid())
            local lookdir = getCreatureLookDirection(cid)
            doRemoveCreature(getNpcCid())
            local summonCid = doCreateMonster(summonName, pos)
            doCreatureSetLookDirection(summonCid, lookdir)
            addEvent(checkForBruce, 5000, summonName)
        else
            selfSay("Oh, I can not fight with you anymore", cid)
        end
    end
   
    return true 
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
function checkForBruce(name)
    local Bruce = isCreature(getCreatureByName("Mecha Frieza")) and getCreatureByName("Mecha Frieza") or false
    if isNpc(Bruce) then
        return false
    end
    if not Bruce then
        Bruce = isCreature(getCreatureByName("Mecha Frieza_evolved")) and getCreatureByName("Mecha Frieza_evolved") or Bruce
    end
    if isCreature(getCreatureTarget(Bruce)) then
        addEvent(checkForBruce, 5000, name)
        return true
    else
        local pos = getThingPos(Bruce)
        doRemoveCreature(Bruce)
        doCreateNpc(name, pos)
    end
end
 
Back
Top