• 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 Guild bank system

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
A request from izaak here: http://otland.net/f132/request-guildbank-system-101926/

First, execute this on MySQL:
Code:
alter table guilds add balance int(11) not null default 0;

The npc:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Jhon" script="guildbank.lua" walkinterval="0" floorchange="0">
	<health now="150" max="150"/>
	<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
    <parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. If you wan't to see your guild's balance, say {balance}."/>
    </parameters>
</npc>

Lua:
function getGuildBalance(id)
	local query = db.getResult("select balance from guilds where id = " .. id .. ";")
	if query:getID() ~= -1 then
		return query:getDataInt("balance")
	end
	return LUA_ERROR
end

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

local money = 0
function creatureSayCallback(cid, type, msg)

	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "balance") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("The balance for the guild " .. getPlayerGuildName(cid) .. " is " .. getGuildBalance(getPlayerGuildId(cid)) .. " gold coins.", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, "deposit") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("How much money do you want deposit to your guild balance?", cid)
			talkState[talkUser] = 1
		end
	elseif talkState[talkUser] == 1 then
		if not tonumber(msg) or tonumber(msg) < 1 then
			selfSay("Please tell me how much do you want to deposit to your guild's balance?", cid)
		end

		money = math.abs(tonumber(msg))
		selfSay("Are you sure that do you want to deposit " .. money .. " gold coins to your guild's balance?", cid)
		talkState[talkUser] = 2
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			if getPlayerMoney(cid) >= money then
				local query = db.executeQuery("update guilds set balance = balance + " .. money .. " where id = " .. getPlayerGuildId(cid) .. ";")
				if query ~= LUA_ERROR then
					selfSay("You have deposited " .. money .. " gold coins to your guild's balance.", cid)
					doPlayerRemoveMoney(cid, money)
					talkState[talkUser] = 0
				else
					selfSay("Money can not be deposited, please contact a gamemaster.", cid)
					error("[Error::Query] " .. query .. ", error while trying to add a value into balance.")
					talkState[talkUser] = 0
				end
			else
				selfSay("Sorry, you don't have the money.", cid)
				talkState[talkUser] = 0
			end
		end
	elseif msgcontains(msg, "withdraw") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("How much money do you want to withdraw from your guild's balance?", cid)
			talkState[talkUser] = 3
		end
	elseif talkState[talkUser] == 3 then
		if not tonumber(msg) or tonumber(msg) < 1 then
			selfSay("Please tell me how much do you want to withdraw from your guild's balance?", cid)
		end

		money = math.abs(tonumber(msg))
		selfSay("Are you sure that do you want to withdraw " .. money .. " gold coins from your guild's balance?", cid)
		talkState[talkUser] = 4
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 4 then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			if getGuildBalance(getPlayerGuildId(cid)) >= money then
				local query = db.executeQuery("update guilds set balance = (balance - " .. money.. ") where id = " .. getPlayerGuildId(cid) .. ";")
				if query then
					selfSay("You withdraw " .. money .. " gold coins from your guild's balance.", cid)
					doPlayerAddMoney(cid, money)
					talkState[talkUser] = 0
				else
					selfSay("Money can not be retired, please contact a gamemaster.", cid)
					error("[Error::Query] " .. query .. ", error while trying to remove a value from balance.")
					talkState[talkUser] = 0
				end
			else
				selfSay("Sorry, your guild don't have the money in the balance.", cid)
				talkState[talkUser] = 0
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Hope you like it! ^_^
 
Last edited:
oh! o_O rlly nice thanks for sharing it ^^
for what version u did it? 0.3.6pl1?
 
rep++ xD thank you ^^
also big thanks for this script darkhaos because thanks to you i understand allot more about sql commands inside of scripts...
 
Last edited:
update the npc please " the npc dousnt remove the money from my backpack

after
Code:
	if getPlayerMoney(cid) >= money then
				local query = db.executeQuery("update guilds set balance = balance + " .. money .. " where id = " .. getPlayerGuildId(cid) .. ";")
				if query ~= LUA_ERROR then
					selfSay("You have deposited " .. money .. " gold coins to your guild's balance.", cid)
					talkState[talkUser] = 0

add
Code:
					doPlayerRemoveMoney(cid,money)

thank you for this npc its great
 
Can I lick your balls?

I'll see if it works first, then I'll lick


update the npc please " the npc dousnt remove the money from my backpack

after
Code:
	if getPlayerMoney(cid) >= money then
				local query = db.executeQuery("update guilds set balance = balance + " .. money .. " where id = " .. getPlayerGuildId(cid) .. ";")
				if query ~= LUA_ERROR then
					selfSay("You have deposited " .. money .. " gold coins to your guild's balance.", cid)
					talkState[talkUser] = 0

add
Code:
					doPlayerRemoveMoney(cid,money)

thank you for this npc its great

That's true, thanks for fix

