Mano table atrodo taip:
id, ip, name, kills, deaths, headshots, skill.
Turiu tokį kodą kuris gauna, kills, deaths, headshots ir gauna žaidėjo vietą, rikiuojant pagal (kills + headshots) / deaths, viskas veikia.
Code: Select all
public display_rank(id) { new steam_id[32] get_user_authid(id, steam_id, 31) format(MySQL_Query, 511, "SELECT rank, (SELECT COUNT(*) FROM stats) AS total, kills, deaths, headshots FROM (SELECT @rank:=@rank+1 AS rank, steam, kills, deaths, headshots FROM stats, (SELECT @rank:=0) NONE ORDER BY ((kills + headshots) / deaths) DESC) AS result WHERE steam_id='%s'", steam_id) new Handle:Query = SQL_PrepareQuery(MySQL_Connection, MySQL_Query) if(SQL_Execute(Query) && SQL_MoreResults(Query)) { new rank = SQL_ReadResult(Query, 0) new total = SQL_ReadResult(Query, 1) new kills = SQL_ReadResult(Query, 2) new deaths = SQL_ReadResult(Query, 3) new headshots = SQL_ReadResult(Query, 4) client_print(id, print_chat, "You are rank %i of %i, with %i kills, %i headshots and %i deaths", rank, total, kills, headshots, deaths) }}
Bet bandžiau pats padaryti, bet kažkodėl nerodo išvis tada.
Štai kaip aš bandžiau padaryti:
Code: Select all
public display_rank(id) { new steam[32] get_user_authid(id, steam, charsmax(steam)) formatex(MySQL_Query, 511, "SELECT rank, (SELECT COUNT(*) FROM stats) AS total, kills, deaths, headshots, skill FROM (SELECT @rank:=@rank+1 AS rank, steam, kills, deaths, headshots, skill FROM stats, (SELECT @rank:=0) NONE ORDER BY (skill DESC) AS result WHERE steam='%s'", steam) new Handle:Query = SQL_PrepareQuery(MySQL_Connection, MySQL_Query) if(SQL_Execute(Query) && SQL_MoreResults(Query)) { new rank = SQL_ReadResult(Query, 0) new total = SQL_ReadResult(Query, 1) new kills = SQL_ReadResult(Query, 2) new deaths = SQL_ReadResult(Query, 3) new headshots = SQL_ReadResult(Query, 4) new skill = SQL_ReadResult(Query, 5) if(kills + headshots > 5 && deaths > 5) client_print(id, print_chat, "Your rank is %i of %i with %i skill", rank, total, skill ) else client_print(id, print_chat, "You can not be ranked, you do not have any kills or deaths") }}