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

NPC [TFS 1.3] Bank NPC

Togu

Advanced OT User
Joined
Jun 22, 2018
Messages
301
Best answers
1
Reaction score
155
Location
Brazil
Since the original forgottenserver on GitHub doesn't have an Bank NPC, I will post that one that I made getting some codes on the internet.

Using this feature I've found many functions, they deserve the credits:
orts/server

You will have to add on data/lib/core/player.lua: pasteBin
Lua:
function Player.depositMoney(self, amount)
   if not self:removeMoney(amount) then
       return false
   end

   self:setBankBalance(self:getBankBalance() + amount)
   return true
end

function Player.withdrawMoney(self, amount)
   local balance = self:getBankBalance()
   if amount > balance or not self:addMoney(amount) then
       return false
   end

   self:setBankBalance(balance - amount)
   return true
end

function Player.transferMoneyTo(self, target, amount)
   local balance = self:getBankBalance()
   if amount > balance then
       return false
   end

   local targetPlayer = Player(target)
   if targetPlayer then
       targetPlayer:setBankBalance(targetPlayer:getBankBalance() + amount)
   else
       if not playerExists(target) then
           return false
       end
       db.query("UPDATE `players` SET `balance` = `balance` + '" .. amount .. "' WHERE `name` = " .. db.escapeString(target))
   end

   self:setBankBalance(self:getBankBalance() - amount)
   return true
end
and then in data/npc/scripts/bank.lua: pasteBin

I didn't tested the guild bank functions and features, but player deposit, withdraw, balance and transfer are working.
 

hellboy

Well-Known Member
Joined
Apr 6, 2008
Messages
451
Best answers
4
Reaction score
73
Location
player:getTown()
[...]
db.query("UPDATE `players` SET `balance` = `balance` + '" .. amount .. "' WHERE `name` = " .. db.escapeString(target))
[...]
This part could make a lot of troubles :)
How?
1. Login as player A and player B
2. Transfer money from player A to player B
3. There is database UPDATE
4. Logout as player B
5. There is database uptade on player B row, that could overwrite changes
6. Money dissapear

Rest functions look nice. I guess if everythink will work as it should, it should be merged in github.
 
OP
Togu

Togu

Advanced OT User
Joined
Jun 22, 2018
Messages
301
Best answers
1
Reaction score
155
Location
Brazil
This part could make a lot of troubles :)
How?
1. Login as player A and player B
2. Transfer money from player A to player B
3. There is database UPDATE
4. Logout as player B
5. There is database uptade on player B row, that could overwrite changes
6. Money dissapear

Rest functions look nice. I guess if everythink will work as it should, it should be merged in github.
I don't know how to force this error. Actually I didn't understand how the code can reach this db.query (I simply copied it and tested and it was working). Cause if the target player exists he will add money in his bank. But if he didn't exist he will return false before reaching the db.query.

Do you know why there isn't datapacks commits on forgottenserver on GitHub? It could have the NPCs and actions from a global map.
 

Nekiro

Legendary OT User
TFS Developer
Support Team
Joined
Sep 7, 2015
Messages
2,141
Best answers
94
Reaction score
1,007
This part could make a lot of troubles :)
How?
1. Login as player A and player B
2. Transfer money from player A to player B
3. There is database UPDATE
4. Logout as player B
5. There is database uptade on player B row, that could overwrite changes
6. Money dissapear

Rest functions look nice. I guess if everythink will work as it should, it should be merged in github.
No, it wont make any trouble.
Code checks if player is online and sets the balance, otherwise it query the change directly to database.
 

super23

New Member
Joined
Dec 27, 2013
Messages
93
Best answers
0
Reaction score
4
How do i make the actual npc then? if someone could help please?
 
Top