Raised This Month: $ Target: $400
 0% 

Cash storage via nick


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CreativeTR
Junior Member
Join Date: Mar 2017
Location: Turkey
Old 03-12-2017 , 08:09   Cash storage via nick
Reply With Quote #1

Example

HTML Code:
new p_Cash[33]
public client_disconnect(id) {
	new p_name[33]
	get_user_name(id, p_name, 33)
	p_Cash[p_name] = current_cash
}
Error: Error: Array must be indexed (variable "p_name") on line blabla

Help
CreativeTR is offline
Send a message via Skype™ to CreativeTR
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-12-2017 , 08:21   Re: Cash storage via nick
Reply With Quote #2

Correct code.
Code:
#include < amxmodx > #define MAX_PLAYERS 33 new g_iStoreCash[ MAX_PLAYERS ] ; public client_disconnect( id ) {     new PlayerName[ 33 ], CurrentCash;     get_user_name( id, PlayerName, charsmax( PlayerName ) )         CurrentCash = cs_get_user_money( id )         g_iStoreCash[ id ] = CurrentCash }

Your Mistake ( Highlighted ) :

Quote:
Originally Posted by CreativeTR View Post
Example

Code:
new p_Cash[33] public client_disconnect(id) {        new p_name[33]  get_user_name(id, p_name, 33) // It should be 32 because 33 - 1 = 32 (last character in a string must be ^0)        p_Cash[p_name] = current_cash }
You should always use Charsmax instead of doing it manually.
__________________

Last edited by edon1337; 03-12-2017 at 08:23.
edon1337 is offline
CreativeTR
Junior Member
Join Date: Mar 2017
Location: Turkey
Old 03-12-2017 , 08:31   Re: Cash storage via nick
Reply With Quote #3

But if i use save via client id method, when player disconnect from server and other player connect server he's client id same from who disconnected

(i am sorry for my bad english)
CreativeTR is offline
Send a message via Skype™ to CreativeTR
CreativeTR
Junior Member
Join Date: Mar 2017
Location: Turkey
Old 03-12-2017 , 08:33   Re: Cash storage via nick
Reply With Quote #4

I want to save user's cash via their nick name

Last edited by CreativeTR; 03-12-2017 at 08:33.
CreativeTR is offline
Send a message via Skype™ to CreativeTR
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-12-2017 , 10:08   Re: Cash storage via nick
Reply With Quote #5

Quote:
Originally Posted by CreativeTR View Post
But if i use save via client id method, when player disconnect from server and other player connect server he's client id same from who disconnected

(i am sorry for my bad english)
I only helped you fix the code you needed help with. Best way is to use [f/n]Vault / SQLx etc.. (As Klippy stated).
__________________

Last edited by edon1337; 03-12-2017 at 10:09.
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-12-2017 , 08:41   Re: Cash storage via nick
Reply With Quote #6

Look into nvault, fvault, MySQL, SQLite or similar. Plugins are not capable of such storage, you need a database.
klippy is offline
CreativeTR
Junior Member
Join Date: Mar 2017
Location: Turkey
Old 03-12-2017 , 09:00   Re: Cash storage via nick
Reply With Quote #7

Thanks KliPPy, I fixed this.
CreativeTR is offline
Send a message via Skype™ to CreativeTR
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-12-2017 , 10:11   Re: Cash storage via nick
Reply With Quote #8

His error was here actually: p_Cash[p_name] = current_cash
He was trying to use the name instead of the user's id.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-12-2017 , 10:14   Re: Cash storage via nick
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
His error was here actually: p_Cash[p_name] = current_cash
He was trying to use the name instead of the user's id.
Yeah, that was the main mistake.
__________________

Last edited by edon1337; 03-12-2017 at 10:14.
edon1337 is offline
Reply


Thread Tools
Display Modes

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 17:55.


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