-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added sample Banker NPC #2934
Added sample Banker NPC #2934
Conversation
I added it mainly because of @Znote so we can start implementing the guild bank feature from #2214 and also provide a consistent bank NPC for users to have a base to work on - Script and functions are mostly from ORTS, I just did small modifications and added the restriction to not transfer money to no vocation players - Added xml and lua npc files - Added isNumber function to compat (was going to add at global.lua but seems like it was an old and used function so better at compat) - Added playerExists(name) function, to check if offline player exists by name - Added getPlayerVocationAux(name) to get offline player vocationID by name (function by Sarah Wesker) - Added Player.transferMoneyTo and Player.withdrawMoney function by ORTS - Added isValidMoney, getMoneyCount and getMoneyWeight to lib\npc.lua
!!!!!!!!!!!!!!THIS NEED TO BE TESTED!!!!!!!!!!!!!!
please guys test these changes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the else
s in lines 219, 258, 283 and 307 be replaced with:
elseif msgcontains(msg, "no") then
?
maybe I should do a separated PR adding the functions and leave this one to NPC files only? for better review |
I'm fine with either. |
draft until #3085 gets approval |
Fixed the 5 noted issues in PR
@soul4soul @Zbizu @luanluciano93 @m4g1ch @DSpeichert |
Give a hint that players can change their coins.
These functions were added in order for the upcoming sample `Banker` NPC #2934 and in the future for the guild balance feature #2214 - function getPlayerDatabaseInfo(name_or_guid) TFS 1.3 function that queries for player information from the database, returns a table of useful information if success, false if player doesn't exist. - function isNumber(str) used in several distros but wasn't there on compat.lua yet - function Player.transferMoneyTo(self, target, amount) - function Player.withdrawMoney(self, amount) - function Player.depositMoney(self, amount) - function isValidMoney(money) - function getMoneyCount(string) - function getMoneyWeight(money) Co-authored-by: Znote <stefan_brannfjell@live.no>
Since #3085 was merged, it is easier to test this. Simply update your data to latest commit in master and add these files: /data/npc/scripts/bank.lua If you use Linux, you can just do this in your terminal: cd data/npc/
wget https://raw.githubusercontent.com/otland/forgottenserver/97b0fb1ead758c3c3e8fa612c310afec18a72109/data/npc/Banker.xml
cd scripts/
wget https://raw.githubusercontent.com/otland/forgottenserver/97b0fb1ead758c3c3e8fa612c310afec18a72109/data/npc/scripts/bank.lua
ls Restart the server (or reload npc) and do |
If you look at my GuildBanker NPC: You see that I added a table of topics: local topicList = {
NONE = 0,
DEPOSIT_GOLD = 1,
DEPOSIT_CONSENT = 2,
WITHDRAW_GOLD = 3,
WITHDRAW_CONSENT = 4,
TRANSFER_TYPE = 5,
TRANSFER_PLAYER_GOLD = 6,
TRANSFER_PLAYER_WHO = 7,
TRANSFER_PLAYER_CONSENT = 8,
TRANSFER_GUILD_GOLD = 9,
TRANSFER_GUILD_WHO = 10,
TRANSFER_GUILD_CONSENT = 11,
LEDGER_CONSENT = 12
}
-- psuedo code
if npcHandler.topic[cid] == topicList.WITHDRAW_GOLD then
count[cid] = getMoneyCount(msg)
if count[cid] > 0 and count[cid] <= guild:getBankBalance() then
npcHandler:say("Are you sure you wish to withdraw " .. count[cid] .. " gold from the guild " .. guild:getName() .. "?", cid)
npcHandler.topic[cid] = topicList.WITHDRAW_CONSENT
else
npcHandler:say("There is not enough gold in the guild " .. guild:getName() .. ". Their available balance is currently " .. guild:getBankBalance() .. ".", cid)
npcHandler.topic[cid] = topicList.NONE
end
return true
end It makes the Lua code a bit easier to handle, since you dont need to keep track of topic numbers and what they represent. |
I'll do for sure |
I added it mainly because of @Znote so we can start implementing the guild bank feature from #2214 and also provide a consistent bank NPC for users to have a base to work on