• 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 Banker.lua with all option

sfynks870

New Member
Joined
Jan 17, 2010
Messages
4
Reaction score
0
This is simply the Bank.lua that came with my server, with the all option scripted in. That way you don't have to know exactly how much money you have to withdraw or deposit all.:D You can simply say "deposit all" or "withdraw all" and all gold will be transferred.

Simple, I know, but, I couldn't find it and thought perhaps others couldn't either.;)

Bank.lua

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local stan = 0
local stan_two = 0
local player_pattern = '^[a-zA-Z0-9 -]+$'
local number_pattern = '%d'
local target_cid = 0
local number_pattern_two = '%d+'
local b, e = 0
local count = 0
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
	end

	if getPlayerStorageValue(cid,8996) == -1 then
		setPlayerStorageValue(cid,8996,0)
	end

	if msgcontains(msg, 'deposit') then
		if string.find(msg, number_pattern) then
			b, e = string.find(msg, number_pattern_two)
			count = tonumber(string.sub(msg, b, e))
			if getPlayerMoney(cid) >= count then
				doPlayerRemoveMoney(cid,count)
				stan = getPlayerStorageValue(cid,8996) + count
				setPlayerStorageValue(cid,8996,stan)
				npcHandler:say('Alright, we have added the amount of '..count..' gold to your balance. You can withdraw your money anytime.', cid)
				local talk_state = 0
			else
				npcHandler:say('You don\'t have that much gold.', cid)
				local talk_state = 0
			end
		elseif msgcontains(msg, 'all') then
			count = getPlayerMoney(cid)
			doPlayerRemoveMoney(cid,count)
			stan = getPlayerStorageValue(cid,8996) + count
			setPlayerStorageValue(cid,8996,stan)
			npcHandler:say('Alright, we have added the amount of '..count..' gold to your balance.  You can withdraw your money at anytime.', cid)
			local talk_state = 0
		else
			npcHandler:say('Please tell me how much gold you would like to deposit.', cid)
			local talk_state = 1
		end
	elseif msgcontains(msg, 'withdraw') then
		if string.find(msg, number_pattern) then
			b, e = string.find(msg, number_pattern_two)
			count = tonumber(string.sub(msg, b, e))
			if getPlayerStorageValue(cid,8996) - count >= 0 then
				stan = getPlayerStorageValue(cid,8996) - count
				setPlayerStorageValue(cid,8996,stan)
				doPlayerAddMoney(cid,count)
				npcHandler:say('Here you are, '..count..' gold. Please let me know if there is something else I can do for you.', cid)
				local talk_state = 0
			else
				npcHandler:say('There is not enough gold on your account.', cid)
				local talk_state = 0
			end
		elseif msgcontains(msg, 'all') then
			count = getPlayerStorageValue(cid,8996)
			doPlayerAddMoney(cid,count)
			setPlayerStorageValue(cid,8996,0)
			npcHandler:say('Here you are, '..count..' gold.  Please let me know if there is something else I can do for you.',cid)
			local talk_state = 0
		else
			npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
			local talk_state = 2
		end
	elseif msgcontains(msg, 'balance') then
		if getPlayerStorageValue(cid,8996) == -1 then
			setPlayerStorageValue(cid,8996,0)
		end
			npcHandler:say('Your account balance is ' .. getPlayerStorageValue(cid,8996) .. ' gold.', cid)
			local talk_state = 0
	elseif talk_state == 1 then
		count = tonumber(string.sub(msg, b, e))
		if string.find(msg, number_pattern) then
			if doPlayerRemoveMoney(cid, msg) then
				stan = getPlayerStorageValue(cid,8996) + msg
				setPlayerStorageValue(cid,8996,stan)
				doPlayerRemoveMoney(cid,msg)
				npcHandler:say('Alright, we have added the amount of '..count..' gold to your balance. You can withdraw your money anytime.', cid)
				local talk_state = 0
			else
				npcHandler:say('You don\'t have so much gold.', cid)
				local talk_state = 0
			end
		else
			npcHandler:say('Please tell me how much gold you would like to deposit.', cid)
			local talk_state = 1
		end
	elseif talk_state == 2 then
		count = tonumber(string.sub(msg, b, e))
		stan = getPlayerStorageValue(cid,8996)
		if string.find(msg, number_pattern) then
			if getPlayerStorageValue(cid,8996) - msg >= 0 then
				stan = getPlayerStorageValue(cid,8996) - msg
				setPlayerStorageValue(cid,8996,stan)
				doPlayerAddMoney(cid,msg)
				npcHandler:say('Here you are, '..count..' gold. Please let me know if there is something else I can do for you.', cid)
				local talk_state = 0
			else
				npcHandler:say('There is not enough gold on your account.', cid)
				local talk_state = 0
			end
		else
			npcHandler:say('Please tell me how much gold you would like to deposit.', cid)
			local talk_state = 2
		end
	return true
	end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
--npcHandler:setMessage(MESSAGE_FAREWELL, 'Bye, bye. You gold safe at here, |PLAYERNAME|. <snickers>!')
npcHandler:addModule(FocusModule:new())
 
Back
Top