Raised This Month: $12 Target: $400
 3% 

Storing data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 01-28-2020 , 17:07   Storing data
Reply With Quote #1

hey,
looking for suggestions on how to store data into player variable efficiently.

Player can have unlimited count of skins.
Stored data will look something like this in MySQL: id (int), skin_id (int), nametag (string), kills (int), hs (int), damage (double)

What would be the best approach?
__________________

Last edited by Airkish; 01-28-2020 at 17:07.
Airkish is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-28-2020 , 17:28   Re: Storing data
Reply With Quote #2

Does each skin have all of the columns below? Or are skins in a separate table which has skin_id as PK?
When you say unlimited, what is the max you would ever expect?
How does this data need to be referenced? Is there a steam-id field that you are not showing?

Give some context for your usage of this data.

id (int) - Is this the primary key ID, or player ID
skin_id (int)
nametag (string) - Is this player name or name of skin?
kills (int)
hs (int)
damage (double)
__________________
Bugsy is online now
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 01-29-2020 , 01:15   Re: Storing data
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Does each skin have all of the columns below? Or are skins in a separate table which has skin_id as PK?
When you say unlimited, what is the max you would ever expect?
How does this data need to be referenced? Is there a steam-id field that you are not showing?

Give some context for your usage of this data.

id (int) - Is this the primary key ID, or player ID
skin_id (int)
nametag (string) - Is this player name or name of skin?
kills (int)
hs (int)
damage (double)
I might have missed some info. Skins are retrieved from .cfg file, I thought about storing them in MySQL but it will take more time to load, right? And how would I go about precaching models then?

id - primary key ID
user_id - user id, references another table
skin_id - skin_id, with this id I retrieve info about skin from skins array
is_stattrak (int) - if true, will allow to level up skin, track hs, kills, damage
level - skin level
kills -
hs -
damage -

I expect user to have ~1000 skins at some point.

This data will be shown in users inventory.
2 types - stattrak and normal (wont track stats)
They will be able to equip them.

