Raised This Month: $ Target: $400
 0% 

Creating some sort of cash system while being a beginner


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rapidgame7
Member
Join Date: Jul 2014
Location: In planet Earth
Old 01-20-2015 , 23:42   Creating some sort of cash system while being a beginner
Reply With Quote #1

Well, after seeing the several mods out there and seeing that the plugin I need isn't there, I'd like to know:
How hard is to make a variable that is stored for every player and is also saved in a database or something?

I want to make a way to add "cash" into TF2, giving every player "money" (that actually is a variable I guess) that is saved on a database every now and then and when they disconnect, also admins can modify it to their liking and players would be able to "trade" their money to anyone in the server.

I'd like to know what I'm about to get into and how hard it may be.
I'm still learning, and all I learnt is to set variables.
__________________
Learning AngelScript I guess?
Rapidgame7 is offline
Send a message via Skype™ to Rapidgame7
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 01-21-2015 , 00:08   Re: Creating some sort of cash system while being a beginner
Reply With Quote #2

I suppose you can use a series of adt_arrays or regular arrays with client index as an array index:

Code:
new String:PlayerIDs[32][25];
new PlayerCash[32];
and just index via client index to access their steam ID/cash amount. Then you can hook to the Client connect/client disconnect events (basically, a function that is called if a client disconnects or connects to the server) to retrieve information from the database (on client connect) or add/update information in the database (on client disconnect).

Basically, use client ID as a "key", and then use a couple of arrays to store the client's steam ID & cash amounts. You can increment/decrement cash amounts by accessing the arrays at specific indices (so player 1 might be client index 2, so to get player 1's cash you would do PlayerCash[2] or PlayerCash[iClient] where iClient is 2). Then when the client leaves, you can then "dump" (store) that data into a database (requires some basic sql knowledge, like INSERT INTO or UPDATE commands).

Storing client steam IDs and client money values, and adding/editing/retrieving information from/to a database, should not be difficult. If anything, it's the stuff you want them to do with the money (like trading as you said) that would be a little more complicated.
Potato Uno is offline
Rapidgame7
Member
Join Date: Jul 2014
Location: In planet Earth
Old 01-21-2015 , 00:48   Re: Creating some sort of cash system while being a beginner
Reply With Quote #3

Thanks for the explanation!
__________________
Learning AngelScript I guess?
Rapidgame7 is offline
Send a message via Skype™ to Rapidgame7
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 01-21-2015 , 03:27   Re: Creating some sort of cash system while being a beginner
Reply With Quote #4

Your best option (if is just the money variable and you don't want to get into SQL) is to use the client cookies with private settings.

So OnClientCookiesCached you get their cookie value, and on client disconnect you set them. Of course you use a normal vector to save the money while the client is on the server. Also don't forget to call OnClientDisconnect for every connected player on plugin end so they values are saved when you unload the plugin for some reason.
ClassicGuzzi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode