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

[request] npc script

iksior

New Member
Joined
Jan 25, 2009
Messages
33
Reaction score
0
Hello everybody ! Sory for my bad eng. :)
I want to make NPC that will set random voc from 1-4 'knigh' 'paladin' 'sorc' 'druid' and set my looktype to warrior if knight hunter if pally druid if druid and if sorc set it to wizard. Can anyone write something like this ?
 
here is npc script

LUA:
local cfg = {
	minLevel = 1
	}
	
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 lvl = getPlayerLevel(cid)
local voc = getPlayerVocation(cid)
	if msgcontains(msg, "vocation") then
		if lvl >= cfg.minLevel then
			if voc ~= 0 then
				local rand = math.random(1,4)
				selfSay("Here you are.", cid)
				doPlayerSetVocation(cid, rand)
				doPlayerSendOutfitWindow(cid)
				doPlayerSetStorageValue(cid, (63835 + rand), true)
				doPlayerSetMaxCapacity(cid, (lvl*(getVocationInfo(rand).capacity)+400))
				setCreatureMaxHealth(cid, (lvl*(getVocationInfo(rand).healthGain)+150))
				setCreatureMaxMana(cid, (lvl*(getVocationInfo(rand).manaGain)))
			else
				selfSay("Sorry, I cannot help you.", cid)
			end
		else
			selfSay("Your level is too low!", cid)
		end
	else
		selfSay("Ask me for {vocation}.", cid)
	end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

you have to change a bit your file with outfits to protect players from changing outfit.
go to data/xml/outfits.xml
and find outfits named knight, hunter, mage, and druid.

add:
LUA:
quest="63836"
for mage. it have to looks like this:
LUA:
	<outfit id="1" quest="63836">
		<list gender="0" lookType="138" name="Mage"/>
		<list gender="1" lookType="130" name="Mage"/>
	</outfit>

do the same forrest professions.
63837 for druid,
63838 for pala,
63839 for kina


LUA:
doSetCreatureOutfit(cid, outfit, time)
is good too, but if someone relog, his outfit may not save, and will return back to first outfit.
 
Last edited:
Back
Top