PHP Code:
SELECT FROM `user_skinsWHERE user_id '%d' 
PHP Code:
while(SQL_MoreResults(Query)) {
//Storing data, best approach?

__________________
Airkish is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-29-2020 , 07:15   Re: Storing data
Reply With Quote #4

Quote:
I expect user to have ~1000 skins at some point.
That's not a valid expectation since you can't have more than 512 total resources in your server.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 01-29-2020 , 09:43   Re: Storing data
Reply With Quote #5

Quote:
Originally Posted by OciXCrom View Post
That's not a valid expectation since you can't have more than 512 total resources in your server.
I know that.
Player can have multiple skins (skins != models) which uses same model, that's the point.
Think of it like cs:go, where you can have multiple same skins but they have different values (kills, type, etc.)
__________________
Airkish is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-30-2020 , 19:21   Re: Storing data
Reply With Quote #6

So are you looking for help on an overall data storage system or only for your skills/skins/models or whatever? I need the full picture to help you.
__________________
Bugsy is online now
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 01-31-2020 , 04:48   Re: Storing data
Reply With Quote #7

This is bare bones of csgo mod I made before amx studio glitched out and deleted almost a completely finished mod. I suggest you rewriting player login to use only steamid and password if necessary (talking about non-steam), as it became a headache to handle and deciding which login type to prioritise if two of the accounts somehow match the combination of name / ip /steamid...

This would be a good starting point to make an API out of it and add shop, trading and etc as separate plugins communicating only through natives. Otherwise, at some point, it becomes almost unbearable to dig through all that code after some time has passed. All in all, it should have all the basic functionality, such as saving/loading/equipping skins. If you're gonna use this as the starting point, start by deleting ip/nickname save methods. Also, after each item operation such as trading, case opening, getting a key, I would suggest saving it with a threaded query.
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <sqlx>
#include <cellarray>

#define OWNER ADMIN_RCON

//sql************************
new Host[]     = "127.0.0.1"
new User[]    = ""
new Pass[]     = ""
new Db[]     = ""
//sql************************
//cvars
new cvar_password_lenght

//end of cvars
new Handle:g_SqlTuple
new g_Error[512]

new ID[33]
//case opening
new times[][] = {"0.2", "0.4", "0.5", "0.6", "0.7", "0.8", "1.0", "1.1", "1,2", "1,5"}

//case opening end
new equiped[33][33]
new player_weapons[33][256]//player_id//skin_id
new player_skins[33][35]
//csgo_weapons******************
new skin_id[256]
new weapon_name[256][32]
new model_v[256][32]
new model_p[256][32]
new model_w[256][32]
new weapon_id[256]
new cost[256]
new chance[256]
new flags[256][32]
new chest[256]
//csgo_weapons end******************

//login stuff
new password[33][32]

new login_data[33][32]
new login_type[33]
new login_types[][] = {
	"STEAM_ID",
	"IP",
	"NAME",
	"STEAM_ID"
	
}
new loged[33]

//login stuff end

new equipmenu[33]
new gunm[33], adminm[33], adminID[33]

new player_menuMode[33]

new adminm_items[][] = {
	"\yset \wpoints",
	"\ygive \wpoints",
	"\ygive \witem",
	"\ygive \wkeys",
	"\ygive \wcases",
	"\ywipe \winventory"	
}

new default_skins_v[][] = {
	"models/v_ak47.mdl",
	"models/v_m4a1.mdl",
	"models/v_awp.mdl",
	"models/v_scout.mdl",
	"models/v_galil.mdl",
	"models/v_famas.mdl",
	"models/v_sg552.mdl",
	"models/v_aug.mdl",
	"models/v_xm1014.mdl",
	"models/v_m3.mdl",
	"models/v_ump45.mdl",
	"models/v_mac10.mdl",
	"models/v_mp5navy.mdl",
	"models/v_m249.mdl",
	"models/v_tmp.mdl",
	"models/v_g3sg1.mdl",
	"models/v_sg550.mdl",
	"models/v_p90.mdl",
	
	"models/v_deagle.mdl",
	"models/v_p228.mdl",
	"models/v_elite.mdl",
	"models/v_fiveseven.mdl",
	"models/v_glock18.mdl",
	
	"models/v_hegrenade.mdl",
	"models/v_smokegrenade.mdl",
	"models/v_flashbang.mdl",
	"models/v_c4.mdl",
	
	"models/v_knife.mdl"
}

new default_skins_p[][] = {
	"models/p_ak47.mdl",
	"models/p_m4a1.mdl",
	"models/p_awp.mdl",
	"models/p_scout.mdl",
	"models/p_galil.mdl",
	"models/p_famas.mdl",
	"models/p_sg552.mdl",
	"models/p_aug.mdl",
	"models/p_xm1014.mdl",
	"models/p_m3.mdl",
	"models/p_ump45.mdl",
	"models/p_mac10.mdl",
	"models/p_mp5navy.mdl",
	"models/p_m249.mdl",
	"models/p_tmp.mdl",
	"models/p_g3sg1.mdl",
	"models/p_sg550.mdl",
	"models/p_p90.mdl",
	
	"models/p_deagle.mdl",
	"models/p_p228.mdl",
	"models/p_elite.mdl",
	"models/p_fiveseven.mdl",
	"models/p_glock18.mdl",
	
	"models/p_hegrenade.mdl",
	"models/p_smokegrenade.mdl",
	"models/p_flashbang.mdl",
	"models/p_c4.mdl",
	
	"models/p_knife.mdl"
}
new guns[][] = {
	"AK47",
	"M4A1",
	"AWP",
	"Scout",
	"Galil",
	"Famas",
	"sg552",
	"AUG",
	"XM1014",
	"M3",
	"ump45",
	"mac10",
	"MP5navy",
	"M249",
	"TMP",
	"G3SG1",
	"sg550",
	"P90",
				
	"Deagle",
	"P228",
	"elite",
	"FiveSeven",
	"Glock18",
				
	"He nade",
	"Smoke nade",
	"Flashbang",
	"C4",
	
	"Knife"
}

new gun_count

new gunsid[] = {28, 22, 18, 3, 14, 15, 27, 8, 5, 21, 12, 7, 19, 20, 23 ,24, 13, 30,   26, 1, 10, 11, 17,   4, 9, 25, 6,   29}
//new gunscsw[]= {CSW_AK47, CSW_M4A1, CSW_AWP, CSW_SCOUT, CSW_GALIL, CSW_FAMAS, CSW_SG552, CSW_AUG, CSW_XM1014, CSW_M3, CSW_UMP45, CSW_MAC10, CSW_MP5NAVY, CSW_M249,
//		   CSW_TMP, CSW_G3SG1, CSW_SG550, CSW_P90, CSW_DEAGLE, CSW_P228, CSW_ELITE, CSW_FIVESEVEN, CSW_GLOCK18, CSW_HEGRENADE, CSW_SMOKEGRENADE, CSW_FLASHBANG, CSW_C4, CSW_KNIFE}

new RANKS[33]
new ranks[][] = {
	"Unranked",
	"Silver I",
	"Silver II",
	"Silver III",
	"Silver IV",
	"Silver elite",
	"Silver elite master",
	"Gold nova I",
	"Gold nova II",
	"Gold nova III",
	"Gold nova Master",
	"Master Guardian I",
	"Master Guardian II",
	"Master Guardian ELITE",
	"Distinguished Master Guardian",
	"Legendary Eagle",
	"Legendary Eagle Master",
	"Supreme Master FIRST CLASS",
	"Global Elite"
}
new keys[33], points[33], kills[33]
new chests[33][100]
new cases[330][24]

new tpoints[33], tid[33]

public plugin_init() {
	register_plugin("CS:GO mod", "1.0", "Softero")
	register_event("CurWeapon", "change_model", "be", "1=1")
	//cvars
	cvar_password_lenght = register_cvar("minimum_password_lenght", "6")
	//stuff
	register_clcmd( "say /menu","main_menu" );	register_clcmd( "team_say /menu","main_menu" )
	//register_clcmd( "say /reg","reg_menu" );	register_clcmd( "team_say /reg","reg_menu" )
	register_clcmd( "say test","test_say" )
	
	register_clcmd("CSGOset", "set_password")

	register_clcmd("CSGOinput", "adminm_menu_handler2")
	
	register_clcmd("CSGOset_points", "input_points")

	
	register_clcmd("chooseteam", "main_menu")
	//events
}

public plugin_precache() {
	MySql_Init()
	
	new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
	if(SqlConnection == Empty_Handle)
		set_fail_state(g_Error)
	
	new szTemp[512]
	format(szTemp,charsmax(szTemp),"SELECT * FROM `csgo_weapons` ORDER BY 'ID'")
	new Handle:Query = SQL_PrepareQuery(SqlConnection, szTemp)
	
	if(!SQL_Execute(Query)) {
		SQL_QueryError(Query,g_Error,511)
		set_fail_state(g_Error)	
	}
	
	if(SQL_NumResults(Query) < 1)
		return PLUGIN_CONTINUE
	else 
	{
		gun_count = SQL_AffectedRows(Query)
		for(new i = 0; i < gun_count; ++i) {
			skin_id[i] = SQL_ReadResult(Query, 0)
			SQL_ReadResult(Query, 1, weapon_name[i], 55)
			SQL_ReadResult(Query, 2, model_v[i], 55)
			SQL_ReadResult(Query, 3, model_p[i], 55)
			SQL_ReadResult(Query, 4, model_w[i], 55)
			weapon_id[i] = SQL_ReadResult(Query, 5)
			cost[i] = SQL_ReadResult(Query, 6)
			SQL_ReadResult(Query, 7, chance[i], 55)
			SQL_ReadResult(Query, 8, flags[i], 55)
			chest[i] = SQL_ReadResult(Query, 9)
			if(strlen(model_v[i]) > 7)
				precache_model(model_v[i])
			if(strlen(model_p[i]) > 7)
				precache_model(model_p[i])
			if(strlen(model_w[i]) > 7)
				precache_model(model_w[i])
			
			SQL_NextRow(Query)
		}
	}
	return PLUGIN_HANDLED
}

public test_say(id) {
	//client_print(id, print_chat, "%s  %i  %i", model_v[0], gunsid[0], weapon_id[0])
	
	
}

public set_password(id) {
	new data[192], lenght = get_pcvar_num(cvar_password_lenght)
	read_args(data, charsmax(data))
	remove_quotes(data)
	if(strlen(data) < lenght) {
		format(data, charsmax(data), "^4[^3playcounter^4]^1 password is too short. Minimum %d characters", lenght)
		client_print_color(id, print_chat, data)
	}
	else {
		copy(password[id], charsmax(password[]), data)
		format(data, charsmax(data), "^4[^3playcounter^4]^1 Your password is: ^4%s", password[id])
		client_print_color(id, print_chat, data)
	}
	account_menu(id)
	return PLUGIN_HANDLED
}

public input_points(id) {
	new data[12]
	read_args(data, charsmax(data))
	if(!is_str_num(data)) {
		
		points_menu(id)
		return PLUGIN_HANDLED
	}
	
	clamp(tpoints[id] = str_to_num(data), 0, 99999999)
	points_menu(id)
	return PLUGIN_HANDLED
}

public main_menu(id) {
	new temp[512]
	format(temp,charsmax(temp),"\wYou have [\r%i\w] points^nRank: \w[\y%s\w]", points[id], ranks[RANKS[id]])
	new menu = menu_create( temp, "main_menu_handler" );
	//new call = menu_makecallback("Call_Back");
	
	//menu_additem( menu, "\yTapti \rSaimonu", _, _, ( g_SimonCount == 0 ) ? -1 : call )
	format(temp,charsmax(temp),"Inventory")//inventory
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"Shop")//shop
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"market")//market
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"gifts")//gifts
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"settings")//account management
	menu_additem( menu, temp)
	if(get_user_flags(id) & ADMIN_CVAR)
		menu_additem( menu, "\r admin menu")

	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE

}

public main_menu_handler(id, menu, item) {
	menu_destroy(menu)
	switch(item)
	{	
		case 0:	inv_menu(id)
		case 1:	shop_menu(id)
		case 2:	market_menu(id)
		case 3:	gift_menu(id)
		case 4: account_menu(id)
		case 5:	admin_menu(id)
		default: return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

public account_menu(id) {
	new temp[128]
	switch(login_type[id]) {
		case 0: get_user_authid(id, login_data[id], 31)
		case 1: get_user_ip(id, login_data[id], 31, 1)
		case 2: get_user_name(id, login_data[id], 31)
	}
	
	if(login_type[id] == 2)
		formatex(temp,charsmax(temp),"\wSave type: \r%s^n\wYour \r%s: \y%s^n\wYour unique \yID:\r %i^n\yPassword: \r%s", login_types[login_type[id]], login_types[login_type[id]], login_data[id], ID[id], password[id])
	else
		formatex(temp,charsmax(temp),"\wSave type: \r%s^n\wYour \r%s: \y%s^n\wYour unique \yID:\r %i", login_types[login_type[id]], login_types[login_type[id]], login_data[id], ID[id])
	new menu = menu_create( temp, "account_menu_handler" )
	new call = menu_makecallback("Call_Back")
	
	format(temp,charsmax(temp), "\wchange save type \y(\d%s\y)", login_types[login_type[id]+1])//change save type
	menu_additem( menu, temp)
	format(temp,charsmax(temp), "\wset password \y(\dname only\y)", login_types[login_type[id]+1])//set_password
	menu_additem( menu, temp, _, _, (login_type[id] == 2) ? -1 : call )

	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE
}

public account_menu_handler(id, menu, item) {
	menu_destroy(menu)
	switch(item)
	{	
	case MENU_EXIT: main_menu(id)
		case 0: {
			login_type[id]+=1
			if(login_type[id] == 3)
				login_type[id] = 0
			account_menu(id)
		}
		case 1:
			client_cmd(id, "messagemode CSGOset")
		
		default: return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

public inv_menu(id) {

	new temp[512]
	format(temp,charsmax(temp),"Inventory: %s", points[id], ranks[RANKS[id]])
	new menu = menu_create( temp, "inv_menu_handler" )
	//new call = menu_makecallback("Call_Back");
	
	//menu_additem( menu, "\yTapti \rSaimonu", _, _, ( g_SimonCount == 0 ) ? -1 : call )
	format(temp,charsmax(temp),"Equip skins")//equip
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"Open cases \d[\r%i\d] \ykeys", keys[id])//open
	menu_additem( menu, temp)

	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE
}

public inv_menu_handler(id, menu, item) {
	menu_destroy(menu)
	switch(item)
	{	
		case 0:	equip_menu(id)
		case 1:	case_menu(id)
		default: main_menu(id)
	}
	return PLUGIN_HANDLED
}

public equip_menu(id) {

	new temp[512]
	format(temp,charsmax(temp),"You have \r[\w%i\r]\w \rpoints\w\n Rank: %s", points[id], ranks[13])
	new menu = menu_create( temp, "equip_menu_handler" )
	new call = menu_makecallback("Call_Back")
	
	//menu_additem( menu, "\yTapti \rSaimonu", _, _, ( g_SimonCount == 0 ) ? -1 : call )
	format(temp,charsmax(temp),"Rifles")
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"Pistols")
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"Knifes")/////////
	menu_additem( menu, temp, _, _, (player_skins[id][gunsid[27]] > 0 ) ? -1 : call)
	format(temp,charsmax(temp),"Nades")
	menu_additem( menu, temp)


	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE

}

public equip_menu_handler(id, menu, item) {
	menu_destroy(menu)
	if(item == MENU_EXIT) {
		inv_menu(id)
		return PLUGIN_HANDLED
	}
	equipmenu[id]=item
	equip_weapons_menu(id)
	return PLUGIN_HANDLED
}

public equip_weapons_menu(id) {

	new temp[512], temp1
	new call = menu_makecallback("Call_Back");
	switch(equipmenu[id])
	{
		case 0:{
			format(temp,charsmax(temp),"\w[\rCSGO\w] Rifles:^n")
			new menu = menu_create( temp, "equip_weapons_menu_handler")
			for(new i=0; i<=17; i++) {
				format(temp,charsmax(temp),"%s", guns[i])
				menu_additem( menu, temp, _, _, (player_skins[id][gunsid[i]] > 0 ) ? -1 : call )
			}

			menu_display( id, menu, 0 )
			return PLUGIN_CONTINUE
		}
		case 1:{
			format(temp,charsmax(temp),"\w[\rCSGO\w] Pistols:^n")
			new menu = menu_create( temp, "equip_weapons_menu_handler")
			
			for(new i=18; i<=22; i++)
				if(player_skins[id][gunsid[i]]!=0) {
					temp1+=1
					break
				}
			for(new i=18; i<=22; i++) {
				format(temp,charsmax(temp),"%s", guns[i])
				menu_additem( menu, temp, _, _, (temp1 < 0 ) ? -1 : call)
			}

			menu_display( id, menu, 0 )
			return PLUGIN_CONTINUE
		}
		case 2: {
			gunm[id]=27
			equip_sub_menu(id)
			return PLUGIN_HANDLED
		}
		case 3: {
			format(temp,charsmax(temp),"\w[\rCSGO\w] Explosives:^n")
			new menu = menu_create( temp, "equip_weapons_menu_handler")
			for(new i=23; i<=26; i++)
				if(player_skins[id][gunsid[i]]!=0) {
					temp1+=1
					break
				}
			for(new i=23; i<=26; i++) {
				format(temp,charsmax(temp),"%s", guns[i])
				menu_additem( menu, temp, _, _, ( temp1 < 0 ) ? -1 : call )
			}
			
			menu_display( id, menu, 0 )
			return PLUGIN_CONTINUE
		}
	}
	return PLUGIN_CONTINUE
}

public equip_weapons_menu_handler(id, menu, item) {
	menu_destroy(menu)
	if(item == MENU_EXIT) {
		equip_menu(id)
		return PLUGIN_HANDLED
	}
	gunm[id] = item
	equip_sub_menu(id)
	return PLUGIN_HANDLED
}

public equip_sub_menu(id) {
	
	static temp[512], i
	new data[32]
	formatex(temp,charsmax(temp),"\w[\rCSGO\w]\w %s skins:", guns[gunm[id]])
	new menu = menu_create( temp, "equip_sub_menu_handler" )
	new call = menu_makecallback("Call_Back")
	menu_additem( menu, "reset skin")
	for(i=0; i<gun_count; i++) {
		if(weapon_id[i] == gunsid[gunm[id]]) {
			formatex(temp,charsmax(temp),"\w%s \y(\r%d\y)", weapon_name[i], player_weapons[id][i])
			formatex(data, charsmax(data), "%d", i)
			menu_additem( menu, temp, data, _, (player_weapons[id][i]>0 && equiped[id][i]!=-1) ? -1 : call )
		}
	}

	menu_display( id, menu, 0 )
	return PLUGIN_HANDLED
}

public equip_sub_menu_handler(id, menu, item) {
	if( item == MENU_EXIT) {
		menu_destroy(menu)
		equip_weapons_menu(id)
		return PLUGIN_HANDLED
	}
	if(item == 0) {
		menu_destroy(menu)
		equiped[id][gunsid[gunm[id]]] = 0
		if(get_user_weapon(id) == gunsid[gunm[id]]) {
			set_pev(id, pev_viewmodel2, default_skins_v[gunm[id]])
			set_pev(id, pev_weaponmodel2, default_skins_p[gunm[id]])
		}
		equip_sub_menu(id)
		return PLUGIN_HANDLED
	}
	new data[6], szName[64]
	new _access, item_callback
	menu_item_getinfo(menu, item, _access, data,charsmax(data), szName,charsmax(szName), item_callback)
	new i = str_to_num(data)
	equiped[id][gunsid[gunm[id]]] =i+1
	if(get_user_weapon(id) == gunsid[gunm[id]]) {
		if(strlen(model_v[i]) > 7)
			set_pev(id, pev_viewmodel2, model_v[i])
		else
			set_pev(id, pev_viewmodel2, default_skins_v[gunm[id]])
		if(strlen(model_p[i]) > 7)
			set_pev(id, pev_weaponmodel2, model_p[i])
		else
			set_pev(id, pev_weaponmodel2, default_skins_p[gunm[id]])
	}
	menu_destroy(menu)
	equip_sub_menu(id)
	return PLUGIN_HANDLED
}

public admin_menu(id) {
	new menu = menu_create( "\y admin menu", "admin_menu_handler" )
	
	for(new i; i<sizeof(adminm_items); i++)
		menu_additem( menu, adminm_items[i])

	menu_display( id, menu, 0)
	return PLUGIN_CONTINUE
}

public admin_menu_handler(id, menu, item) {
	menu_destroy(menu)
	if(item == MENU_EXIT) {
		main_menu(id)
		return PLUGIN_HANDLED
	}
	adminm[id] = item+1
	adminm_menu(id)
	return PLUGIN_CONTINUE
}

public adminm_menu(id) {
	new menu = menu_create( "%s", adminm_items[id])
	new players[32], name[32], data[4], count
	get_players(players, count)
	for(new i; i<count; i++) {
		formatex(data, charsmax(data), "%d", players[i])
		get_user_name(players[i], name, charsmax(name))
		menu_additem(menu, name, data)
	}
	menu_display(id, menu, 0)
	return PLUGIN_CONTINUE
}

public adminm_menu_handler(id, menu, item) {
	menu_destroy(menu)
	if(item == MENU_EXIT) {
		admin_menu(id)
		return PLUGIN_HANDLED
	}
	new data[6], szName[64]
	new _access, item_callback
	menu_item_getinfo(menu, item, _access, data,charsmax(data), szName,charsmax(szName), item_callback)
	adminID[id] = str_to_num(data)
	client_cmd(id, "messagemode CSGOinput")
	
	return PLUGIN_HANDLED
}

public adminm_menu_handler2(id) {
	if(!(get_user_flags(id) & ADMIN_CVAR))
		return PLUGIN_CONTINUE
	new data[16]
	read_args(data, charsmax(data))
	if(!is_str_num(data))
		return PLUGIN_HANDLED
	
	return PLUGIN_HANDLED
}

public case_menu(id) {

	new temp[512]
	format(temp,charsmax(temp),"You have \r%i \ykeys", keys[id])
	new menu = menu_create( temp, "case_menu_handler" )
	new call = menu_makecallback("Call_Back")
	
	format(temp,charsmax(temp),"Chroma case [%i]", cases[id][0])
	menu_additem( menu, temp, _, _, ( cases[id][0] > 0 ) ? -1 : call )
	format(temp,charsmax(temp),"Gamma case [%i]", cases[id][1])
	menu_additem( menu, temp, _, _, ( cases[id][1] > 0 ) ? -1 : call )
	format(temp,charsmax(temp),"Vanguard case [%i]", cases[id][2])
	menu_additem( menu, temp, _, _, ( cases[id][2] > 0 ) ? -1 : call )
	format(temp,charsmax(temp),"E-Sports case [%i]", cases[id][3])
	menu_additem( menu, temp, _, _, ( cases[id][3] > 0 ) ? -1 : call )
	format(temp,charsmax(temp),"reload")
	menu_additem( menu, temp)
	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE

}

public case_menu_handler(id, menu, item) {
	switch(item)
	{
		case 4: case_menu(id)
		default: return PLUGIN_CONTINUE
	}
	return PLUGIN_CONTINUE
}

public shop_menu(id) {

	new temp[512]
	format(temp,charsmax(temp),"You have \r[\w%i\r]\w \rpoints\w\n Rank: %s", points[id], ranks[RANKS[id]])
	new menu = menu_create( temp, "shop_menu_handler" );
	//new call = menu_makecallback("Call_Back")
	
	//menu_additem( menu, "\yTapti \rSaimonu", _, _, ( g_SimonCount == 0 ) ? -1 : call )
	format(temp,charsmax(temp),"Inventory")//inventory
	menu_additem( menu, temp)

	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE

}

public shop_menu_handler(id, menu, item) {
	switch(item)
	{	
		case 0:{
			inv_menu(id)
		}

	}
	return PLUGIN_CONTINUE
}

public market_menu(id) {

	new temp[512]
	format(temp,charsmax(temp),"You have \r[\w%i\r]\w \rpoints\w\n Rank: %s", points[id], ranks[13])
	new menu = menu_create( temp, "market_menu_handler" )
	//new call = menu_makecallback("Call_Back");
	
	//menu_additem( menu, "\yTapti \rSaimonu", _, _, ( g_SimonCount == 0 ) ? -1 : call );
	format(temp,charsmax(temp),"Inventory")//inventory
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"Shop")//shop
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"market")//market
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"Send gifts")//gifts
	menu_additem( menu, temp)

	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE

}

public market_menu_handler(id, menu, item) {
	switch(item)
	{	
		case 0:{
			inv_menu(id)
		}

	}
	return PLUGIN_CONTINUE
}

public gift_menu(id) {

	new temp[512]
	format(temp,charsmax(temp),"You have \r[\w%i\r]\w \rpoints\w\n Rank: %s", points[id], ranks[RANKS[id]])
	new menu = menu_create( temp, "gift_menu_handler" )
	//new call = menu_makecallback("Call_Back")
	
	//menu_additem( menu, "\yTapti \rSaimonu", _, _, ( g_SimonCount == 0 ) ? -1 : call)
	format(temp,charsmax(temp),"points")//inventory
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"chests/keys")//shop
	menu_additem( menu, temp)
	format(temp,charsmax(temp),"items")//gifts
	menu_additem( menu, temp)

	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE
}

public gift_menu_handler(id, menu, item) {
	switch(item)
	{	
		case MENU_EXIT:	main_menu(id)
		case 0: {
			player_menuMode[id] = 1
			player_menu(id)
		}
		case 1: {
			player_menuMode[id] = 2
			player_menu(id)
		}
		case 2: {
			player_menuMode[id] = 3
			player_menu(id)
		}
		default: return PLUGIN_CONTINUE

	}
	return PLUGIN_HANDLED
}

public player_menu(id) {
	new temp[512]
	switch(player_menuMode[id]) {
		case 0: format(temp,charsmax(temp),"\rERROR")
		case 1:	format(temp,charsmax(temp),"\wChoose player \y[\rpoints\y]\w:")
		case 2:	format(temp,charsmax(temp),"\wChoose player \y[\rchests/keys\y]\w:")
		case 3:	format(temp,charsmax(temp),"\wChoose player \y[\ritems\y]\w:")
		
	}
	new menu = menu_create( temp, "player_menu_handler" )
	new players[32], pname[32], data[6], pnum, pid
	get_players(players, pnum, "")

	for(new i; i<pnum; i++)	{
		pid = players[i]
		get_user_name(pid, pname, charsmax(pname))
		formatex(data, charsmax(data), "%i", pid)
		menu_additem(menu, pname, data, 0)
	}

	menu_display(id, menu, 0)
}

public player_menu_handler(id, menu, item) {
	if(item == MENU_EXIT) {
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}
	new szData[6], szName[64]
	new _access, item_callback
	menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback )
	
	new data[6], _dummy, pid
	menu_item_getinfo(menu, item, _dummy, data, charsmax(data), .callback = _dummy)
	
	pid = str_to_num(data)
	tid[id] = pid
	


	if(pid && is_user_connected(pid))	{
		switch(player_menuMode[id]) {
			case 0:	{
				
			
			}
			case 1:	{//points
				
			
			}
			case 2:	{//chests/keys
				
			
			}
			case 3:	{//items
				
			
			}
		}
	}
	return PLUGIN_HANDLED
}
 
public points_menu(id) {
	new temp[128]
	format(temp,charsmax(temp),"You have \r[\w%i\r]\w \rpoints\n\wselected: \r%i \ypoints", points[id], tpoints[id])
	new menu = menu_create(temp, "points_menu_handler")
	new call = menu_makecallback("Call_Back")
	
	
	format(temp, charsmax(temp), "Increase by \r1")//by 1
	menu_additem(menu, temp, _, _, (tpoints[id]+1<=points[id]) ? -1 : call)
	format(temp, charsmax(temp), "Increase by \r10")//by 10
	menu_additem(menu, temp, _, _, (tpoints[id]+10<=points[id]) ? -1 : call)
	format(temp, charsmax(temp), "Increase by \r100")//by 100
	menu_additem(menu, temp, _, _, (tpoints[id]+100<=points[id]) ? -1 : call)
	menu_addblank(menu, 0)
	format(temp, charsmax(temp), "Decrease by \r1")//by 1
	menu_additem(menu, temp, _, _, (tpoints[id]-1<=tpoints[id]) ? -1 : call)
	format(temp, charsmax(temp), "Decrease by \r10")//by 10
	menu_additem(menu, temp, _, _, (tpoints[id]-10<=tpoints[id]) ? -1 : call)
	format(temp, charsmax(temp), "Decrease by \r100")//by 100
	menu_additem(menu, temp, _, _, (tpoints[id]-100<=tpoints[id]) ? -1 : call)
	format(temp, charsmax(temp), "reset to 0")
	menu_additem(menu, temp, _, _, (tpoints[id]!=0) ? -1 : call)
	format(temp, charsmax(temp), "Input number")//input
	menu_additem(menu, temp)
	
	format(temp, charsmax(temp), "Send points")//send
	menu_additem(menu, temp)
	
	
	menu_additem(menu, "\wExit")
	menu_setprop(menu, MPROP_PERPAGE, 0)
	
	menu_display( id, menu, 0 )
	return PLUGIN_CONTINUE
	
}
public points_menu_handler(id, menu, item) {

	if(item == MENU_EXIT) {
		menu_destroy(menu)
		gift_menu(id)
		return PLUGIN_HANDLED
	}
	menu_destroy(menu)
	new data[128], pid = tid[id]

	if(!is_user_connected(pid)) {
		format(data, charsmax(data), "^4[^3playcounter^4]^4 Client is not connected anymore")
		client_print_color(id, print_chat, data)
		
	}
	switch(player_menuMode[id]) {
		case 0:	{//1+
			tpoints[id]+=1
			points_menu(id)
		}
		case 1:	{//10+
			tpoints[id]+=10
			points_menu(id)
		}
		case 2:	{//100+
			tpoints[id]+=100
			points_menu(id)
		}
		case 3:	{//1-
			tpoints[id]-=1
			points_menu(id)		
		}
		case 4:	{//10-
			tpoints[id]-=10
			points_menu(id)		
		}
		case 5:	{//100-
			tpoints[id]-=100
			points_menu(id)		
		}
		case 6:	{//0
			tpoints[id]=0
			points_menu(id)		
		}
		case 7: {
			client_cmd(id, "messagemode CSGO_points")
		}
		case 8: {
		//	get_user_name(pid, data[id], 31)
		//	get_user_name(pid, data, 31)
		//	format(data, charsmax(data), "^4[^3playcounter^4]^4 %i ^ipoints were successfuly sent to ^4%s",tpoints[id], data)
		//	client_print_color(id, print_chat, data)
		}
	}
	return PLUGIN_HANDLED
}

public MySql_Init() {
	g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
   
	new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
	if(SqlConnection == Empty_Handle)
		set_fail_state(g_Error)
       
	new Handle:Queries[5]
	Queries[0] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_players` (`ID` INT AUTO_INCREMENT PRIMARY KEY, `player_id` varchar(32), `player_password` varchar(32), `chests` varchar(32), `keys` INT(15), `points` INT(15), `kills` INT(5))")
	Queries[1] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_weapons` (`skin_id` INT AUTO_INCREMENT PRIMARY KEY, `weapon_name` varchar(32), `model_v` varchar(32), `model_p` varchar(32), `model_w` varchar(32), `weapon_id` INT(2), `cost` INT(11), `chance` INT(11), `case` INT(2), `flags` varchar(32))")
	Queries[2] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_player_weapons` (`ID` INT AUTO_INCREMENT PRIMARY KEY, `player_id` INT(15), `skin_id` INT(15), `active` INT(1), `count` INT(5), `weapon_id` INT(3))")
	Queries[3] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_market` (`player_weapon_ID` INT AUTO_INCREMENT PRIMARY KEY, `player_ID` INT(11), `player_name` varchar(32), `item_type` INT(11), `skin-case_id` INT(11), `cost` INT(11))")
	Queries[4] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_logs` (`ID` INT AUTO_INCREMENT PRIMARY KEY, `date` INT(11), `info` varchar(256))")
	
	for(new i=0; i<5; i++) {
		if(!SQL_Execute(Queries[i])) {
			SQL_QueryError(Queries[i],g_Error,charsmax(g_Error))
			set_fail_state(g_Error)
		}
		SQL_FreeHandle(Queries[i])
	}
	SQL_FreeHandle(SqlConnection)   
}
public MySql_LoadNormal(id) {
	new temp[512], data[1]
	data[0] = id
	switch(login_type[id]) {
		case -1: {
			login_type[id] = 0
			get_user_authid(id, login_data[id], charsmax(login_data[]))
			format(temp, charsmax(temp),"SELECT * FROM `csgo_players` WHERE (`player_id` = '%s')", login_data[id])
		//	console_print(0, "0000000000000000000000000000")
		}
		case 0: {
			login_type[id] = 1
			get_user_ip(id, login_data[id], charsmax(login_data[]), 0)
			format(temp, charsmax(temp),"SELECT * FROM `csgo_players` WHERE (`player_id` = '%s')", login_data[id])
			//console_print(0, "111111111111111111111111111111")
		}
		case 1: {
			login_type[id] = 2
			get_user_name(id, login_data[id], charsmax(login_data[]))
			format(temp, charsmax(temp),"SELECT * FROM `csgo_players` WHERE (`player_id` = '%s')", login_data[id])
			//console_print(0, "2222222222222222222222222222222")
		}
	}
	SQL_ThreadQuery(g_SqlTuple,"Threaded_PlayerLoad",temp,data,1) 
}

