• 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 event request

Elgenady

Veteran OT User
Joined
Aug 5, 2011
Messages
1,638
Solutions
35
Reaction score
352
i want npc for event gave player 10 token and teleported player to postion
 
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
	local c = { 
		tokenid = 1234, 			-- id of the token
		num = 10,					-- number of tokens
		pos = {x=100, y=100, z=7} 	-- teleport position
		}

	if(msgcontains(msg, 'event')) then
		selfSay('Do you have the '..c.num..' tokens?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if getPlayerItemCount(cid, c.tokenid) >= c.num then
			doPlayerRemoveItem(cid, c.tokenid, c.num)
			doTeleportThing(cid, c.pos)
			selfSay('Good luck.', cid)
		else
			selfSay("Sorry, you don\'t have the "..c.num.." tokens.", cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
i want npc work like this

player: hi

npc welcome to event reward npc

player reward

and npc gave player 10 token and teleport player to pos someone can do it ? tfs 3.6
 
i want npc gave 10 token for player and teleport player to temple

example

player say : hi

Npc say : welcome to reward npc

player say : reward

and then npc gave 10 token for player and teleport him to temple

( sorry for bad english , but that i have :S )
 
storage value? something?

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
	local c = { 
		tokenid = 1234, -- id of the token
		num = 10, -- number of tokens
		pos = {x=100, y=100, z=7} -- teleport position
		}
 
	if(msgcontains(msg, 'event')) then
		selfSay('Congratulations! You win the event, are you prepared to be teleported?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if INSERT_FUNCTION_HERE then
			doPlayerAddItem(cid, c.tokenid, c.num)
			doTeleportThing(cid, c.pos)
			selfSay('Good luck.', cid)
		else
			selfSay("Sorry, you don\'t win the event.", cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
16:48 Eventur: Welcome, Herotom! I have been expecting you.
16:48 Grats [785]: event
16:48 Eventur: Congratulations! You win the event, are you prepared to be teleported?
16:48 Grats [785]: yes
16:48 Eventur: Sorry, you don't win the event.

and don't tp me :S i want npc work like this

Player : hi

npc : welcome to reward npc say reward to take ur reward

player : reward

and then player take 10 token and teleport to temple
 
The xml of the NPC is just for the name/looktype/greetmessage etc. You can copy any NPC you have and change this. Of course also change the lua file directory and if it sells/buys items delete that part or take an xml of an NPC that doesn't have this.
 
look limos this first script streamside posted \/

21:02 Eventur: Welcome, Swae! I have been expecting you.
21:02 Swae [785]: event
21:02 Eventur: Do you have the 10 tokens?
21:02 Swae [785]: yes
21:02 Eventur: Sorry, you don't have the 10 tokens.


please fix it i want npc gave 10 token to player and teleport him to temple
 
And what happens after that? The NPC should give the 10 tokens again when the player comes back to the NPC or is this just for one time, and if it's just for one time, what should happen with the teleport part, it will teleport without getting tokens?
 
should works

>npc/NPCNAME.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NPCNAME" script="event.lua" walkinterval="2000" floorchange="0">
	<health now="150" max="150"/>
	<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
    <parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|."/>
    </parameters>
</npc>

>npc/scripts/event.lua
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
	local c = { 
		tokenid = 1234, -- id of the token
		num = 10, -- number of tokens
		temple = false,
		pos = {x=1000, y=1000, z=6} -- teleport position
		}
 
	if(msgcontains(msg, 'event')) then
		selfSay('Congratulations! You win the event, are you prepared to be teleported?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		doPlayerAddItem(cid, c.tokenid, c.num)
		doTeleportThing(cid, (c.temple and getTownTemplePosition(getPlayerTown(cid))) or c.pos)
		selfSay('Good luck.', cid)
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

you can config all...

Lua:
	local c = { 
		tokenid = 1234, -- id of the token
		num = 10, -- number of tokens
		temple = false, -- tp to temple or pos (true to temple, false to configurable pos)
		pos = {x=1000, y=1000, z=6} -- teleport position if temple = false
		}
 
Last edited:
Back
Top