24.03.2010, 01:25
Some handy utils functions for dealing with lists of PVars:
Code:
//------------------------------------------- // Sends a list of all PVars to the player as // client messages. SendPVarListToPlayer(playerid) { new ubound = GetPVarsUpperIndex(playerid); new x=0; new name[40+1]; new line[128+1]; SendClientMessage(playerid,0xF000F0F0, "---Player Vars List---"); while(x != ubound) { if(GetPVarNameAtIndex(playerid,x,name,40)) { if(Util_GetPVarEntryAsString(playerid,name,line,128)) { SendClientMessage(playerid,0xFFFFFFFF,line); } } x++; } } //------------------------------------------- // return PVar entry as 'name'='value' string stock Util_GetPVarEntryAsString(playerid, name[], ret[], len) { new Float:fValue; new iValue; new szStrValue[1024+1]; // this might require greater size if you store large strings in PVars new type; ret[0] = EOS; type = GetPVarType(playerid, name); if(type != PLAYER_VARTYPE_NONE) { switch(type) { case PLAYER_VARTYPE_STRING: { GetPVarString(playerid,name,szStrValue,1024); format(ret,len,"%s=%s",name,szStrValue); } case PLAYER_VARTYPE_INT: { iValue = GetPVarInt(playerid,name); format(ret,len,"%s=%d",name,iValue); } case PLAYER_VARTYPE_FLOAT: { fValue = GetPVarFloat(playerid,name); format(ret,len,"%s=%f",name,fValue); } } return 1; } return 0; } //------------------------------------------- // Fills the provided string with all the player's PVars // seperated by the specified 'delimiter' stock Util_CreatePVarList(playerid, retstr[], len, delimiter[]) { if(!IsPlayerConnected(playerid)) return 0; new x=0; new remaining_string=len; new line[2048+1]; new name[40+1]; retstr[0] = EOS; new ubound = GetPVarsUpperIndex(playerid); while(x != ubound) { if(GetPVarNameAtIndex(playerid,x,name,40)) { if(Util_GetPVarEntryAsString(playerid,name,line,2048)) { // if there is enough space, concat this line to the return string if(remaining_string > (strlen(line) + strlen(delimiter))) { strcat(retstr,line); strcat(retstr,delimiter); remaining_string -= (strlen(line) + strlen(delimiter)); } } } x++; } return 1; } //-------------------------------------------