• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Monster Arena (READ)

exique

Natala-ot.com
Joined
Sep 28, 2008
Messages
1,673
Reaction score
25
Location
Sweden
I want this:

A npc that creates monsters.
Player: Hi
Npc: Hello |PLAYERNAME| {arena}.
Player: Arena
Npc: I can make Penguins, Demons, Flamingos, Ghazbarans, Orshabaals and Amazons.
Player: Penguin
Npc: How many penguins would you like me to create?
Player: 3
Npc: Are you sure?
Player: Yes

And he creates 3 penguins!
Reputation (Ofc) :thumbup:
 
:untested:

Code:
local monsters = {"demon", "ghazbaran"}
local monster = {}
local count = {}

if (msg == "arena" and talkState[talkUser] < 1) then
	local msg = "I can summon "
	for i = 1, #monsters
		if (i == 1) then
			msg = msg .." ".. monsters[i]
		else
			msg = msg ..", ".. monsters[i]
		end
	end
	npcHandler:selfSay(msg, cid)
	talkState[talkUser] = 1
elseif (isInArray(monsters, msg) and talkState[talkUser] == 2) then
	monster[talkUser] = msg
	talkState[talkUser] = 3
elseif (msg and talkState[talkUser] == 3) then
	if (msg.type == 'number') then
		count[talkUser] = msg
		talkState[talkUser] = 4 
	else
		npcHandler:selfSay("Uuuu it's not a number!", cid)
		talkState[talkUser] = 0
	end
elseif (msg == "yes" and talkState[talkUser] == 4) then
	for i = 1, count[talkUser] do
		doSummonCreature(monster[talkUser], getCreaturePosition(cid))
	end
	count[talkUser] = 0
	monster[talkUser] = 0
	talkState[talkUser] = 0
end
 
Code:
local monsters = {"demon", "ghazbaran"}
local monster = {}
local count = {}

if (msg == "arena" and talkState[talkUser] < 1) then
    local msg = "I can summon "
    for i = 1, #monsters
    do    if (i == 1) then
            msg = msg .." ".. monsters[i]
        else
            msg = msg ..", ".. monsters[i]
        end
    end
    npcHandler:selfSay(msg, cid)
    talkState[talkUser] = 1
elseif (isInArray(monsters, msg) and talkState[talkUser] == 2) then
    monster[talkUser] = msg
    talkState[talkUser] = 3
elseif (msg and talkState[talkUser] == 3) then
    if (msg.type == 'number') then
        count[talkUser] = msg
        talkState[talkUser] = 4 
    else
        npcHandler:selfSay("Uuuu it's not a number!", cid)
        talkState[talkUser] = 0
    end
elseif (msg == "yes" and talkState[talkUser] == 4) then
    for i = 1, count[talkUser] do
        doSummonCreature(monster[talkUser], getCreaturePosition(cid))
    end
    count[talkUser] = 0
    monster[talkUser] = 0
    talkState[talkUser] = 0
end

He doesn't talk to me! I can't say hi! So I added:
Code:
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()                npcHandler:onThink()                    end

npcHandler:addModule(FocusModule:new())
And now he answers on "hi"..
But!
Nothing happens when you say arena :S
 
Fix:

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

local monsters = {"wolf", "rat"}
local monster = {}
local count = {}


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, 'arena')) then
	local msgs = "I can summon "
	for i = 1, #monsters do
	local monsteryy = monsters[i]
		if (i == 1) then
			msgs = msgs .." ".. monsters[i]
		else
			msgs = msgs ..", ".. monsters[i]
		end
	end
	selfSay(msgs, cid)
	talkState[talkUser] = 1
elseif (isInArray(monsters, msg) and talkState[talkUser] == 1) then
	monster[talkUser] = msg
	talkState[talkUser] = 2
	selfSay("Enter number of monsters.", cid)
elseif (string.find(msg, "[1-9]") and talkState[talkUser] == 2) then
		count[talkUser] = msg
		talkState[talkUser] = 3 
selfSay("Want to try your hand?", cid)
elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
	for i = 1, count[talkUser] do
		doSummonCreature(monster[talkUser], getCreaturePosition(cid))
	end
	count[talkUser] = 0
	monster[talkUser] = 0
	talkState[talkUser] = 0
end

	
	
	
	
	return true
end
	
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Nope, it will print error "no space" or smth like dat. Use getClosestFreeTile

@GSMaster:
Don't do it! If someone is not able to split piece of code with NPC, he should not have OTServ :P
 
Check the script.. maximum 9! BUt I get a error..
luaDoCreateMonster(). Cannot create monster: penguin
It creates.. but after a while... THEN IT KEEPS SPAMMING AND THE SERVER LAGGS AS HELL (MEGA FREEZE!) And then I need to restart! :( Help!
 
Back
Top