@script

dude, it fuc*ing work *-*

Thanks a lot hoho very nice... btw, anyone of the guild can withdraw, deposit and view balance?
 
Last edited:
yes everyone can use it from the guild i have just tested it and all members can use it
 
update the npc please " the npc dousnt remove the money from my backpack

after
Code:
	if getPlayerMoney(cid) >= money then
				local query = db.executeQuery("update guilds set balance = balance + " .. money .. " where id = " .. getPlayerGuildId(cid) .. ";")
				if query ~= LUA_ERROR then
					selfSay("You have deposited " .. money .. " gold coins to your guild's balance.", cid)
					talkState[talkUser] = 0

add
Code:
					doPlayerRemoveMoney(cid,money)

thank you for this npc its great

My fail, updated
 
This functions on sqlite 1.1.3-b???? And i don't understand where you need to put balance int (11) not null default 0....
 
Dantarrix open youre sql lite database then find something that says execute sql , and paste it there then click on oke or execute query and it wil update
 
U know what would be great?

If only leader/vice-leader could withdraw

The other functions could be for everyone, members also

-- edit --

lol I'm totally noob at scripting, but after some tries I've managed to make an bugged and imperfect, but functional, limitation for withdrawing money, only leaders and vice-leaders can remove money, here's what I've changed:

Add this at npc/scripts/guildbank.lua

Lua:
function getGuildRank(id)
	local query = db.getResult("select level from guild_ranks where guild_id = " .. id .. ";")
	if query:getID() ~= -1 then
		return query:getDataInt("balance")
	end
	return LUA_ERROR
end

search

Lua:
elseif msgcontains(msg, "withdraw") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("How much money do you want to withdraw from your guild's balance?", cid)
			talkState[talkUser] = 3
		end

replace

Lua:
	elseif msgcontains(msg, "withdraw") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
			else
					if getGuildRank(getPlayerGuildId(cid)) == 3 then
			selfSay("Only leaders and vice-leaders can withdraw money.", cid)
		else
			selfSay("How much money do you want to withdraw from your guild's balance?", cid)
			talkState[talkUser] = 3
		end
		end

the player can't withdraw money if he's a member, but the the message is bugged lol, it just say there's no balance in the account, it's bugged but works lol, if someone could fix it would be good

here's my entire script for consulting:

Lua:
function getGuildBalance(id)
	local query = db.getResult("select balance from guilds where id = " .. id .. ";")
	if query:getID() ~= -1 then
		return query:getDataInt("balance")
	end
	return LUA_ERROR
end

function getGuildRank(id)
	local query = db.getResult("select level from guild_ranks where guild_id = " .. id .. ";")
	if query:getID() ~= -1 then
		return query:getDataInt("balance")
	end
	return LUA_ERROR
end
 
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
 
local money = 0
function creatureSayCallback(cid, type, msg)
 
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "balance") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("The balance for the guild " .. getPlayerGuildName(cid) .. " is " .. getGuildBalance(getPlayerGuildId(cid)) .. " gold coins.", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, "deposit") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("How much money do you want deposit to your guild balance?", cid)
			talkState[talkUser] = 1
		end
	elseif talkState[talkUser] == 1 then
		if not tonumber(msg) or tonumber(msg) < 1 then
			selfSay("Please tell me how much do you want to deposit to your guild's balance?", cid)
		end
 
		money = math.abs(tonumber(msg))
		selfSay("Are you sure that do you want to deposit " .. money .. " gold coins to your guild's balance?", cid)
		talkState[talkUser] = 2
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			if getPlayerMoney(cid) >= money then
				local query = db.executeQuery("update guilds set balance = balance + " .. money .. " where id = " .. getPlayerGuildId(cid) .. ";")
				if query ~= LUA_ERROR then
					selfSay("You have deposited " .. money .. " gold coins to your guild's balance.", cid)
					talkState[talkUser] = 0
					doPlayerRemoveMoney(cid,money)
				else
					selfSay("Money can not be deposited, please contact a gamemaster.", cid)
					error("[Error::Query] " .. query .. ", error while trying to add a value into balance.")
					talkState[talkUser] = 0
				end
			else
				selfSay("Sorry, you don't have the money.", cid)
				talkState[talkUser] = 0
			end
		end
	elseif msgcontains(msg, "withdraw") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
			else
					if getGuildRank(getPlayerGuildId(cid)) == 3 then
			selfSay("Only leaders and vice-leaders can withdraw money.", cid)
		else
			selfSay("How much money do you want to withdraw from your guild's balance?", cid)
			talkState[talkUser] = 3
		end
		end
		
		
	elseif talkState[talkUser] == 3 then
		if not tonumber(msg) or tonumber(msg) < 1 then
			selfSay("Please tell me how much do you want to withdraw from your guild's balance?", cid)
		end
 
		money = math.abs(tonumber(msg))
		selfSay("Are you sure that do you want to withdraw " .. money .. " gold coins from your guild's balance?", cid)
		talkState[talkUser] = 4
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 4 then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			if getGuildBalance(getPlayerGuildId(cid)) >= money then
				local query = db.executeQuery("update guilds set balance = (balance - " .. money.. ") where id = " .. getPlayerGuildId(cid) .. ";")
				if query then
					selfSay("You withdraw " .. money .. " gold coins from your guild's balance.", cid)
					doPlayerAddMoney(cid, money)
					talkState[talkUser] = 0
				else
					selfSay("Money can not be retired, please contact a gamemaster.", cid)
					error("[Error::Query] " .. query .. ", error while trying to remove a value from balance.")
					talkState[talkUser] = 0
				end
			else
				selfSay("Sorry, your guild don't have the money in the balance.", cid)
				talkState[talkUser] = 0
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
this 1 works ive tested it , members can deposit and ask balance but they cant withdraw money from the bank. only leaders and vice leaders can