public MySql_LoadRegister(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
	if(FailState == TQUERY_CONNECT_FAILED)
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	else if(FailState == TQUERY_QUERY_FAILED)
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	SQL_FreeHandle(Query)

	new temp[512], id = Data[0]
	login_type[id] = 0
	get_user_authid(id, login_data[id], charsmax(login_data[]))
	format(temp, charsmax(temp),"SELECT * FROM `csgo_players` WHERE (`player_id` = '%s')", login_data[id])
	SQL_ThreadQuery(g_SqlTuple,"Threaded_PlayerLoadRegister",temp,Data,1)
}

public Threaded_PlayerLoad(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
	if(FailState == TQUERY_CONNECT_FAILED)
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	else if(FailState == TQUERY_QUERY_FAILED)
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	
	new id = Data[0]

	if(SQL_NumResults(Query) < 1 && login_type[id] == 2) {
		new temp[256]
		get_user_authid(id, login_data[id], charsmax(login_data[]))
		login_type[id] = 0
		format(temp,charsmax(temp),"INSERT INTO `csgo_players` (`player_id`,`player_password`, `chests`, `keys`, `points`, `kills`) VALUES ('%s','','0 0 0 0','0','0','0');",login_data[id])
		SQL_ThreadQuery(g_SqlTuple,"MySql_LoadRegister",temp)
		return PLUGIN_HANDLED
	}
		
	if(SQL_NumResults(Query) < 1 && login_type[id] != 2) {
		MySql_LoadNormal(id)
		return PLUGIN_HANDLED
	}
	
	if (SQL_NumResults(Query) > 0) {
		ID[id] = SQL_ReadResult(Query, 0)
		SQL_ReadResult(Query, 2, password[id], 31)
		SQL_ReadResult(Query, 3, chests[id], 31)
		keys[id] = SQL_ReadResult(Query, 4)
		points[id] = SQL_ReadResult(Query, 5)
		kills[id] = SQL_ReadResult(Query, 6)
		parse(chests[id], 31, cases[id][0], 5, cases[id][1], 5, cases[id][2], 5, cases[id][3], 5)
		MySql_load_player_skins(id)
	}
	return PLUGIN_HANDLED
}

