I'm trying to use HamSandwich and hook FwdPlayerSpawnPost (Ham_Spawn) + use This stock
My objective: Set user skill points in their name upon spawning.
I have been trying for the past hour without any results, I have given up!
Please anyone willing to give me some tips, I tried to manually loop through each player and get_user_skill but so far it was a huge failure.
What is the issue? Is the name not updating at all, or is the skill value in the name wrong? Provide your code
The issue is that I'm trying to implement this but I do not understand the coding in this particular plugin, neither I am that advanced to accomplish this task but I do wish to learn, even if I will achieve this through tips... I am currently half-way through the AMXX tutorials and it's been a breeze because the code is easy (not compact, it is kinda hard-coded as well so it's super easy to understand), it's just that this plugin has given me headaches, whoever wrote this plugin is just amazing!!! I can't seem to grasp how it works even though I tried to - for hours!
Basically should be:
(Your name) + (" [YOUR_POINTS] ")
PHP Code:
//init public plugin_init() { RegisterHam(Ham_Spawn, "player", "FwdPlayerSpawnPost", 1) }
public FwdPlayerSpawnPost( id ) { if( is_user_alive( id ) ) { new szName[ 32 ] get_user_info( id, "name", szName, charsmax( szName ) )
new iLen = strlen( szName )
new iPos = iLen - 1
if( szName[ iPos ] == '>' ) { new i for( i = 1; i < 7; i++ ) { if( szName[ iPos - i ] == '<' ) { iLen = iPos - i szName[ iLen ] = EOS break } } } new player_id[32],user_skill; get_user_skill(player_id, user_skill); for (new i; i<num; i++) { format( szName[ iLen ], charsmax( szName ) - iLen, szName[ iLen-1 ] == ' ' ? "[%d]" : " [%d]", get_user_skill(player_id[], user_skill)); set_user_info( id, "name", szName ) } } }
This is what I currently have...
So basically the full plugin(which I have stated the source to)
Spoiler
PHP Code:
/* * AES: StatsX v. 0.5 * by serfreeman1337 http://1337.uz/ */
#include <amxmodx> #include <csx> #include <hamsandwich> //EDITED THIS CUZ FORGOT to include :D
#if AMXX_VERSION_NUM < 183 #include <colorchat>
#define print_team_default DontChange #define print_team_grey Grey #define print_team_red Red #define print_team_blue Blue
//#define AES // расскомментируйте для поддержки AES (http://1337.uz/advanced-experience-system/) //#define CSSTATSX_SQL // расскомментируйте для поддержки CSstatsX SQL (http://1337.uz/csstatsx-sql/)
// Global player flags. new const BODY_PART[8][] = { "WHOLEBODY", "AES_HEAD", "AES_CHEST", "AES_STOMACH", "AES_LARM", "AES_RARM", "AES_LLEG", "AES_RLEG" }
new Float:g_skill_opt[sizeof g_skill_letters]
#define BUFF_LEN 1535
new theBuffer[BUFF_LEN + 1] = 0
#define MENU_LEN 512
new g_MenuStatus[MAX_PLAYERS + 1][2]
public SayStatsMe = 0 // displays user's stats and rank public SayRankStats = 0 // displays user's rank stats public SayRank = 0 // displays user's rank public SayTop15 = 0 // displays first 15 players public SayStatsAll = 0 // displays all players stats and rank public SayHot = 0 // displays top from current players #if defined CSSTATSX_SQL public SaySeStats = 0 // displays players match history #endif
#if defined AES new aes_track_mode #endif
public plugin_precache() { register_plugin(PLUGIN, VERSION, AUTHOR)
/* // Отображение /top15 и /rank // ВАЖНО! Motd окно не может показывать больше 1534-х символов, а сообщение в чат больше 192-х. // Если что то отображается криво или не полностью, то нужно уменьшить количество пунктов. (Топ не показывает больше 10-ти игроков) // * - Ранг // a - Ник (Only /top15) // b - Убийста // c - Смерти // d - Попаданий // e - Выстрелов // f - В голову // g - Точность // h - Эффективность // i - Скилл // j - Звание Army Ranks // k - K:D // l - HS:K // m - HS % // n - онлайн время */
#if defined CSSTATSX_SQL register_dictionary("time.txt") #endif }
public plugin_init() { register_clcmd("say","Say_Catch") register_clcmd("say_team","Say_Catch") RegisterHam(Ham_Spawn, "player", "FwdPlayerSpawnPost", 1) //THIS HAS BEEN ADDED! register_menucmd(register_menuid("Stats Menu"), 1023, "actionStatsMenu") }
#if AMXX_VERSION_NUM < 183 public plugin_cfg() #else public OnAutoConfigsBuffered() #endif { new levelString[512],stPos,ePos,rawPoint[20],cnt get_pcvar_string(cvar[CVAR_SKILL],levelString,charsmax(levelString))
// парсер значений для скилла do { ePos = strfind(levelString[stPos]," ")
switch(desc_char[0]) { // время case 'p': { new stime = get_sestats_read_stime(sestats_array,i) format_time(cell_str,charsmax(cell_str),"%m/%d/%Y - %H:%M:%S",stime) } // изменение скилла case 'o': { new Float:skill = get_sestats_read_skill(sestats_array,i)
formatex(cell_str,charsmax(cell_str),"%s%.2f", skill > 0.0 ? "+" : "", skill ) } // карта case 'q': { get_sestats_read_map(sestats_array,i,cell_str,charsmax(cell_str)) } // убийства case 'b': { formatex(cell_str,charsmax(cell_str),"%d",stats[STATS_KILLS]) } // смерти case 'c': { formatex(cell_str,charsmax(cell_str),"%d",stats[STATS_DEATHS]) } // попадания case 'd': { formatex(cell_str,charsmax(cell_str),"%d",stats[STATS_HITS]) } // выстрелы case 'e': { formatex(cell_str,charsmax(cell_str),"%d",stats[STATS_SHOTS]) } // хедшоты case 'f': { formatex(cell_str,charsmax(cell_str),"%d",stats[STATS_HS]) } // точнсть case 'g': { formatex(cell_str,charsmax(cell_str),"%.2f%%", accuracy(stats) ) } // эффективность case 'h': { formatex(cell_str,charsmax(cell_str),"%.2f%%", effec(stats) ) } // K:D case 'k': { formatex(cell_str,charsmax(cell_str),"%.2f", kd_ratio(stats) ) } // HS:K case 'l': { formatex(cell_str,charsmax(cell_str),"%.2f", hsk_ratio(stats) ) } // HS effec case 'm': { formatex(cell_str,charsmax(cell_str),"%.2f%%", effec_hs(stats) ) } // время в игре case 'n': { new ot = get_sestats_read_online(sestats_array,i) func_format_ot(ot,cell_str,charsmax(cell_str),id) } default: continue }
} #if defined AES // опыт и ранг case 'j': { // TODO: AES RANKS formatex(cell_str,charsmax(cell_str),"lyl") } #endif // K:D case 'k': { formatex(cell_str,charsmax(cell_str),"%.2f", kd_ratio(stats) ) } // HS:K case 'l': { formatex(cell_str,charsmax(cell_str),"%.2f", hsk_ratio(stats) ) } // HS effec case 'm': { formatex(cell_str,charsmax(cell_str),"%.2f%%", effec_hs(stats) ) } #if defined CSSTATSX_SQL // время в игре case 'n': { new ot = get_user_gametime(player_id) func_format_ot(ot,cell_str,charsmax(cell_str),id) } #endif default: continue }
// выводим отформатированные данные row_len += formatex(row_str[row_len],charsmax(row_str)-row_len,"%L",id,"AES_BODY_CELL",cell_str) }
row_len = len len += formatex(theBuffer[len],charsmax(theBuffer)-len,"%L",id,"AES_BODY_ROW",odd ? " id=b" : " id=q",row_str)
if(rank > 0) { len += formatex(message[len],charsmax(message) - len,"%L ",id,"AES_YOUR_RANK_IS",rank,stats_num) len += parse_rank_desc(id,message[len],charsmax(message)-len,stats) } else { len += formatex(message[len],charsmax(message) - len,"%L ",id,"AES_STATS_INFO2") }
client_print_color(id,print_team_default,message)
return PLUGIN_HANDLED }
// // Формирование сообщения /rank // parse_rank_desc(id,msg[],maxlen,stats[8]){ new cnt,theChar[4],len
new desc_str[10] get_pcvar_string(cvar[CVAR_CHAT_DESC],desc_str,charsmax(desc_str))
// Проверяем всё флаги for(new i,length = strlen(desc_str) ; i < length ; ++i){ theChar[0] = desc_str[i] // фз почему напрямую не рабатает
// если это первое значение, то рисуем в начале скобку, иначе запятую с пробелом if(cnt != length) len += formatex(msg[len],maxlen - len,cnt <= 0 ? "(" : ", ")
// добавляем в сообщение информацию в соотв. с флагами switch(theChar[0]){ // убийства case 'b': { len += formatex(msg[len],maxlen - len,"%L ^3%d^1",id,"KILLS",stats[0]) } // смерти case 'c': { len += formatex(msg[len],maxlen - len,"%L ^3%d^1",id,"DEATHS",stats[1]) } // попадания case 'd': { len += formatex(msg[len],maxlen - len,"%L ^3%d^1",id,"HITS",stats[5]) } // выстрелы case 'e': { len += formatex(msg[len],maxlen - len,"%L ^3%d^1",id,"SHOTS",stats[4]) } // хедшоты case 'f': { len += formatex(msg[len],maxlen - len,"%L ^3%d^1",id,"STATS_HS",stats[2]) } // точность case 'g': { len += formatex(msg[len],maxlen - len,"%L ^3%.2f%%^1",id,"ACC",accuracy(stats)) } // эффективность case 'h': { len += formatex(msg[len],maxlen - len,"%L ^3%d%%^1",id,"EFF",effec(stats)) } // скилл case 'i': { new Float:skill,skill_id
#if defined CSSTATSX_SQL get_user_skill(id,skill) #else skill = effec(stats) #endif
skill_id = aes_statsx_get_skill_id(skill)
len += formatex(msg[len],maxlen - len,"%L ^3%s^1 (%.2f)",id,"STATS_SKILL", g_skill_letters[skill_id], skill )
} #if defined AES case 'j':{ // ранг и опыт new Float:player_exp = aes_get_player_exp(id)
if(player_exp == -1.0)// без ранга { len += formatex(msg[len],maxlen - len,"%L ^4---^1",id,"STATS_RANK") } else { new level_str[AES_MAX_LEVEL_LENGTH ] new player_level = aes_get_player_level(id) aes_get_level_name(player_level,level_str,charsmax(level_str),id)
len += formatex(msg[len],maxlen - len,"%L ^3%L^1",id,"STATS_RANK",id,"AES_RANK", level_str,player_exp ) } } #endif // K:D case 'k': { len += formatex(msg[len],maxlen - len,"%L ^3%.2f^1", id,"AES_KS", kd_ratio(stats) ) } // HS:K case 'l': { len += formatex(msg[len],maxlen - len,"%L ^3%.2f^1", id,"AES_HSK", hsk_ratio(stats) ) } // HS effec case 'm': { len += formatex(msg[len],maxlen - len,"%L ^3%.2f^1%%", id,"AES_HSP", effec_hs(stats) ) } #if defined CSSTATSX_SQL // время в игре case 'n': { new ot = get_user_gametime(id)
len += formatex(msg[len],maxlen - len,"%L: ^3",id,"AES_TIME") len += func_format_ot(ot,msg[len],maxlen - len,id) len += formatex(msg[len],maxlen - len,"^1") } #endif }
theChar[0] = 0 cnt ++ }
// завершаем всё сообщение скобкой, если была подстановка параметров if(cnt) { len += formatex(msg[len],maxlen - len,")") }
return len }
#if defined CSSTATSX_SQL func_format_ot(ot,string[],len,idLang = LANG_SERVER) { new d,h,m,s
d = (ot / SECONDS_IN_DAY) ot -= (d * SECONDS_IN_DAY) h = (ot / SECONDS_IN_HOUR) ot -= (h * SECONDS_IN_HOUR) m = (ot / SECONDS_IN_MINUTE) ot -= (m * SECONDS_IN_MINUTE) s = ot
// // Общая статистика // len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<td valign=top width=%d%% class=q><table cellspacing=0><tr><th colspan=2>", is_wstats ? 40 : 50 )
len += formatex(theBuffer[len],charsmax(theBuffer)-len,"%L", id,"AES_RANKSTATS_TSTATS", name,rank,stats_num )
len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td>%L<td>%d (%L %d (%.2f%%))",id,"AES_KILLS",stats[STATS_KILLS],id,"AES_HS",stats[STATS_HS],effec_hs(stats)) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=b><td>%L<td>%d (%L %.2f)",id,"AES_DEATHS",stats[STATS_DEATHS],id,"AES_KS",kd_ratio(stats)) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td>%L<td>%d",id,"AES_HITS",stats[STATS_HITS]) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=b><td>%L<td>%d",id,"AES_SHOTS",stats[STATS_SHOTS]) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td>%L<td>%d",id,"AES_DMG",stats[STATS_DAMAGE]) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=b><td>%L<td>%.2f%%",id,"AES_ACC",accuracy(stats)) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td>%L<td>%.2f%%",id,"AES_EFF",effec(stats)) len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=b><td>%L<td>%s",id,"AES_SKILL",skill_str)
#if !defined CSSTATSX_SQL len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td height=18px><td>") #else len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td>%L<td>",id,"AES_TIME") len += func_format_ot( get_user_gametime(player_id), theBuffer[len],charsmax(theBuffer)-len, id )
len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=b><td>%L<td>%d",id,"CSXSQL_JOINS",stats3[STATS3_CONNECT])
/* new from = get_systime() - get_user_lastjoin_sql(player_id) new from_str[40] get_time_length(id,from,timeunit_seconds,from_str,charsmax(from_str))
len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=q><td>%L<td>",id,"CSXSQL_FIRSTJOIN")
if(firstjoin > 0) { len += format_time(theBuffer[len],charsmax(theBuffer)-len,"%m/%d/%Y - %H:%M:%S",firstjoin) } else { len += formatex(theBuffer[len],charsmax(theBuffer)-len,"-") } #endif len += formatex(theBuffer[len],charsmax(theBuffer)-len,"</td></tr></table></td>")
#if !defined CSSTATSX_SQL // // Статистика по попаданиям // len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<td valign=top width=50%% class=q><table cellspacing=0><tr><th colspan=2>") len += formatex(theBuffer[len],charsmax(theBuffer)-len,"%L",id,"AES_RANKSTATS_THITS")
new theSwitcher
for (new i = 1; i < 8; i++) { len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=%s><td>%L<td>%d", theSwitcher ? "b" : "q", id,BODY_PART[i],bh[i] )
theSwitcher = theSwitcher ? false : true }
// mne tak nadoel etot kod :( for(new i = 0 ; i < 2; ++i){ len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=%s><td height=18px><td>",theSwitcher ? "b" : "q")
theSwitcher = theSwitcher ? false : true }
len += formatex(theBuffer[len],charsmax(theBuffer)-len,"</td>") #else // статистика по оружию выключена if(!is_wstats) { // // Статистика по попаданиям // len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<td valign=top width=50%% class=q><table cellspacing=0><tr><th colspan=2>") len += formatex(theBuffer[len],charsmax(theBuffer)-len,"%L",id,"AES_RANKSTATS_THITS")
new theSwitcher
for (new i = 1; i < 8; i++) { len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=%s><td>%L<td>%d", theSwitcher ? "b" : "q", id,BODY_PART[i],bh[i] )
theSwitcher = theSwitcher ? false : true }
// mne tak nadoel etot kod :( for(new i = 0 ; i < 5; ++i){ len += formatex(theBuffer[len],charsmax(theBuffer)-len,"<tr id=%s><td height=18px><td>",theSwitcher ? "b" : "q")
theSwitcher = theSwitcher ? false : true }
len += formatex(theBuffer[len],charsmax(theBuffer)-len,"</td>") } else { // // Статистика по используемому оружию // len += formatex(theBuffer[len],BUFF_LEN-len,"<td valign=top width=60%% class=q><table cellspacing=0 width=100%%><tr><th>%L<th>%L<th>%L<th>%L<th>%L<th>%L<th>%L", id,"AES_WEAPON", id,"AES_KILLS", id,"AES_DEATHS", id,"AES_HITS", id,"AES_SHOTS", id,"AES_DMG", id,"AES_ACC" )
new bool:odd new wpn_stats[9],Array:wpn_stats_array = ArrayCreate(sizeof wpn_stats)
// LENA FIX if(len >= BUFF_LEN) { len = lena theBuffer[len] = 0
break }
odd ^= true }
ArrayDestroy(wpn_stats_array) } #endif
show_motd(id,theBuffer,motd_title)
return PLUGIN_HANDLED }
#if defined CSSTATSX_SQL public Sort_WeaponStats(Array:array, item1, item2) { new wpn_stats1[9],wpn_stats2[9] ArrayGetArray(array,item1,wpn_stats1) ArrayGetArray(array,item2,wpn_stats2)
// // Личная статистка за карту // // id - кому показывать // stId - кого показывать public StatsMeSay(id,player_id){ if(!SayStatsMe){ client_print_color(id,0,"%L %L",id,"STATS_TAG", id,"DISABLED_MSG")
// Формирование окна /top // В Pos указывается с какой позиции рисовать public SayTop(id,Pos) { if(!SayTop15){ client_print_color(id,0,"%L %L",id,"STATS_TAG", id,"DISABLED_MSG")
// // Сбор статистики // public SayTopHandler(id,Pos) { new Array:stats_array = ArrayCreate(stats_former_array) new stats_info[stats_former_array],last_rank
#if defined CSSTATSX_SQL new size = min(get_statsnum_sql(),Pos) #else new size = min(get_statsnum(),Pos) #endif
#if defined AES new Array:authids_array = ArrayCreate(sizeof stats_info[STATSF_AUTHID]) #endif
new rank,stats[8],stats2[4],bh[8],name[MAX_NAME_LENGTH],authid[30]
// Формируем заголовок таблицы для топа игроков parse_top_desc_header(id,buff[],maxlen,len,bool:isAstats,desc_str[]){ new tmp[256],len2,theChar[4],lCnt
// формирование меню для просмотра статистики игроков public ShowStatsMenu(id,page){ if(!SayStatsAll){ client_print_color(id,0,"%L %L",id,"STATS_TAG", id,"DISABLED_MSG")
return PLUGIN_HANDLED }
new menuKeys,menuText[512],menuLen new tName[42],players[32],pCount
switch(g_MenuStatus[id][0]) { case 0: RankStatsSay(id,usrIndex) case 1: StatsMeSay(id,usrIndex) #if defined CSSTATSX_SQL case 2: SeStats_Show(id,usrIndex) #endif }
ShowStatsMenu(id,g_MenuStatus[id][1]) } case 8:{ g_MenuStatus[id][1] ++ ShowStatsMenu(id,g_MenuStatus[id][1]) } case 9:{ if(g_MenuStatus[id][1]){ g_MenuStatus[id][1] -- ShowStatsMenu(id,g_MenuStatus[id][1]) } } }
return PLUGIN_HANDLED }
public FwdPlayerSpawnPost( id ) // THIS HAS BEEN ADDED { if( is_user_alive( id ) ) { new szName[ 32 ] get_user_info( id, "name", szName, charsmax( szName ) )
new iLen = strlen( szName )
new iPos = iLen - 1
if( szName[ iPos ] == '>' ) { new i for( i = 1; i < 7; i++ ) { if( szName[ iPos - i ] == '<' ) { iLen = iPos - i szName[ iLen ] = EOS break } } } new player_id[32],user_skill; get_user_skill(player_id, user_skill); for (new i; i<num; i++) { format( szName[ iLen ], charsmax( szName ) - iLen, szName[ iLen-1 ] == ' ' ? "[%d]" : " [%d]", get_user_skill(player_id[], user_skill)); set_user_info( id, "name", szName ) } } }
EDIT: I kinda tried to understand the coding but it is just too advanced for me, I mean, the whole plugin, in general, is very neatly coded, it is all well-coded but the problem I encountered is that I got kinda lost when I saw no global variables and it's been a pain in the ... for me to understand most (70%) of the code.
TL;DR - this plugin is just too well-made for me to understand the coding...
The issue is that I'm trying to implement this but I do not understand the coding in this particular plugin, neither I am that advanced to accomplish this task but I do wish to learn, even if I will achieve this through tips... I am currently half-way through the AMXX tutorials and it's been a breeze because the code is easy (not compact, it is kinda hard-coded as well so it's super easy to understand), it's just that this plugin has given me headaches, whoever wrote this plugin is just amazing!!! I can't seem to grasp how it works even though I tried to - for hours!
Basically should be:
(Your name) + (" [YOUR_POINTS] ")
PHP Code:
public FwdPlayerSpawnPost( id )
{
if( is_user_alive( id ) )
{
new szName[ 32 ]
get_user_info( id, "name", szName, charsmax( szName ) ) //get user name
new iLen = strlen( szName ) //get length of name
new iPos = iLen - 1 //last character of the name
if( szName[ iPos ] == '>' ) //check if the last character is '>' (if it is, he already has a skill tag)
{
new i //he has a skill tag, we need to check when the skill tag starts (char '<')
for( i = 1; i < 7; i++ ) //I don't know why 7, probably the skill can't be too big
{
if( szName[ iPos - i ] == '<' ) //found the start of the skill tag
{
iLen = iPos - i
szName[ iLen ] = EOS //delete everything from here until the end (terminates the string right here)
break
}
}
}
new player_id[32],user_skill; //deleting the current skill tag completed, now writing a new one.
//I don't see why you need a for loop here, you already have the player's id (id). 'num' is undefined and 'players_id' is empty. You don't need those anyway.
public FwdPlayerSpawnPost( id )
{
if( is_user_alive( id ) )
{
new szName[ 32 ]
get_user_info( id, "name", szName, charsmax( szName ) ) //get user name
new iLen = strlen( szName ) //get length of name
new iPos = iLen - 1 //last character of the name
if( szName[ iPos ] == '>' ) //check if the last character is '>' (if it is, he already has a skill tag)
{
new i //he has a skill tag, we need to check when the skill tag starts (char '<')
for( i = 1; i < 7; i++ ) //I don't know why 7, probably the skill can't be too big
{
if( szName[ iPos - i ] == '<' ) //found the start of the skill tag
{
iLen = iPos - i
szName[ iLen ] = EOS //delete everything from here until the end (terminates the string right here)
break
}
}
}
new player_id[32],user_skill; //deleting the current skill tag completed, now writing a new one.
//I don't see why you need a for loop here, you already have the player's id (id). 'num' is undefined and 'players_id' is empty. You don't need those anyway.
Natsheh, you do not need to use an ampersand to pass an array by reference. Arrays are always passed by-reference by default. I also tried the code and it is not working for me.
@OP, try this. If a player has a long name, this will trim off just enough to fit the skill value.
PHP Code:
new szName[ 32 ]; SetSkillInName( id , szName , charsmax( szName ) );
public SetSkillInName( id , szOutput[] , maxchars ) { new iNameLen , szSkill[ 10 ] , iSkillLen , iSetPos , Float:fSkill;
// 5 is to accound for ' [ # ]', without the #, adjust as needed if you change the formatex() format below. if ( ( iNameLen + iSkillLen + 5 ) > 31 ) { iSetPos = iNameLen - ( iSkillLen + 5 ); } else { iSetPos = iNameLen; }
Natsheh, you do not need to use an ampersand to pass an array by reference. Arrays are always passed by-reference by default. I also tried the code and it is not working for me.
You're totally right i forgot about that.
And i didn't test the code I'll check what's wrong.
Can you also tell me what it did output ? I can't do tests...
Natsheh, you do not need to use an ampersand to pass an array by reference. Arrays are always passed by-reference by default. I also tried the code and it is not working for me.
@OP, try this. If a player has a long name, this will trim off just enough to fit the skill value.
PHP Code:
new szName[ 32 ]; SetSkillInName( id , szName , charsmax( szName ) );
public SetSkillInName( id , szOutput[] , maxchars ) { new iNameLen , szSkill[ 10 ] , iSkillLen , iSetPos , Float:fSkill;
// 5 is to accound for ' [ # ]', without the #, adjust as needed if you change the formatex() format below. if ( ( iNameLen + iSkillLen + 5 ) > 31 ) { iSetPos = iNameLen - ( iSkillLen + 5 ); } else { iSetPos = iNameLen; }
I'm about to try this out, I've been tinkering with this for a while. Thanks!
I have a hard time understanding what, or how return formatex works, could you please elaborate? If I'm not asking too much.
also EDIT: Seems to be not working, doesn't do anything at all in fact.
Also, I assume the following:
PHP Code:
new szName[ 32 ]; SetSkillInName( id , szName , charsmax( szName ) );
Is for my Ham_Spawn hook? If yes, it does not work (sadly) - I tried looping through players but it does absolutely nothing.
Also tried to set it as an infinite task and again it does nothing
Debug doesn't show anything abnormal/any errors.
My current Code:
PHP Code:
public SetSkillInName( id , szOutput[] , maxchars ) // Credit:Bugsy { new iNameLen , szSkill[ 10 ] , iSkillLen , iSetPos , Float:fSkill;
// 5 is to accound for ' [ # ]', without the #, adjust as needed if you change the formatex() format below. if ( ( iNameLen + iSkillLen + 5 ) > 31 ) { iSetPos = iNameLen - ( iSkillLen + 5 ); } else { iSetPos = iNameLen; }