inherit
203080
0
Mar 17, 2014 14:50:56 GMT -8
baratheon
43
December 2013
baratheon
|
Post by baratheon on Dec 16, 2013 18:41:53 GMT -8
Within a plugin I'm developing, a user can win a game that will reward him with money/credits. But I am unsure of how to implement the Monetary System so that it will automatically send the user a given amount of money if he/she wins. Any ideas?
Thank you in advance.
|
|
Former Member
inherit
guest@proboards.com
131621
0
Dec 1, 2024 16:35:45 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Dec 16, 2013 22:57:46 GMT -8
Gift Money, perhaps?
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Dec 16, 2013 23:08:36 GMT -8
This is taken from the monetary system page. It's actually quite easy. pixeldepth.monetary.add('100'); That should be it. And it will add the current user 100 dollars/points/pesos I believe you can use a number OR a string and it will be interpreted as a number
API For Developers
The Monetary System has a very basic API for other developers to hook into the money system.
For the moment the following methods are implemented.
Note: These are all methods.
pixeldepth.monetary.get - Gets money (see source for params). pixeldepth.monetary.subtract - Removes money (see source for params). pixeldepth.monetary.add - Adds money (see source for params). pixeldepth.monetary.clear - Clears the money amount (see source for params). pixeldepth.monetary.bank.clear_transactions - Clears all the transactions. pixeldepth.monetary.bank.clear_balance - This will clear the bank balance (doesn't touch the wallet). pixeldepth.monetary.bank.get_transactions - Gets the last X transactions. pixeldepth.monetary.disable_earning - Can disable money from being earned for the current page. pixeldepth.monetary.enable_earning - Can enable money to be earned for the current page. pixeldepth.monetary.clear_all - Clears everything for the user (data object is reset). pixeldepth.monetary.clear_last_interest - Clears the last interest timestamp.
Please look through the source to see how they work. If you have questions, or need to know how they work, what parameters etc, please ask. I will try to put better docs together if people start using them.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Dec 16, 2013 23:10:11 GMT -8
|
|
inherit
203080
0
Mar 17, 2014 14:50:56 GMT -8
baratheon
43
December 2013
baratheon
|
Post by baratheon on Dec 27, 2013 15:53:38 GMT -8
I used the pixeldepth.monetary.add(value) function to add money for the current user successfully, but now I need to input money for a specific user. I looked through the source code but there doesn't seem to be a parameter to specify the user in the add() function. The only parameters besides the value are the bank, and the no_update parameters, and I'm not sure if I understand them.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,023
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Dec 27, 2013 17:31:14 GMT -8
I used the pixeldepth.monetary.add(value) function to add money for the current user successfully, but now I need to input money for a specific user. I looked through the source code but there doesn't seem to be a parameter to specify the user in the add() function. The only parameters besides the value are the bank, and the no_update parameters, and I'm not sure if I understand them. Peter would obviously be most qualified to answer this but in his absence I took a look and reached the conclusion that the plugin is geared to interact with the current user only. The yootil function the monetary plugin's add function calls however ( yootil.key.set) does have provisions to specify a user ID so I would simply bypass the add function and go directly to the yootil function where you could then specify a user ID not necessarily matching the user ID of the current user. Just be sure you're comfortable with the data format expected to avoid corrupting the key. yootil.key.set("pixeldepth_money", this.data, null, true);the null param would be where you would specify the user ID (null says use current user ID)
|
|
inherit
203080
0
Mar 17, 2014 14:50:56 GMT -8
baratheon
43
December 2013
baratheon
|
Post by baratheon on Dec 27, 2013 18:36:25 GMT -8
I'm not sure if I understand the parameters...
Say, I need to add 100 credits into Mike's account, that would mean I'd do yootil.key.set("pixeldepth_money", "100", "Mike", true), is this correct?
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,023
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Dec 27, 2013 19:14:53 GMT -8
I'm not sure if I understand the parameters... Say, I need to add 100 credits into Mike's account, that would mean I'd do yootil.key.set("pixeldepth_money", "100", "Mike", true), is this correct? That is what I meant by first understanding the data format to avoid corrupting the key's data, for example the monetary plugin makes the call using this.data as the param so you would then look to see what structure this.data uses and it is right there in the source of the monetary plugin { // General money (aka wallet) m: 0, // Bank b: 0, // Last transactions lt: [], // Last interest date li: "", // Stock market s: {}, // Wages w: {} } It is that structure that is used in that param so you would use that same structure when making your bypass call. This is the format used in that key so you would most likely grab the key data for that user ID first to then add the money to money that user may already have. As for the user ID it specifically says "integer" in the documentation I linked you to so that would have to be the numeric ID of the user not the username or display name
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Dec 27, 2013 19:21:49 GMT -8
Isn't the key a Super User Key? That means he wouldn't be able to add the money without the user being loaded on the page anyway right? My solution would be to allow the user to collect the money when they are logged in. (via confirm dialogue or a button to collect, which also requires a separate key)
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Dec 27, 2013 19:31:10 GMT -8
Eton is saying it will look more like this: var data = {m: 0,b: 0,lt: [],li: "",s: {},w: {}} yootil.key.set("pixeldepth_money", data, 1, true),
1 is the proboards.data('user').id data is the object containing all of the user's current data + adding to the m: 0, amount. However if you add to the user's money like this and they are busy doing something that would make the original plugin set that key, like making a single post. It will overwrite all of your changes as if it never happened. That is why Texas made it only for the current user, and why I advise you not even attempt this method.
|
|
inherit
203080
0
Mar 17, 2014 14:50:56 GMT -8
baratheon
43
December 2013
baratheon
|
Post by baratheon on Dec 28, 2013 9:49:54 GMT -8
I went with pasuleo's solution, and just sent a confirmation message to the winner. I appreciate all your responses, though. You've been really helpful to me, and I'm grateful for your fast replies.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Dec 29, 2013 1:07:38 GMT -8
I proposed the solution I did because I ran into the exact same problem myself, and that was the best I came up with. It's easier and safer.
|
|