public Threaded_PlayerLoadRegister(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
	if(FailState == TQUERY_CONNECT_FAILED)
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	else if(FailState == TQUERY_QUERY_FAILED)
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	
	new temp[256], id = Data[0]

	if (SQL_NumResults(Query) > 0) {
		ID[id] = SQL_ReadResult(Query, 0)
		for(new i=0; i<gun_count; i++) {
			format(temp,charsmax(temp),"INSERT INTO `csgo_player_weapons` ( `player_id`,`skin_id`, `active`, `count`, `weapon_id`) VALUES ('%i','%i','0','0','%i');",ID[id], skin_id[i], weapon_id[i])
			SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",temp)
		}
	}
	else
		console_print(0, "NERA REZULTATU!!")
	login_type[id] = -1
	MySql_LoadNormal(id)
	
	return PLUGIN_HANDLED
}

public MySql_load_player_skins(id) {
	new szTemp[156]

	new Data[1]
	Data[0] = id
	format(szTemp,charsmax(szTemp),"SELECT * FROM `csgo_player_weapons` WHERE (`player_id` = '%i') ORDER BY 'skin_id'", ID[id])
	SQL_ThreadQuery(g_SqlTuple,"Threaded_SkinsLoad",szTemp,Data,1)
}
	
public Threaded_SkinsLoad(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
	if(FailState == TQUERY_CONNECT_FAILED)
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	else if(FailState == TQUERY_QUERY_FAILED)
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	new id = Data[0]
	new rows = SQL_AffectedRows(Query)
	for(new i; i < rows; i++) {
		player_weapons[id][SQL_ReadResult(Query, 2)-1] = SQL_ReadResult(Query, 4)
		player_skins[id][SQL_ReadResult(Query, 5)]+=1
		if(SQL_ReadResult(Query, 3)>0)
			equiped[id][SQL_ReadResult(Query, 5)] = i+1

		SQL_NextRow(Query)
	}
	new check[256]
	if(gun_count != rows) {
		new Temp[256]
		console_print(0, "guns: %i   rows:%i", gun_count, rows)
		for(new i; i < gun_count; i++) {
			SQL_Rewind(Query)
			for(new I; I < rows; I++) {
				if(skin_id[i] == SQL_ReadResult(Query, 2))
					check[i] = 1
				SQL_NextRow(Query)
			}
			if(!check[i]) {
				format(Temp,charsmax(Temp),"INSERT INTO `csgo_player_weapons` ( `player_id`,`skin_id`, `active`, `count`, `weapon_id`) VALUES ('%i','%i','0','0','%i');",ID[id], skin_id[i], weapon_id[i])
				SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",Temp)
			}
		}
	}
	SQL_FreeHandle(Query)
	return PLUGIN_HANDLED
}

