• 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 with summon

andii95

New Member
Joined
Aug 21, 2009
Messages
413
Reaction score
2
Location
Sweden
Well i was thinking if somebody would like to make me a script.
A npc script, and when you say duel to the npc he summons a monster.
You can also just meet this npc once, and you get a reward after defeating the npc.

Thanks in advance :)
 
Last edited:
NPC script which is shared among all duel NPCs:
LUA:
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

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'duel') or msgcontains(msg, 'yes') then
		local t = duels[getNpcName():lower()]
		if t then
			if getCreatureStorage(cid, t[1]) == -1 then
				local v = getCreatureSummons(cid)
				if #v ~= 0 then
					doCreatureSay(getNpcCid(), 'Go, ' .. t[2], TALKTYPE_ORANGE_1)
					local k = doCreateMonster(t[2], getNpcPos())
					doMonsterSetTarget(k, v[1])
					doSendMagicEffect(getThingPos(k), CONST_ME_TELEPORT)
					doCreatureSetStorage(cid, t[1], 1)
				else
					selfSay('Sorry, but you must have a pokemon released!', cid)
				end
			else
				selfSay('You have already dueled me.', cid)
			end
			npcHandler:releaseFocus(cid)
		end
	end
	return true
end

npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, do you want to {duel}?")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
onKill creaturescript for players:
LUA:
function onKill(cid, target, lastHit)
	if lastHit and isMonster(target) and #getCreatureSummons(cid) ~= 0 then
		local name = getCreatureName(target):lower()
		for k, v in pairs(duels) do
			if v[2]:lower() == name and getCreatureStorage(cid, v[1]) == 1 then
				local npc = getCreatureByName(k)
				doCreatureSay(npc, 'Nicely done! Here, take this as a reward.', TALKTYPE_PRIVATE_NP, false, cid, getThingPos(npc))
				doPlayerAddExperience(cid, v[3])
				doSendAnimatedText(getThingPos(cid), v[3], 215)
				doRemoveCreature(target)
				doCreatureSetStorage(cid, v[1], 2)
				break
			end
		end
	end
	return true
end
onKill creaturescript for duel summons:
LUA:
function onKill(cid, target, lastHit)
	if isMonster(target) then
		local master = getCreatureMaster(target)
		if master and master ~= target and isPlayer(master) then
			local name = getCreatureName(cid):lower()
			for k, v in pairs(duels) do
				if v[2]:lower() == name and getCreatureStorage(master, v[1]) == 1 then
					doRemoveCreature(cid)
					doCreatureSetStorage(master, v[1])
					local npc = getCreatureByName(k)
					doCreatureSay(npc, 'Too bad. Come back when you are stronger.', TALKTYPE_PRIVATE_NP, false, master, getThingPos(npc))
					break
				end
			end
		end
	end
	return true
end
This goes into 000-constant.lua:
LUA:
duels = {
	['ben'] = {12345, 'Poliwag', 1000},
	['ling'] = {12344, 'Kadabra', 1500},
}
 
Last edited:

Similar threads

Back
Top