AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   'String formatted incorrectly' [SOLVED!] (https://forums.alliedmods.net/showthread.php?t=77134)

anakin_cstrike 09-06-2008 05:56

'String formatted incorrectly' [SOLVED!]
 
Hi.
I'm getting this error when i'm using a command:
Quote:

L 09/06/2008 - 12:50:56: String formatted incorrectly - parameter 5 (total 4)
L 09/06/2008 - 12:50:56: [AMXX] Run time error 25 (plugin "war.amxx") - debug not enabled!
Code:
PHP Code:

public skillme_cmd(id)
{
    new 
motd[MAX_BUFFER_LENGTH],len,stats[8],body[8],stats2[4];
    new 
rank_pos get_user_stats(id,stats,body);
    new 
rank_max get_statsnum();
    
len format(motdMAX_BUFFER_LENGTH,"<body bgcolor=#000000><font color=#87cefa><pre>")
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<center><h4><font color=^"blue^"> Player Stats </font></h4></center>");
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Rank</B> - <font color=^"white^">%d/%d</color></left>^n",rank_pos,rank_max);
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Kills</B> - <font color=^"white^">%d</color></left>^n",stats[0]);
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Deaths</B> - <font color=^"white^">%d/%d</color></left>^n",stats[1])
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Bombs Planted</B> - <font color=^"white^">%d</color></left>^n",stats2[2]);
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Bombs Exploded</B> - <font color=^"white^">%d</color></left>^n",stats2[3]);
    
len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Bombs Defused</B> - <font color=^"white^">%d</color></left>^n",stats2[1]);
    
show_motd(idmotd"SkillMe");
    return 
PLUGIN_CONTINUE;



atomen 09-06-2008 06:24

Re: 'String formatted incorrectly'
 
Example of a string formatted incorrectly:
PHP Code:

formatex("lolzor: %s (1) || %s (2) || %s (3)""Hello""Cool"); 

As you can see, there's 3 '%s' but only 2 Strings to fetch.

You used '%d' twice but only 1 variable to fetch
PHP Code:

len += format(motd[len], MAX_BUFFER_LENGTH-len,"<left><font color=^"red^"><B>Deaths</B> - <font color=^"white^">%d/%d</color></left>^n",stats[1]) 


anakin_cstrike 09-06-2008 08:14

Re: 'String formatted incorrectly'
 
Oh:oops:

danielkza 09-06-2008 15:34

Re: 'String formatted incorrectly'
 
Just and idea,instead of including the styles inline with the rows,you could use CSS. Two or three style lines woudl replace all the <left>,<font>,etc tags. Like this:
Code:

stock const Status_RowStart[]        = "%s<tr class=^"%s^">"
stock const Status_RowEnd[]        = "</tr>"

stock const Status_TableHead[]        = "%s<th>%s</th>"
stock const Status_DataString[]        = "%s<td>%s</td>"
stock const Status_DataInteger[]    = "%s<td>%d</td>"

stock FormatTime(szTime[],iLen,iSeconds)
{
    new iMinutes,iHours
   
    iSeconds -= (iHours = iSeconds / 3600) * 3600
    iSeconds -= (iMinutes = iSeconds / 60) * 60
   
    formatex(szTime,iLen,"%d:%02d:%02d",iHours,iMinutes,iSeconds)
}

stock htmlspecialchars(szBuffer[],iLen)
{
    replace_all(szBuffer,iLen,"&","&amp;")
    replace_all(szBuffer,iLen,"<","&lt;")
    replace_all(szBuffer,iLen,">","&gt;")
    replace_all(szBuffer,iLen,"^"","&quot;")
}

#define STATUS_MAX_PLAYERS 4
public Status_Command(id,level,cid)
{
    if(!cmd_access(id,level,cid,1))
        return PLUGIN_HANDLED
   
    new iPlayerStart = 1
    if(read_argc() >= 2)
    {
        new szPlayerStart[8]
        read_argv(1,szPlayerStart,charsmax(szPlayerStart))
       
        if(is_str_num(szPlayerStart))
            iPlayerStart = str_to_num(szPlayerStart)
    }
   
    static szBuffer[2048],szTemp[256]
    new iRowCount = 0
   
    // ---------------- HTML Header ----------------------
    copy(    szBuffer,charsmax(szBuffer),"<!DOCTYPE html PUBLIC ^"-//W3C//DTD HTML 4.01//EN^" ^"http://www.w3.org/TR/html4/strict.dtd^">")   
    add(    szBuffer,charsmax(szBuffer),"<html>")
    add(    szBuffer,charsmax(szBuffer),"<head><title>AMXX Player Status</title>")
   
    add(    szBuffer,charsmax(szBuffer),"<style type=^"text/css^">")
    // ---------------- CSS Properties -------------------
    add(    szBuffer,charsmax(szBuffer),"body        {margin:0px; padding:0px; background:black; color:#FFB000;}")
    add(    szBuffer,charsmax(szBuffer),"table,td,th    {border-collapse:collapse; border-style:solid; border-width:1px; border-color:#FFB000;}")
    add(    szBuffer,charsmax(szBuffer),"tr.even        {background: #805800;}")
    // ---------------------------------------------------
    add(    szBuffer,charsmax(szBuffer),"</style></head>")
    // ---------------------------------------------------
   
   
    // ----------------- Table Start ---------------------
    add(    szBuffer,charsmax(szBuffer),"<body><table>")
   
    // ------------------- Row Start ---------------------
    format(    szBuffer,charsmax(szBuffer),Status_RowStart,szBuffer,(++iRowCount % 2) ? "odd" : "even")
   
    for(new i=0;i < sizeof(Status_Elements);i++)
        format(    szBuffer,charsmax(szBuffer),Status_TableHead,szBuffer,Status_Elements[i])
   
    add(    szBuffer,charsmax(szBuffer),Status_RowEnd)
    // -------------------- Row End ----------------------
   
    new iMaxPlayers = get_maxplayers(),iCount
    new iPing,iLoss,Float:fTemp
   
    for(new i=iPlayerStart;i <= iMaxPlayers;i++)
    {
        if(!is_user_connected(i))
            continue
        else if(++iCount > STATUS_MAX_PLAYERS)
            break
           
        format(    szBuffer,charsmax(szBuffer),Status_RowStart,    szBuffer,(++iRowCount % 2) ? "odd" : "even")
           
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,get_user_userid(i))
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,i)
       
        get_user_name(i,szTemp,charsmax(szTemp))
        htmlspecialchars(szTemp,charsmax(szTemp))
        format(    szBuffer,charsmax(szBuffer),Status_DataString,    szBuffer,szTemp)
       
        get_user_authid(i,szTemp,charsmax(szTemp))
        format(    szBuffer,charsmax(szBuffer),Status_DataString,    szBuffer,szTemp)
       
        get_user_ip(i,szTemp,charsmax(szTemp),1)
        format(    szBuffer,charsmax(szBuffer),Status_DataString,    szBuffer,szTemp)
       
        get_flags(get_user_flags(i),szTemp,charsmax(szTemp))
        format(    szBuffer,charsmax(szBuffer),Status_DataString,    szBuffer,szTemp)
       
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,pev(i,pev_frags))
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,get_user_deaths(i))
       
        pev(i,pev_health,fTemp)
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,floatround(fTemp))
       
        pev(i,pev_armorvalue,fTemp)
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,floatround(fTemp))
       
        get_user_ping(i,iPing,iLoss)
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,iPing)
        format(    szBuffer,charsmax(szBuffer),Status_DataInteger,    szBuffer,iLoss)
       
        get_user_team(i,szTemp,charsmax(szTemp))
        format(    szBuffer,charsmax(szBuffer),Status_DataString,    szBuffer,szTemp)

        FormatTime(szTemp,charsmax(szTemp),get_user_time(i))
        format(    szBuffer,charsmax(szBuffer),Status_DataString,    szBuffer,szTemp)
       
        add(    szBuffer,charsmax(szBuffer),Status_RowEnd)
    }
   
    add(    szBuffer,charsmax(szBuffer),"</table></body>")
    // ------------------ Table End ---------------------
    add(    szBuffer,charsmax(szBuffer),"</html>")
    // ----------------- Document End -------------------
   
    new hFile = fopen("addons\motd.html","w")
    if(hFile)
    {
        fputs(hFile,szBuffer)
        fclose(hFile)
    }
   
    show_motd(id,szBuffer)
   
    return PLUGIN_HANDLED
}


anakin_cstrike 09-06-2008 15:40

Re: 'String formatted incorrectly'
 
Thats a lot of code and is not what i'm looking for, thanks anyway.

danielkza 09-06-2008 16:05

Re: 'String formatted incorrectly'
 
Quote:

Originally Posted by anakin_cstrike (Post 682227)
Thats a lot of code and is not what i'm looking for, thanks anyway.

If you're doing a small thing it may not be worth, but it's always a good practice to stick to the standards (most of the style elements are deprecated in W3 rules). Since it looks like a simple thing, just keep it as it is.


All times are GMT -4. The time now is 03:01.

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