-
Notifications
You must be signed in to change notification settings - Fork 960
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 money transfer functions #1099
base: main
Are you sure you want to change the base?
Conversation
Black money is not in the core, but crypto is, and you didn't put it in ? |
Good point, but actually that information is only commented information, I mean is not really whitelisting those monetypes it is only info not actual code. Anyway I'll fixed it tomorrow |
Fixed the annotation and also renamed the |
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.
Some thing to change to prevent failure and I think code can be optimize a little bit (wording etc included)
server/functions.lua
Outdated
---@param quant number | ||
---@param reason string | ||
---@return boolean | ||
function QBCore.Functions.TransferMoney(emitercid, emitermoneytype, receivercid, receivermoneytype, quant, reason) |
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.
quant
should be replaced by amount
since it's the wording use by default for this kind of property
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.
sourcecid and targetcid wil lbe better than emitercid
/ receivercid
no ? and same for all properties then ? What do you think ?
server/functions.lua
Outdated
if not result then errorOnLast = true end | ||
result = json.decode(result) | ||
result[receivermoneytype] += quant | ||
if not MySQL.update.await('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(result), receivercid }) then return false end |
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.
you should not return false here but do errorOnLast = true
or the emiter will loose the money if their is an error on the receiver player
server/player.lua
Outdated
@@ -337,6 +337,29 @@ function QBCore.Player.CreatePlayer(PlayerData, Offline) | |||
return true | |||
end | |||
|
|||
function self.Functions.TransferMoneyTo(emitermoneytype, receivercid, receivermoneytype, quant, reason) |
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.
quant
should be replaced by amount
since it's the wording use by default for this kind of property
server/functions.lua
Outdated
local EmiterPlayer = QBCore.Functions.GetPlayerByCitizenId(emitercid) | ||
local ReceiverPlayer = QBCore.Functions.GetPlayerByCitizenId(receivercid) | ||
if not tonumber(quant) then return false end | ||
quant = tonumber(quant) or 0 |
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.
operation with 0 should not be done I think. Probably you can do if not tonumber(quant) or tonumber(quant) <= 0 then return false end
or just if tonumber(quant) <= 0 then return true end
server/player.lua
Outdated
function self.Functions.TransferMoneyTo(emitermoneytype, receivercid, receivermoneytype, quant, reason) | ||
local ReceiverPlayer = QBCore.Functions.GetPlayerByCitizenId(receivercid) | ||
if not tonumber(quant) then return false end | ||
quant = tonumber(quant) or 0 |
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.
same remark at the first file regarding 0 transaction handling
server/player.lua
Outdated
if not result then errorOnLast = true end | ||
result = json.decode(result) | ||
result[receivermoneytype] += quant | ||
if not MySQL.update.await('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(result), receivercid }) then return false end |
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.
instead of return false
it should be errorOnLast = true
Changed those things that you commented, you were right in all of them jajaja |
Will check that soon and let you know if I find something else |
Sorry I added changes by mistake, changes reverted |
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.
LGTM 👍
I don't know if we can add some log, but regarding the code itself i don't see any other mistake :)
Jus added logs and Money Events, a bit chunky the blocks of code but I don't know how to make it smaller. |
Update QB-Core correctly
This PR has had 60 days of inactivity & will close within 7 days |
Any update? |
Feel like this functionality could just be added onto |
I don't understand that |
Description
Implementation of the suggestion [SUGGESTION] Implement monetary transactions as a function. There have been added to two new functions. One in functions (
QBCore.Functions.TransferMoney
) and other one on player (Player.Functions.TansferTo
), both aproach the same objective, trasnfering money betwwen two players if both are online, online one is online or both are offline.Checklist