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

NPC RPG - Royal Fufu

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
Have you thought about creating a NPC with artificial intelligence ?
I 've thought , and created !

This NPC I created will walk through a pre determined way , and will return.
He will speak some cool phrases too, automatically.
On the route that the NPC does , it stops for a while. The moment he stops, means that it is opening a box.


The script was pretty big , because I don't have many skills, but I'm offering because it works. And someone with more skills can make the best script yet!

On the map of my server, this NPC walks between two points , this includes up and down a ladder
Function from NPC on my server , is to take items from a box to another box located on the map.

End. The script is working perfectly. I'm just sharing for improvement!
 
Royal Fufu.lua
Code:
-- [[ Feito por Anderson (BomBa)]]

waypoint_royalFufu = 971714008
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local msgs = {
"Que meus inimigos sejam fortes e bravos para que eu nao sinta remorsos ao derrota-los",
"Voce deve se fazer uma pergunta: 'Estou com sorte?",
"Nunca se ouviu dizer que filho valente tivera nascido de pai temeroso.",
"Nunca comece uma briga, mas sempre a termine.",
"Eu me pergunto qual seria melhor, ser temido ou respeitado? Seria de mais pedir os dois. ",
}

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

local function greet(cid)
    return false
end

function onThink()
    local pos = getCreaturePosition(getNpcCid())
    -- indo
    if getGlobalStorageValue(waypoint_royalFufu) <= 0 then
        doTeleportThing(getNpcCid(), {x=1011, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 1)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 1 then
        doTeleportThing(getNpcCid(), {x=1010, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 2)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 2 then
        doTeleportThing(getNpcCid(), {x=1009, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 3)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 3 then
        doTeleportThing(getNpcCid(), {x=1008, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 4)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 4 then
        doTeleportThing(getNpcCid(), {x=1007, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 5)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 5 then
        doTeleportThing(getNpcCid(), {x=1006, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 6)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 6 then
        doTeleportThing(getNpcCid(), {x=1005, y=1357, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 7)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 7 then
        doTeleportThing(getNpcCid(), {x=1005, y=1358, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 8)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 8 then
        doTeleportThing(getNpcCid(), {x=1005, y=1360, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 9)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 9 then
        doTeleportThing(getNpcCid(), {x=1005, y=1361, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 10)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 10 then
        doTeleportThing(getNpcCid(), {x=1005, y=1362, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 11)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 11 then
        doTeleportThing(getNpcCid(), {x=1005, y=1363, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 12)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 12 then
        doTeleportThing(getNpcCid(), {x=1005, y=1364, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 13)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 13 then
        doTeleportThing(getNpcCid(), {x=1005, y=1365, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 14)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 14 then
        doTeleportThing(getNpcCid(), {x=1005, y=1366, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 15)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 15 then
        doTeleportThing(getNpcCid(), {x=1005, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 16)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 16 then
        doTeleportThing(getNpcCid(), {x=1006, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 17)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 17 then
        doTeleportThing(getNpcCid(), {x=1007, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 18)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 18 then
        doTeleportThing(getNpcCid(), {x=1008, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 19)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 19 then
        doTeleportThing(getNpcCid(), {x=1008, y=1366, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 20)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 20 then
        doTeleportThing(getNpcCid(), {x=1008, y=1365, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 21)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 21 then
        doTeleportThing(getNpcCid(), {x=1008, y=1364, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 22)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 22 then
        doTeleportThing(getNpcCid(), {x=1008, y=1363, z=7}, true)
        doCreatureSetLookDir(getNpcCid(), WEST)
        addEvent(setGlobalStorageValue, 20000, waypoint_royalFufu, 23)

    -- voltando
    elseif getGlobalStorageValue(waypoint_royalFufu) == 23 then
        doTeleportThing(getNpcCid(), {x=1008, y=1364, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 24)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 24 then
        doTeleportThing(getNpcCid(), {x=1008, y=1365, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 25)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 25 then
        doTeleportThing(getNpcCid(), {x=1008, y=1366, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 26)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 26 then
        doTeleportThing(getNpcCid(), {x=1008, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 27)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 27 then
        doTeleportThing(getNpcCid(), {x=1007, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 28)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 28 then
        doTeleportThing(getNpcCid(), {x=1006, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 29)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 29 then
        doTeleportThing(getNpcCid(), {x=1005, y=1367, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 30)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 30 then
        doTeleportThing(getNpcCid(), {x=1005, y=1366, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 31)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 31 then
        doTeleportThing(getNpcCid(), {x=1005, y=1365, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 32)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 32 then
        doTeleportThing(getNpcCid(), {x=1005, y=1364, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 33)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 33 then
        doTeleportThing(getNpcCid(), {x=1005, y=1363, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 34)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 34 then
        doTeleportThing(getNpcCid(), {x=1005, y=1362, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 35)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 35 then
        doTeleportThing(getNpcCid(), {x=1005, y=1361, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 36)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 36 then
        doTeleportThing(getNpcCid(), {x=1005, y=1360, z=7}, true)
        setGlobalStorageValue(waypoint_royalFufu, 37)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 37 then
        doTeleportThing(getNpcCid(), {x=1005, y=1358, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 38)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 38 then
        doTeleportThing(getNpcCid(), {x=1006, y=1358, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 39)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 39 then
        doTeleportThing(getNpcCid(), {x=1007, y=1358, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 40)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 40 then
        doTeleportThing(getNpcCid(), {x=1008, y=1358, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 41)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 41 then
        doTeleportThing(getNpcCid(), {x=1009, y=1358, z=6}, true)
        setGlobalStorageValue(waypoint_royalFufu, 42)
    elseif getGlobalStorageValue(waypoint_royalFufu) == 42 then
        doTeleportThing(getNpcCid(), {x=1010, y=1357, z=6}, true)
        doCreatureSetLookDir(getNpcCid(), SOUTH)
        addEvent(setGlobalStorageValue, 20000, waypoint_royalFufu, 0)
    end

    -- falas
    local falarA = math.random(1, 100000)
    if falarA <= 500 then
        doCreatureSay(getNpcCid(), msgs[math.random(#msgs)], TALKTYPE_SAY)
    end

    return true
end

npcHandler:addModule(FocusModule:new())
npcHandler:setCallback(CALLBACK_GREET, greet)

In globalevents, look for 'init.lua' and paste it:
Code:
setGlobalStorageValue(waypoint_royalFufu, 0)

 
Last edited:
Just use a table to store the coordinates or write a function to determine the walk cycle

Something like this

Code:
-- [[ Feito por Anderson (BomBa)]]

waypoint_royalFufu = 971714008
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local msgs = {
"Que meus inimigos sejam fortes e bravos para que eu nao sinta remorsos ao derrota-los",
"Voce deve se fazer uma pergunta: 'Estou com sorte?",
"Nunca se ouviu dizer que filho valente tivera nascido de pai temeroso.",
"Nunca comece uma briga, mas sempre a termine.",
"Eu me pergunto qual seria melhor, ser temido ou respeitado? Seria de mais pedir os dois. ",
}

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

local function greet(cid)
    return false
end

function walk(pos, dir)
    local p = dir % 2 == 0 and 'x' or 'y'
    if isInArray({2, 3}, dir) then
        pos[p] = pos[p] + 1
    else
        pos[p] = pos[p] - 1
    end
    doTeleportThing(getNpcCid(), pos, true)
end

function getAndSet(storage, max)
    local value = getGlobalStorageValue(storage)
    if value >= max then
        -- reset
        setGlobalStorageValue(storage, 0)
        return
    end
    setGlobalStorageValue(storage, value + 1)
end

local steps = 6
local count = 0
local direction = 0

function onThink()
    local pos = getCreaturePosition(getNpcCid())
    getAndSet(waypoint_royalFufu, 22)
    if count < steps then
        walk(pos, direction)
        count = count + 1
    else
        -- reset
        count = 0
        if direction > 3 then
            direction = 0
        else
            direction = direction + 1
        end
        -- update the npc look direction
        doCreatureSetLookDir(getNpcCid(), direction)
    end


    -- falas
    local falarA = math.random(1, 100000)
    if falarA <= 500 then
        doCreatureSay(getNpcCid(), msgs[math.random(#msgs)], TALKTYPE_SAY)
    end

    return true
end

npcHandler:addModule(FocusModule:new())
npcHandler:setCallback(CALLBACK_GREET, greet)
 
Last edited:
Now he's walking in a circle. I think something like this, maybe:
Code:
-- walk
[1] = {{x = 1011, y = 1357, z = 6}, {x = 1005, y = 1357, z = 6}}, -- from position, to position
[2] = {{x = 1005, y = 1357, z = 6}, {x = 1005, y = 1358, z = 6}}, -- from position, to position
[4] = {{x = 1005, y = 1360, z = 7}}, -- only down stair
[5] = {{x = 1005, y = 1360, z = 7}, {x = 1005, y = 1367, z = 7}}, -- from position, to position
[6] = {{x = 1005, y = 1367, z = 7}, {x = 1008, y = 1367, z = 7}}, -- from position, to position
 
Back
Top