• 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 + Elfbot}

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,858
Reaction score
96
Location
Brazil
I'm using dev 0.4, rev 3884 (8.6).
How to protect NPCs against Elfbot? People are buying itens for free with elfbot. How can I protect NPCs?

This is a CRITICAL BUG that can crash this rev easy. When people start buy itens with Elfbot in any NPCs (Example: Perac) this messages spam the console and don't stop.
I think if more than 10 guys start it in different NPCs the server will crash.

imagemni.jpg

This time my friend was doing in NPC Perac.
PS.: The messages in console show another NPC, I don't know why. Just me and my friend online. (Test Server)

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Perac" script="data/npc/scripts/default.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="129" head="78" body="52" legs="68" feet="114" addons="0"/>
    <parameters>
        <parameter key="message_greet" value="Oh, please come in, |PLAYERNAME|. What do you need? I sell fine distance weapons and ammunition."/>
        <parameter key="message_farewell" value="Good bye, |PLAYERNAME|."/>
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="job;" />
        <parameter key="keyword_reply1" value="I am the fletcher of Carlin. I am selling bows, crossbows, and ammunition. Do you need anything?" />
        <parameter key="module_shop" value="1"/>
        <parameter key="shop_buyable" value="crossbow,2455,500;bow,2456,400;bolt,2543,4;arrow,2544,3;spear,2389,10;assassin star,7368,100" />
        <parameter key="shop_sellable" value="spear,2389,3;" />

    </parameters>
</npc>

-----------------------------------------------
I'm using libs and npc/libs from rev3884.
-----------------------------------------------
I followed this tutorial and nothing solved.
http://otland.net/f16/cloning-elfbot-urgently-104658/
-----------------------------------------------
Cykotitan said: I don't think that's the lib you're using with the server, because the errors you're getting are from lib files of different version.
Check here.
-----------------------------------------------






SOLUTION:
modules.lua
Lua:
-- Callback onBuy() function. If you wish, you can change certain Npc to use your onBuy().
	function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
		local shopItem = nil
		for _, item in ipairs(self.npcHandler.shopItems) do
			if(item.id == itemid and item.subType == subType) then
				shopItem = item
				break
			end
		end

		if(shopItem == nil) then
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Item not found on shopItems list')
			return false
		end

		if(shopItem.buy == -1) then
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Attempt to purchase an item which only sellable')
			return false
		end

		if(amount <= 0) then
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Attempt to purchase ' .. amount .. ' items')
			return false
		end

		local backpack, totalCost = 1988, amount * shopItem.buy
		if(inBackpacks) then
			totalCost = totalCost + (math.max(1, math.floor(amount / getContainerCapById(backpack))) * 20)
		end

		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = amount,
			[TAG_TOTALCOST] = totalCost,
			[TAG_ITEMNAME] = shopItem.name
		}

		if(getPlayerMoney(cid) < totalCost) then
			local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
			doPlayerSendCancel(cid, self.npcHandler:parseMessage(msg, parseInfo))
			return false
		end

		local subType = shopItem.subType or 1
		local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
		if(a < amount) then
			local msgId = MESSAGE_NEEDMORESPACE
			if(a == 0) then
				msgId = MESSAGE_NEEDSPACE
			end

			local msg = self.npcHandler:getMessage(msgId)
			parseInfo[TAG_ITEMCOUNT] = a

			doPlayerSendCancel(cid, self.npcHandler:parseMessage(msg, parseInfo))
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end

			if(a > 0) then
				doPlayerRemoveMoney(cid, ((a * shopItem.buy) + (b * 20)))
				return true
			end

			return false
		end

		local msg = self.npcHandler:getMessage(MESSAGE_BOUGHT)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, self.npcHandler:parseMessage(msg, parseInfo))

		doPlayerRemoveMoney(cid, totalCost)
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			self.npcHandler.talkStart[cid] = os.time()
		else
			self.npcHandler.talkStart = os.time()
		end

		return true
	end


I just removed this line, no more bugs in console, is there any problem?
Lua:
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Item not found on shopItems list')

Just 1 problem:
When I select 'buy with backpack' do not have effect.
 
Last edited:
How to buy items for free with Elf bot :O ? I never tried that.
Topic: Turn off function of buying items or do people have to rewrite some codes from the images xd, sry i tried to no offtop.
 
How to buy items for free with Elf bot :O ? I never tried that.
Topic: Turn off function of buying items or do people have to rewrite some codes from the images xd, sry i tried to no offtop.
They're buying it ingame from NPCs, not on the website :p.
 
I know Cyko~ but it was a joke i meant more like npc gives you some letter with code to rewrite xD .. But i guess you could be joking too ;d?
 
Just replace the code responsible for this bug (modules.lua->ShopModule:callbackOnBuy), with the code from 0.3.6? And adapt it, if necessary.
 
modules.lua
Lua:
-- Callback onBuy() function. If you wish, you can change certain Npc to use your onBuy().
	function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
		local shopItem = nil
		for _, item in ipairs(self.npcHandler.shopItems) do
			if(item.id == itemid and item.subType == subType) then
				shopItem = item
				break
			end
		end

		if(shopItem == nil) then
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Item not found on shopItems list')
			return false
		end

		if(shopItem.buy == -1) then
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Attempt to purchase an item which only sellable')
			return false
		end

		if(amount <= 0) then
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Attempt to purchase ' .. amount .. ' items')
			return false
		end

		local backpack, totalCost = 1988, amount * shopItem.buy
		if(inBackpacks) then
			totalCost = totalCost + (math.max(1, math.floor(amount / getContainerCapById(backpack))) * 20)
		end

		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = amount,
			[TAG_TOTALCOST] = totalCost,
			[TAG_ITEMNAME] = shopItem.name
		}

		if(getPlayerMoney(cid) < totalCost) then
			local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
			doPlayerSendCancel(cid, self.npcHandler:parseMessage(msg, parseInfo))
			return false
		end

		local subType = shopItem.subType or 1
		local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
		if(a < amount) then
			local msgId = MESSAGE_NEEDMORESPACE
			if(a == 0) then
				msgId = MESSAGE_NEEDSPACE
			end

			local msg = self.npcHandler:getMessage(msgId)
			parseInfo[TAG_ITEMCOUNT] = a

			doPlayerSendCancel(cid, self.npcHandler:parseMessage(msg, parseInfo))
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end

			if(a > 0) then
				doPlayerRemoveMoney(cid, ((a * shopItem.buy) + (b * 20)))
				return true
			end

			return false
		end

		local msg = self.npcHandler:getMessage(MESSAGE_BOUGHT)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, self.npcHandler:parseMessage(msg, parseInfo))

		doPlayerRemoveMoney(cid, totalCost)
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			self.npcHandler.talkStart[cid] = os.time()
		else
			self.npcHandler.talkStart = os.time()
		end

		return true
	end


EDIT
I just removed this line, no more bugs in console, is there any problem?
Lua:
			print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Item not found on shopItems list')

Just 1 problem:
When I select 'buy with backpack' do not have effect.
 
Last edited:
Back
Top