public Threaded_SkinCheck(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
	if(FailState == TQUERY_CONNECT_FAILED)
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	else if(FailState == TQUERY_QUERY_FAILED)
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	
}

public MySql_save_player_skins(id) {
	new temp[512]
	for(new i=0; i<gun_count; i++) {
		console_print(0, "%i", i)
		format(temp,charsmax(temp), "UPDATE `csgo_player_weapons` SET `active` = '%i', `count` = '%i' WHERE `csgo_player_weapons`.`player_id` = '%i', `skin_id` = '%i'", equiped[id][i], player_weapons[id][i], ID[id], skin_id[i])
		console_print(0, "%i", skin_id[i])
		SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",temp)
	}
	return PLUGIN_HANDLED
}

public MySql_save_player_data(id) {
	new temp[512]
	format(chests[id], 24, "%i %i %i %i", cases[id][0], cases[id][1], cases[id][2], cases[id][3])
	switch(login_type[id]) {
		case 0: get_user_authid(id, login_data[id], charsmax(login_data[]))
		case 1: get_user_ip(id, login_data[id], charsmax(login_data[]), 1)
		case 2: get_user_name(id, login_data[id], charsmax(login_data[]))
	}
	console_print(0, "update  0")
	format(temp,charsmax(temp),"UPDATE `csgo_players` SET `chests` = '%s', `keys` = '%i', `points` = '%i', `kills` = '%i', `player_id` = '%s', `player_password` = '%s' WHERE `csgo_players`.`ID` = '%i';", chests[id], keys[id], points[id], kills[id], login_data[id], (login_type[id] == 2) ? password[id] : "", ID[id])
	console_print(0, "update 1")
	SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",temp)
	return PLUGIN_HANDLED
}