Code:
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 getPlayerGuildRank(id)
	local query = db.getResult("select rank_id from players where id = " .. id .. ";")
	if query:getID() ~= -1 then
		return query:getDataInt("rank_id")
	end
	return LUA_ERROR
end
local money = 0

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "balance") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else 
			selfSay("The balance for the guild " .. getPlayerGuildName(cid) .. " is " .. getGuildBalance(getPlayerGuildId(cid)) .. " gold coins.", cid)
			talkState[talkUser] = 0
		end	
	elseif msgcontains(msg, "deposit") then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("How much money do you want deposit to your guild balance?", cid)
			talkState[talkUser] = 1
		end
	elseif talkState[talkUser] == 1 then
		if not tonumber(msg) or tonumber(msg) < 1 then
			selfSay("Please tell me how much do you want to deposit to your guild's balance?", cid)
		end
 
		money = math.abs(tonumber(msg))
		selfSay("Are you sure that do you want to deposit " .. money .. " gold coins to your guild's balance?", cid)
		talkState[talkUser] = 2
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			if getPlayerMoney(cid) >= money then
				local query = db.executeQuery("update guilds set balance = balance + " .. money .. " where id = " .. getPlayerGuildId(cid) .. ";")
				if query ~= LUA_ERROR then
					selfSay("You have deposited " .. money .. " gold coins to your guild's balance.", cid)
					talkState[talkUser] = 0
					doPlayerRemoveMoney(cid,money)
				else
					selfSay("Money can not be deposited, please contact a gamemaster.", cid)
					error("[Error::Query] " .. query .. ", error while trying to add a value into balance.")
					talkState[talkUser] = 0
				end
			else
				selfSay("Sorry, you don't have the money.", cid)
				talkState[talkUser] = 0
			end
		end
	elseif msgcontains(msg, "withdraw") then
			if (getPlayerGuildRank(47)) then
			selfSay("You need to be a vice leader to take money from the guildbank.", cid)
			else
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			selfSay("How much money do you want to withdraw from your guild's balance?", cid)
			talkState[talkUser] = 3
		end
	end	
	elseif talkState[talkUser] == 3 then
		if not tonumber(msg) or tonumber(msg) < 1 then
			selfSay("Please tell me how much do you want to withdraw from your guild's balance?", cid)
		end
 
		money = math.abs(tonumber(msg))
		selfSay("Are you sure that do you want to withdraw " .. money .. " gold coins from your guild's balance?", cid)
		talkState[talkUser] = 4
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 4 then
		if getPlayerGuildId(cid) < 1 then
			selfSay("You don't have any guild.", cid)
		else
			if getGuildBalance(getPlayerGuildId(cid)) >= money then
				local query = db.executeQuery("update guilds set balance = (balance - " .. money.. ") where id = " .. getPlayerGuildId(cid) .. ";")
				if query then
					selfSay("You withdraw " .. money .. " gold coins from your guild's balance.", cid)
					doPlayerAddMoney(cid, money)
					talkState[talkUser] = 0
				else
					selfSay("Money can not be retired, please contact a gamemaster.", cid)
					error("[Error::Query] " .. query .. ", error while trying to remove a value from balance.")
					talkState[talkUser] = 0
				end
			else
				selfSay("Sorry, your guild don't have the money in the balance.", cid)
				talkState[talkUser] = 0	
				end
			end
		end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It is not working for me. Npc Keeps saying Cannot deposit contact Gmaster. Someone explain me? Or give me a diraction where can i search the answer?
 
Last edited:
I think that it should also be possible for the leader and the vice-leader to see transfer stats. Else, if you got a huge guild, thiefing is an easy option. Further it's really a great idea and a nice script =).

But it will need to create new tables on database
 
it's already in TFS 0.3.6 no need it u only copy/paste didn't do any thing new :p (sry for saying that but you copy/paste)
 
Back
Top