• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Sucky but working House Seller.

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,941
Solutions
11
Reaction score
352
Hi.

v Removed da big table v
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local house = {}
local hasHouse = {}
local eachTilePrice = 200 -- price for each house tile
local maxHouses = 100 -- how many houses does your server have
	
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, "free") or msgcontains(msg, "offer") then
		local freeHouses = ""
		local z = ""
		for i = 1, maxHouses do
			if getHouseOwner(i) == 0 then
				if freeHouses == "" then z = "" else z = "," end
				freeHouses = freeHouses..""..z.." "..i
			end
		end
		selfSay("You can buy the following houses: "..freeHouses..".", cid)
	elseif msgcontains(msg, "house") then
		for i = 1, maxHouses do
			if getHouseOwner(i) == getPlayerGUID(cid) then
				hasHouse[cid] = 1
			end
		end
		if hasHouse[cid] == 1 then
			selfSay("You already own a house!", cid)
		else
			selfSay("Which house would you like to buy?", cid)
			talkState[cid] = 1
		end
	elseif msgcontains(msg, "yes") and talkState[cid] == 2 then
		if doPlayerRemoveMoney(cid, getHouseTilesSize(house[cid]) * eachTilePrice) == TRUE then
			selfSay("Congratulations, the house #"..house[cid].." is yours!", cid)
			setHouseOwner(house[cid], getPlayerGUID(cid))
			talkState[cid] = 0
		else
			selfSay("Ehh... Not enough gold. You need "..getHouseTilesSize(house[cid]) * eachTilePrice.." gold pieces to buy it.", cid)
			talkState[cid] = 0
		end
	elseif msgcontains(msg, "no") and talkState[cid] == 2 then
		selfSay("As you wish...", cid)
		talkState[cid] = 0
	elseif talkState[cid] == 1 then
		if isNumber(msg) == TRUE then
			if tonumber(msg) < #houses then
				if getHouseOwner(msg) == 0 then
					selfSay("Uhm... Would you like to buy house #"..msg.." for "..getHouseTilesSize(msg) * eachTilePrice.." gold coins?", cid)
					talkState[cid] = 2
					house[cid] = msg
				else
					selfSay("Sorry, this house is already owned by someone.", cid)
					talkState[cid] = 0
				end
			else
				selfSay("Sorry, there is not that much houses, we have "..maxHouses.." houses", cid)
			end
		else
			selfSay("I could not understand, please repeat the house number.", cid)
			talkState[cid] = 1
		end
	end
	return TRUE
end
		
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

You can buy the house by telling its ID, I will make the houseName version in a min.

Bye.
 
Last edited:
//edit

I will test it later, im kinda busy :p
 
Last edited:
Back
Top