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

Tax Rate NPC

camman

New Member
Joined
Jan 5, 2009
Messages
7
Reaction score
0
Location
United States of America
I'm working on creating a tax system for my OT. I'm trying to create the tax manager NPC now. I've already written rough draft functions to set the tax rate, and view & collect taxes. I just am unsure on how to go about making a NPC that will do this.

Here's an example of what I would like it to work.
Player: Hello
Tax Manager: Greetings Player! I am the tax manager. Through me you can 'set' the tax rate, 'check' the amount of gold paid in taxes, or 'collect' your tax money.
Player: check
Tax Manager: You have 500 gold in taxes stored in the treasury.
Player: collect
Tax Manager: Here is your 500 gold in taxes.
Player: set
Tax Manager: What would you like the tax rate to be?
Player: 25
Tax Manager: Tax rate set to 25 percent.
Player: Bye
Tax Manager: Farewell!

Here are the mock-up functions I wrote.
Code:
function getTaxAmount(cid)
	result = db.getResult("SELECT * FROM `taxes`;")
	taxes = 0;
	if(result_plr:getID() ~= -1) then
		while(true) do
			taxes = taxes + result:getDataInt("value")
		end
	end
	npcHandler:say("You have "..tostring(taxes).." gold in taxes stored in the treasury.", cid)
end

function collectTaxes(cid)
	result = db.getResult("SELECT * FROM `taxes`;")
	taxes = 0;
	if(result_plr:getID() ~= -1) then
		while(true) do
			taxes = taxes + result:getDataInt("value")
		end
	end
	doPlayerAddMoney(cid, taxes)
	npcHandler:say("Here is your "..tostring(taxes).." gold in taxes.", cid)
	db.executeQuery("TRUNCATE TABLE `taxes`;")
end

function setTaxRate(cid, taxRate) then
	if (tonumber(taxRate)) then
		if (tonumber(taxRate) < 26 && tonumber(taxRate) > -1)
			db.executeQuery("UPDATE `server_config` SET value = '"..tostring(taxRate).."' WHERE config = 'tax';")
			npcHandler:say('Tax rate set to '..tostring(taxRate)..' percent.', cid)
		else
			npcHandler:say('Tax must be no greater than 25 and no less than 0.', cid)
		end
	else	
		npcHandler:say('Incorrect tax rate value. Say the number (out of 100). So for a 20% tax rate say 20.', cid)
	end
end

Thanks,
Cameron
 
Last edited:
you should actually create the table by player id or guid so that the npc can understand not pick up all the gold of all the players. something like this:
Code:
CREATE TABLE `taxes`
(
	`player_id` INT NOT NULL DEFAULT 0,
	`value` INT NOT NULL DEFAULT 0
) ENGINE = InnoDB;
then the functions should look like this: (also im not sure about the getPlayerGUID part)
-- leave it global better
Code:
taxes = {}
Code:
function getTaxAmount(cid)
	local result = db.getResult("SELECT `value` FROM `taxes` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
	if result:getID() ~= -1 then
		taxes[cid] = taxes[cid] + result:getDataInt("value")
	end
	return {taxes = taxes}
end
Code:
function collectTaxes(cid)
	local res = db.getResult("SELECT `value` FROM `taxes` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
	if res:getID() ~= -1 then
		taxes[cid] = taxes[cid] + res:getDataInt("value")
	end
	return {taxes = taxes}
end
Code:
function setTaxRate(cid, taxRate)
	--if tonumber(taxRate) then // you dont actually need this because ur the one who is using and shouldn't do it wrong
	--if tonumber(taxRate) < 26 && tonumber(taxRate) > -1 then // no such sympol "&&" in lua it should be "and"
	return db.executeQuery("UPDATE `taxes` SET `value` = `value` + " .. taxRates .. " WHERE `player_id` = " .. getPlayerGUID(cid) .. ";") -- you dont really need to open another table, store the value in just one table better
end
heres an example of how to use these functions stated above:
--
Code:
if getTaxAmount(cid).taxes > 0 then
	npcHandler:say("what ever you want him to say.", cid)
else
	npcHandler:say("You dont have enough taxes.", cid)
end
Code:
if collectTaxes(cid).taxes > 0 then
	npcHandler:say("Here is your " .. getTaxAmount(cid).taxes, cid)
else
	npcHandler:say("You dont have enough taxes.")
end
Code:
if msgcontains(msg, "set") then
	npcHandler:say("How many you want to set . etc", cid)
	--set ur talk state
	if getTaxAmount(cid).taxes > 0 and tonumber(msg) then
		setTaxRate(cid, math.deg(math.pi / msg * 5) -- this is just an example to get the "%"
		npcHandler:say("Stored: " .. msg .. "%.")
	else
		npcHandler:say("You either dont have enough taxes or your message doesnt contain numbers.", cid)
	end
end
--
all the npcHander:say() u can make the possible checks while creating the npc itself then give the result to the player, good luck.
 
Last edited:
Back
Top