camman
New Member
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.
Here are the mock-up functions I wrote.
Thanks,
Cameron
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: