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

[Tutorial] Your first home made npc!

Mokerhamer

Retired Global Mod
Senator
Joined
Aug 6, 2007
Messages
1,767
Reaction score
36
Hello,

Today we are starting with an new Tutorial, I will teach YOU how to creat an Boat Npc and i will explain what eatch function does.

Message for the Mods: Do not add Code Tags i have an good reason for it
====================Start=================

The first line is alwais the Npc information sutch as Name,access,flourchange etc..

We will first start with an .XML file

<npc name="Captain Steven" --The name of the Npc
script="data/npc/scripts/travel.lua" --Where is the .Lua file located
autowalk="1" ------Do u allow the npc to walk? 1= yes 0=no
floorchange="0" ----Do u allow the npc to use stairs? 1=Yes 0=No
access="5" ---Do u allow the npc to use commands that u added in the script? If no Lower the access but there will be an change that players are able to kill the npc, The npc wont respawn only with an restart.
level="1" ---- You can set the lvl of the npc for example if it's an guard
maglevel="1"> ---- You can set the lvl of the npc for example if it's an guard


Line 2 and 3 in the .xml file

<health now="150" max="150"/> ---The Hp of the npc ofcourse
<look type="133" head="20" body="120" legs="75" feet="13" corpse="2212"/> --How the npc should look like

Npc parameters the parameters are for the responce of the npc

<parameters>
<parameter key="module_travel" value="1" /> ----What for function is it, since we are maiking an travel npc it will be module_travel
<parameter key="travel_destinations" ---Dont edit this line
value="derelin,1294,429,6,119;farda,865,251,6,123" /> ----The place where the player should travel. this is an example how to make it work.

derelin,1294,429,6,119
Cityname,X,Y,Z,Price to travel.
If you want to add more city's simply add ";" example
derelin,1294,429,6,119;farda,865,251,6,123

<parameter key="module_keywords" value="1" /> ---Dont edit this line
<parameter key="keywords" value="job;name;offer" /> ---This is on what commands the npc reacts, if you want to add more just add ; just dont forget to add lines with the number
<parameter key="keyword_reply1" value="This if for job" />
<parameter key="keyword_reply2" value="this is for name" />
<parameter key="keyword_reply3" value="this is for offer" />
</parameters>
</npc>

the .xml should look somting like this
Code:
<npc name="Captain Steven" script="data/npc/scripts/travel.lua" autowalk="1" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="133" head="20" body="120" legs="75" feet="13" corpse="2212"/>

 <parameters>
        <parameter key="module_travel" value="1" />
        <parameter key="travel_destinations" value="derelin,1294,429,6,119;farda,865,251,6,123;taqinata,868,690,6,134" />
 
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="job;name;offer" />
        <parameter key="keyword_reply1" value="this is for job" />
        <parameter key="keyword_reply2" value="this is for offer name" />
        <parameter key="keyword_reply3" value="this is for offer" />
    </parameters>
</npc>


The .Lua file


I cant say mutch about this script since it's an basic script, This script redirects lines to global.lua so the npc will respond when u say/hi/bye/ and more things

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
 
 
-- OTServ event handling functions start
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
-- OTServ event handling functions end
 
 
 
-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())




I made this Tutorial as an request i know it's not the best but it will explain a bit, Ofcourse i will make more but the would be complex so keep learning =)

Yours,
Mokerhamer
 
You forgot to add addons for the first line, I would add it but too lazy and busy :(
 
@Mokerhamer
This will help many people, good job!
 
You forgot to add addons for the first line, I would add it but too lazy and busy :(

Not yet i will add it in the future the first need to learn the basic of npc maiking i know i added the parameters but i think it's basic to

@Mokerhamer
This will help many people, good job!

Thank you =)
 
To many noobie questions have been asked so i'm bumping this thread!
 
Hey is there a way to make npcs being pushable? I have 2 city guards on my server that will attack anyone with skull.

Now if someone gets trapped somewhere with these guards, they can only die to get out of there. So I need a function to be able to push the npc.
 
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Dimral" script="default.lua" walkinterval="0" floorchange="0">
<health now="150" max="150"/>
<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
<parameters>
<parameter key="module_travel" value="1"/>
<parameter key="message_greet" value="Hello |PLAYERNAME|. If you don't know where to flow, say {travel}."/>
<parameter key="travel_destinations" value="excelsior,803,1237,6,50;"/>
</parameters>
</npc>

This is the script im useing, it just doesnt tp the player to the other boat and i dono why. plz help?
 
Back
Top