AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cash storage via nick (https://forums.alliedmods.net/showthread.php?t=294961)

CreativeTR 03-12-2017 08:09

Cash storage via nick
 
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

edon1337 03-12-2017 08:21

Re: Cash storage via nick
 
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 (Post 2502962)
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.

CreativeTR 03-12-2017 08:31

Re: Cash storage via nick
 
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 03-12-2017 08:33

Re: Cash storage via nick
 
I want to save user's cash via their nick name

klippy 03-12-2017 08:41

Re: Cash storage via nick
 
Look into nvault, fvault, MySQL, SQLite or similar. Plugins are not capable of such storage, you need a database.

CreativeTR 03-12-2017 09:00

Re: Cash storage via nick
 
Thanks KliPPy, I fixed this.

edon1337 03-12-2017 10:08

Re: Cash storage via nick
 
Quote:

Originally Posted by CreativeTR (Post 2502975)
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).

OciXCrom 03-12-2017 10:11

Re: Cash storage via nick
 
His error was here actually: p_Cash[p_name] = current_cash
He was trying to use the name instead of the user's id.

edon1337 03-12-2017 10:14

Re: Cash storage via nick
 
Quote:

Originally Posted by OciXCrom (Post 2503000)
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.


All times are GMT -4. The time now is 17:55.

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