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

Request: Two NPCs

Alegres

You break it you buy it
Joined
Jun 27, 2009
Messages
325
Reaction score
14
Location
Wroclaw,Poland
Greetings. At first, i would like to say, that i know nothing about LUA. And that's why I'm asking you, may someone create two guys for me?

  • First one: he just walks around and shouts random sentences, if someone tries to say hello, he answers: "Leave me alone, weirdo" and he doesn't focus on a player
  • Second one: normal conversation, hi -> "Hello [player], im [npc name]... blablabla, [long story] -> bye -> Goodbye [player]

Thanks, Alegres.
 
First npc.
.lua file
Lua:
local random_texts = {'Send SMSes!', 'Make donations!', 'Send PayPal transfers!', 'There is no game without donation items!'}
local random_texts_chance = 50 -- percent
local random_texts_interval = 2 -- seconds

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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()
	if(getCreatureStorage(getNpcId(), 1) < os.time()) then
		doCreatureSetStorage(getNpcId(), 1, os.time() + random_texts_interval)
		if(math.random(1, 100) < random_texts_chance) then
			selfSay(random_texts[math.random(1, #random_texts)])
		end
	end
	npcHandler:onThink()
end

function bajbajer(cid, type, msg)
	selfSay('I am busy. I am spamming!',cid)
	return false
end

npcHandler:setCallback(CALLBACK_GREET, bajbajer)

npcHandler:addModule(FocusModule:new())
.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Walker" script="walker.lua" walkinterval="600">
	<health now="100" max="100"/>
	<look type="131" head="58" body="43" legs="38" feet="76" addons="0"/>
	<parameters>
	</parameters>
</npc>

Second NPC is a bit harder and I got no time today.

Movie:
[video=youtube;5GtTNKy38WM]http://www.youtube.com/watch?v=5GtTNKy38WM[/video]
 
Last edited:
I just read thet you wanted him to shout :p
Replace:
PHP:
selfSay(random_texts[math.random(1, #random_texts)])
with:
PHP:
selfSay(random_texts[math.random(1, #random_texts)], 0, TALKTYPE_YELL)
0 - player id 0 - doesn't exist, npc will speak on Default window
TALKTYPE_YELL - yell :)
 
Huh,
some kind of this? (0.3.6)

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Example" script="example.lua" walkinterval="0" floorchange="0">
	<health now="150" max="150"/>
	<look type="379" head="114" body="119" legs="114" feet="114" corpse="2212"/>
    <parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. Do you wanna hear my {story}?/>
    </parameters>
</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



	if(msgcontains(msg, 'history') or msgcontains(msg, 'talk')) then
		selfSay('Blablabla, do you wanna hear more?', cid)
		talkState[talkUser] = 1

	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		selfSay('Blablablabla...', cid)
		talkState[talkUser] = 0

	end



	return true

end



npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())


hmMmmM?
 
Back
Top