Raised This Month: $ Target: $400
 0% 

Formatting question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Estland
Member
Join Date: Nov 2012
Old 11-16-2014 , 17:00   Re: Formatting question
Reply With Quote #1

Quote:
Originally Posted by YamiKaitou View Post
Enable debug so you can figure out exactly which line is producing the error
Code:
L 11/16/2014 - 23:58:06: String formatted incorrectly - parameter 3 (total 2)
L 11/16/2014 - 23:58:06: [AMXX] Displaying debug trace (plugin "vip_prefixid.amxx")
L 11/16/2014 - 23:58:06: [AMXX] Run time error 25: parameter error 
L 11/16/2014 - 23:58:06: [AMXX]    [0] textAtC2cD.sma::admin_chatall (line 39)
L 11/16/2014 - 23:58:06: [AMXX]    [1] textAtC2cD.sma::hook_say (line 29)
Estland is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-16-2014 , 17:06   Re: Formatting question
Reply With Quote #2

Your error is with vformat. If you are unsure why, then you need to debug it. Try logging the contents of input.

Although, since you never pass anything to be formatted, why not just use formatex and drop the usage of vformat?
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Estland
Member
Join Date: Nov 2012
Old 11-16-2014 , 20:11   Re: Formatting question
Reply With Quote #3

First of all - thank you for your responses.

So if I would use...
Code:
formatex(szMsg, charsmax(szMsg), input, 3)
...then what should I do with this line? Leave it as it is?
Code:
stock admin_chatall (const id, const input[], any:...)
Estland is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-16-2014 , 20:32   Re: Formatting question
Reply With Quote #4

Actually, I would use this (after a second look)

Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>

#define VIP_ACCESS    ADMIN_LEVEL_H    // t flag
#define ADMIN_ACCESS    ADMIN_BAN    // d flag
#define IMMU_ACCESS    ADMIN_IMMUNITY    // a flag
#define KORRAHOIDJA    ADMIN_LEVEL_F    // r flag
#define OMANIK        ADMIN_CVAR    // g flag

public plugin_init() {
    register_plugin( "VIP prefixid" , "1.0.0" , "Faval" )
    register_clcmd ( "say" , "hook_say" )
}

public hook_say ( id )
{
    if ( ! is_user_admin ( id ) )
    return PLUGIN_CONTINUE
    
    new tekst[128]
    read_argv ( 1 , tekst , charsmax(tekst) )
    
    // Kontroll
    if(tekst[0] == '@' || tekst[0] == '/' || tekst[0] == '!' || equal(tekst, ""))
    return PLUGIN_CONTINUE
    
    return admin_chatall ( id , tekst )
}

stock admin_chatall (const id, const input[])
{
    static szMsg[768], Name[32]
    get_user_name ( id , Name , charsmax(Name))
    
    if( get_user_flags(id) & OMANIK )
    formatex ( szMsg, charsmax(szMsg), "^x04[OMANIK]^x03 %s^x01:^x04 %s", Name , input )
    
    else if( get_user_flags(id) & KORRAHOIDJA ) 
    formatex ( szMsg, charsmax(szMsg), "^x04[KORRAHOIDJA]^x03 %s^x01:^x04 %s", Name , input )
    
    else if( get_user_flags(id) & IMMU_ACCESS ) 
    formatex ( szMsg, charsmax(szMsg), "^x04[IMMUADMIN]^x03 %s^x01:^x04 %s", Name , input )
    
    else if( get_user_flags(id) & ADMIN_ACCESS ) 
    formatex ( szMsg, charsmax(szMsg), "^x04[ADMIN]^x03 %s^x01:^x04 %s", Name , input )
    
    else if( get_user_flags(id) & VIP_ACCESS ) 
    formatex ( szMsg, charsmax(szMsg), "^x04[VIP]^x03 %s^x01:^x04 %s", Name , input )
    
    new Players[32], iNum;
    get_players(Players, iNum);
    for( new k = 0, iPlayer ; k < iNum ; k++ )
    {        
        iPlayer = Players[k];
        message_begin(MSG_ONE, get_user_msgid("SayText"), {0,0,0}, iPlayer)
        write_byte(iPlayer)
        write_string(szMsg)
        message_end()
    }
    return PLUGIN_HANDLED_MAIN
}
What I changed
* Removed the "return PLUGIN_HANDLED" from hook_say and instead had it return whatever admin_chatall returns
* Removed the vformat altogether, it wasn't doing anything
* Changed all the usages of format to formatex
* Used input in formatex instead of szMsg
* Changed your IF statements into IF ELSE statements
* Replaced your FOR loop with one that uses get_players
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 11-17-2014 at 11:32.
YamiKaitou is offline
Estland
Member
Join Date: Nov 2012
Old 11-17-2014 , 11:27   Re: Formatting question
Reply With Quote #5

Thanks. Code looks better, but still throws an error (displays doublemessages, one with and one without tag).
Code:
L 11/17/2014 - 18:23:44: [AMXX] Displaying debug trace (plugin "vip_prefixid.amxx")
L 11/17/2014 - 18:23:44: [AMXX] Run time error 4: index out of bounds 
L 11/17/2014 - 18:23:44: [AMXX]    [0] textK2evxz.sma::admin_chatall (line 56)
L 11/17/2014 - 18:23:44: [AMXX]    [1] textK2evxz.sma::hook_say (line 29)
Estland is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-17-2014 , 11:33   Re: Formatting question
Reply With Quote #6

Quote:
Originally Posted by Estland View Post
Thanks. Code looks better, but still throws an error (displays doublemessages, one with and one without tag).
Then you have another plugin that is printing the Chat messages as well. If you don't want to fix your other plugin, change the PLUGIN_HANDLED_MAIN to PLUGIN_HANDLED


Quote:
Code:
L 11/17/2014 - 18:23:44: [AMXX] Displaying debug trace (plugin "vip_prefixid.amxx")
L 11/17/2014 - 18:23:44: [AMXX] Run time error 4: index out of bounds 
L 11/17/2014 - 18:23:44: [AMXX]    [0] textK2evxz.sma::admin_chatall (line 56)
L 11/17/2014 - 18:23:44: [AMXX]    [1] textK2evxz.sma::hook_say (line 29)
Fixed code above, typo on my part.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Estland
Member
Join Date: Nov 2012
Old 11-17-2014 , 12:16   Re: Formatting question
Reply With Quote #7

Thank you for your help, this is solved now.
Estland is offline
Reply



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 17:29.


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