public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
	SQL_FreeHandle(Query)
	return PLUGIN_HANDLED
}

public open_chest(id, chest) {
	static counter[33]
	// blue purple red golden legendary
	switch(random(1000)) {
		case 0..400: {//blue
			
		}
		case 401..700: {//purple
		
		}
		case 701..919: {//red
		
		}
		case 920..949: {//golden
		
		}
		case 980..1000: {//legendary
		
		}
	}
	set_task(str_to_float(times[counter[id]]), "open_chest", id)
}

public client_authorized(id) {
	loged[id] = 0
	login_type[id] = -1
	points[id] = 0
	MySql_LoadNormal(id)
}

public client_disconnect(id) {
	MySql_save_player_data(id)
	MySql_save_player_skins(id)
}

public change_model(id) {
	static i
	i = get_user_weapon(id)
	i=equiped[id][i]
	i-=1
	if(i < 0) {
		return PLUGIN_CONTINUE
	}
	if(strlen(model_v[i]) > 7)
		set_pev(id, pev_viewmodel2, model_v[i])
	if(strlen(model_p[i]) > 7)
		set_pev(id, pev_weaponmodel2, model_p[i])


	return PLUGIN_HANDLED
}

public Call_Back(id, menu, item) {
	return ITEM_DISABLED
}
public plugin_end() {
	new temp[512], players[32], count
	get_players(players, count, "ch")
	for(new I; I<count; I++) {
		for(new i=0; i<gun_count; i++) {
			console_print(0, "%i %i", I, i)
			format(temp,charsmax(temp), "UPDATE `csgo_player_weapons` SET `active` = '%d', `count` = '%d' WHERE `player_id` = '%d', `skin_id` = '%d'", equiped[I][i], player_weapons[I][i], ID[I], skin_id[i])
			SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",temp)
		}
	}
	SQL_FreeHandle(g_SqlTuple)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1063\\ f0\\ fs16 \n\\ par }
