Skip to content
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

Merged
merged 36 commits into from
Aug 1, 2020
Merged

Added sample Banker NPC #2934

merged 36 commits into from
Aug 1, 2020

Conversation

ghost
Copy link

@ghost ghost commented Apr 11, 2020

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

Evil Puncker added 2 commits April 11, 2020 00:48
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
data/global.lua Outdated Show resolved Hide resolved
data/npc/lib/npc.lua Outdated Show resolved Hide resolved
data/npc/scripts/bank.lua Outdated Show resolved Hide resolved
data/npc/scripts/bank.lua Outdated Show resolved Hide resolved
data/npc/scripts/bank.lua Outdated Show resolved Hide resolved
data/npc/scripts/bank.lua Outdated Show resolved Hide resolved
data/npc/scripts/bank.lua Outdated Show resolved Hide resolved
data/lib/core/player.lua Outdated Show resolved Hide resolved
@DSpeichert DSpeichert added the needs-testing Needs testing with screenshots label Apr 18, 2020
data/npc/lib/npc.lua Outdated Show resolved Hide resolved
Evil Puncker added 3 commits April 19, 2020 15:08
!!!!!!!!!!!!!!THIS NEED TO BE TESTED!!!!!!!!!!!!!!
@ghost
Copy link
Author

ghost commented Apr 21, 2020

please guys test these changes:
dbd2df6

@DSpeichert DSpeichert added this to the 1.4 milestone Apr 23, 2020
Copy link

@m4g1ch m4g1ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the elses in lines 219, 258, 283 and 307 be replaced with:
elseif msgcontains(msg, "no") then
?

data/npc/scripts/bank.lua Outdated Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Jun 9, 2020

If anyone is going to merge this, make sure to squash the commits and write a nice commit message.

maybe I should do a separated PR adding the functions and leave this one to NPC files only? for better review

@DSpeichert
Copy link
Member

I'm fine with either.

@ghost ghost marked this pull request as draft June 10, 2020 10:53
@ghost
Copy link
Author

ghost commented Jun 10, 2020

draft until #3085 gets approval

Evil Puncker and others added 3 commits June 14, 2020 17:27
@ghost ghost marked this pull request as ready for review June 15, 2020 14:18
@ghost ghost requested a review from DSpeichert June 15, 2020 14:24
@ghost
Copy link
Author

ghost commented Jun 15, 2020

@soul4soul @Zbizu @luanluciano93 @m4g1ch @DSpeichert
okay guys, thanks to znote now everything should be 100%, but I'd like to ask for a final review/approval since a few things have changed and your input is valuable! please refer to #3085 for the functions and this one for the npc, thanks in advance!

Give a hint that players can change their coins.
Znote added a commit that referenced this pull request Jun 16, 2020
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>
@Znote
Copy link
Member

Znote commented Jun 16, 2020

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/Banker.xml
https://raw.githubusercontent.com/otland/forgottenserver/97b0fb1ead758c3c3e8fa612c310afec18a72109/data/npc/Banker.xml

/data/npc/scripts/bank.lua
https://raw.githubusercontent.com/otland/forgottenserver/97b0fb1ead758c3c3e8fa612c310afec18a72109/data/npc/scripts/bank.lua

If you use Linux, you can just do this in your terminal:
First cd to the folder that has config.lua in it, then paste these commands:

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 /s Banker to summon the NPC in-game.

@DSpeichert DSpeichert requested a review from a team June 22, 2020 07:06
@Znote
Copy link
Member

Znote commented Jul 13, 2020

If you look at my GuildBanker NPC:
https://github.com/otland/forgottenserver/blob/d11e44d0f9052a53534143f546da1a4a2f768753/data/npc/scripts/guildbank.lua

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.
Its a bit of a chore, but it would be nice if you could add that here.

@ghost
Copy link
Author

ghost commented Jul 13, 2020

If you look at my GuildBanker NPC:
https://github.com/otland/forgottenserver/blob/d11e44d0f9052a53534143f546da1a4a2f768753/data/npc/scripts/guildbank.lua

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.
Its a bit of a chore, but it would be nice if you could add that here.

I'll do for sure

@DSpeichert DSpeichert merged commit b5c74b4 into otland:master Aug 1, 2020
@ghost ghost deleted the bank-npc branch August 1, 2020 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-testing Needs testing with screenshots
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants