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

Walking the npc to a pos

Gsp

RP
Joined
Jan 3, 2008
Messages
250
Solutions
1
Reaction score
4
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

function selfMoveTo(x, y, z)
local position = {x = 88, y = 58, z = 7}

if (msgcontains(msg, 'yes')) and (isValidPosition(position)) then
     doSteerCreature(getNpcId(), position)

   end
   
return true
end

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

hi guys =] i'm trying to make this npc walk to a position but it just stands still. i don't know what is wrong
i get no errors but it doesnt work. help!
 
I got no idea how it should work, but maaaybe change:
function selfMoveTo(x, y, z)
with:
function creatureSayCallback(cid, msg)
because now you set 'callback' to function that does not exist.
If target place (position) is too far from NPC it's possible that NPC can't find 'way to that position'.
 
thanks Gesior but didn't work. if you dont know how to do it i dont think anyone knows lol
i think i'll give up
 
thanks Gesior but didn't work. if you dont know how to do it i dont think anyone knows lol
i think i'll give up
I know Gesior is smart and all, but don't ever give up man. I wouldn't be scripting today, if I would've gave up on hard scripts. I'll try to help you find out what function to use after I get off work. :D
 
I'm Mega Noob&LOL :)
Didn't it show error in console about compare number with string or something?
It should be:
function creatureSayCallback(cid, type, msg)
without 'type' it tries to find 'yes' in variable type (just named 'msg'), not message, so NPC does nothing.
I got no idea what does:
(isValidPosition(position))
It must return true or 1 to make that script work. I think it's useless in this script.
 
I'm Mega Noob&LOL :)
Didn't it show error in console about compare number with string or something?
It should be:
function creatureSayCallback(cid, type, msg)
without 'type' it tries to find 'yes' in variable type (just named 'msg'), not message, so NPC does nothing.
I got no idea what does:
(isValidPosition(position))
It must return true or 1 to make that script work. I think it's useless in this script.
works! love you man.

final script

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

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

function creatureSayCallback(cid, type, msg)
local pos = {x = 88, y = 58, z = 7}

if (msgcontains(msg, 'yes')) then
     doSteerCreature(getNpcId(), pos)
     

   end
   
return true
end

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

by Gesior!
 
if it is close to the target it walks to it but it doesnt if the target is more than 7sqms away
i need it to move 20-25 sqms
 
if it is close to the target it walks to it but it doesnt if the target is more than 7sqms away
i need it to move 20-25 sqms
I had same problem when I tried to make 'bots'. You must add some table with 'positions of route' and make it go from point to point in 'think' event.
 
Never say never! :)
This is very simple 'walk by route' script, it can only walk once from X to Y position. If you want walk it back etc. - sorry, too much work :p
Code:
-- points, from place where NPC is at start to point we want reach, distance must be lower then 7 sqm between 2 positions one by one in table
local walkRoute = {
{x = 78, y = 65, z = 7},
{x = 83, y = 63, z = 7},
{x = 88, y = 58, z = 7} -- final destination point
}

local walkTo = 0 -- at start of OTS we don't walk anywhere

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

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

function onThink()
    if(walkTo ~= 0) then -- we set NPC to walk by route
        if(getDistanceBetween(getCreaturePosition(getNpcId()), walkRoute[walkTo]) > 1) then -- if NPC did not reach position, go to it
            doSteerCreature(getNpcId(), walkRoute[walkTo])
        elseif(#walkRoute > walkTo) then -- ok, we reached point, go to next point
            walkTo = walkTo + 1
        else -- we reach last point, we don't steer NPC anymore
            walkTo = 0
        end
    end
    npcHandler:onThink() -- here default NPC system code
end

function creatureSayCallback(cid, type, msg)
    if (msgcontains(msg, 'yes')) then
        -- make NPC walk from first point to end of out 'walkRoute'
        walkTo = 1
    end

    return true
end

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

If you really need this NPC (walk back etc.) I can make it for few euro :)
----------------------------------------------
To make my war ots bots walk around 'thais town map', don't stuck and don't look like idiots that go random places. I had to write around 7 KB code (just to walk + ~20KB to choose best target, use spells, runes, make combos etc.) and make JavaScript 'route' editor and draw on it over 30 routes, each with 4-7 positions:
EGjzPa.png
 
Back
Top