*/
__________________
retired chump

Last edited by DjSoftero; 01-31-2020 at 05:52.
DjSoftero is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 01-31-2020 , 12:55   Re: Storing data
Reply With Quote #8

I'm just looking for suggestion on what's the best way to store such data.

My current solution, which I don't feel like is any good:

PHP Code:
#define MAX_USER_SKINS 1024 //let's say user can have max 1024 skins 
PHP Code:
new g_iPlayerSkinId[33][MAX_USER_SKINS]; //Holds skin_id from table
new g_bPlayerSkinStattrak[33][MAX_USER_SKINS]; //Holds skin is_stattrak
new g_iPlayerSkinLevel[33][MAX_USER_SKINS]; //Holds skin level
/* and so on for every mysql column */ 
PHP Code:
new 0;
while(
SQL_MoreResults(Query)) {
 
g_iPlayerSkinId[id][i] = SQL_ReadResult(Query2);
 
//etc.
 
i++;

__________________
Airkish is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 01-31-2020 , 13:59   Re: Storing data
Reply With Quote #9

Well, I posted that plugin for a reason.

these variables hold all the data.
PHP Code:
new equiped[33][33]//[player id][skin_id]
new player_weapons[33][256]//[player id][skin_id] = 3 would mean player has 3 awp asiimovs as an example.
new player_skins[33][35]//[player id][weapon id]//(weapon id from the list below) basically tells the amount of skins for a certain weapon a player has. for example 3 different knife skins for knife would mean value is 3. second array dimension has 35 elements because I was leaving headroom for custom weapons
//skin data**********8
new skin_id[256]//skin index basically
new weapon_name[256][32]//weapon name
new model_v[256][32]
new 
model_p[256][32]
new 
model_w[256][32]
new 
weapon_id[256]//(weapon id from the list below) tells which weapon should use that skin
new cost[256]//cost to sell to shop
new chance[256]//chance from case.
new flags[256][32]//which admin flag you need to equip 
weapon indexes:
Spoiler

as for sql tables:
PHP Code:
Queries[0] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_players` (`ID` INT AUTO_INCREMENT PRIMARY KEY, `player_id` varchar(32), `player_password` varchar(32), `chests` varchar(32), `keys` INT(15), `points` INT(15), `kills` INT(5))")
    
Queries[1] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_weapons` (`skin_id` INT AUTO_INCREMENT PRIMARY KEY, `weapon_name` varchar(32), `model_v` varchar(32), `model_p` varchar(32), `model_w` varchar(32), `weapon_id` INT(2), `cost` INT(11), `chance` INT(11), `case` INT(2), `flags` varchar(32))")
    
Queries[2] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_player_weapons` (`ID` INT AUTO_INCREMENT PRIMARY KEY, `player_id` INT(15), `skin_id` INT(15), `active` INT(1), `count` INT(5), `weapon_id` INT(3))")
    
Queries[3] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_market` (`player_weapon_ID` INT AUTO_INCREMENT PRIMARY KEY, `player_ID` INT(11), `player_name` varchar(32), `item_type` INT(11), `skin-case_id` INT(11), `cost` INT(11))")
    
Queries[4] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `csgo_logs` (`ID` INT AUTO_INCREMENT PRIMARY KEY, `date` INT(11), `info` varchar(256))"
__________________
retired chump

Last edited by DjSoftero; 01-31-2020 at 14:00.
DjSoftero is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-31-2020 , 17:35   Re: Storing data
Reply With Quote #10

Can do something like this:
PHP Code:
#define MAX_USER_SKINS 1024 //let's say user can have max 1024 skins

enum SkinData
{
    
SkinID,
    
bool:IsStattrak,
    
SkinLevel
}

new 
g_sdPlayerSkinsMAX_PLAYERS ][ MAX_USER_SKINS ][ SkinData ];

public 
QueryHandleFailState Handle:Query , const Error[] , Errcode , const Data] , DataSize )
{
    new 
id Data]
    new 
0;
    
    while( ( 
MAX_USER_SKINS ) && SQL_MoreResultsQuery ) ) 
    {
        
g_sdPlayerSkinsid ][ ][ SkinID ] = SQL_ReadResultQuery );
        
g_sdPlayerSkinsid ][ ][ IsStattrak ] = bool:SQL_ReadResultQuery );
        
g_sdPlayerSkinsid ][ ][ SkinLevel ] = SQL_ReadResultQuery );
        
i++;
    } 


__________________

Last edited by Bugsy; 01-31-2020 at 17:36.
Bugsy is online now
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 06:23.


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