Raised This Month: $ Target: $400
 0% 

[AMXX] Getting the mapname


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Popeye
Junior Member
Join Date: Nov 2006
Old 06-30-2009 , 09:06   [AMXX] Getting the mapname
Reply With Quote #1

Hi, I want edit one plugin.

Code:
new base[] = "rules.txt"
How i can edit this code to getting mapname?

Code:
new base[] = "de_dust2.txt"
This is bad :/

Code:
new base [] = get_mapname("s.txt", mapname)

Last edited by Popeye; 06-30-2009 at 09:15.
Popeye is offline
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 06-30-2009 , 09:14   Re: [AMXX] Getting the mapname
Reply With Quote #2

PHP Code:
//...
new base[16];
get_mapname(basesizeof (base));
//or
get_mapname(base16);
// variable "base" will contain name of the current map...
//... 

Last edited by TheRadiance; 06-30-2009 at 09:16.
TheRadiance is offline
Send a message via ICQ to TheRadiance
Popeye
Junior Member
Join Date: Nov 2006
Old 06-30-2009 , 09:23   Re: [AMXX] Getting the mapname
Reply With Quote #3

sry but i'm noob and i dont underestand

Code:
new base[16];
get_mapname(base, "%s.txt", mapname);
not work :/
Popeye is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 06-30-2009 , 09:35   Re: [AMXX] Getting the mapname
Reply With Quote #4

Wtf are you trying todo?
__________________
xPaw is offline
Popeye
Junior Member
Join Date: Nov 2006
Old 06-30-2009 , 09:38   Re: [AMXX] Getting the mapname
Reply With Quote #5

I want to create rules for each map. Rules is read from a text file.
Popeye is offline
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 06-30-2009 , 12:08   Re: [AMXX] Getting the mapname
Reply With Quote #6

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    
register_plugin("maprules""1.0""Popeye");
}

public 
plugin_cfg()
{
    new 
map[32];
    
get_mapname(mapsizeof (map));

    new 
file[64];
    
get_configsdir(filesizeof (file));
    
format(filesizeof (file), "%s/%s.txt"filemap);

    if (
file_exists(file))
    {
        
// Your actions...
    
}


If you not good in scripting you should post topic in suggestions/requests and give us more details about plugin you want

Last edited by TheRadiance; 06-30-2009 at 12:13.
TheRadiance is offline
Send a message via ICQ to TheRadiance
Popeye
Junior Member
Join Date: Nov 2006
Old 06-30-2009 , 13:53   Re: [AMXX] Getting the mapname
Reply With Quote #7

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

new base[] = "rules.txt"

new i, num, text[127], hudmsg[440] //max hudmessage length was 439 chars (?)

public plugin_init()
{
    
    register_plugin("AMXX Public server rules", "1.20", "Priski")
    
    // register command
    
    register_concmd("rules_show", "rules", ADMIN_KICK, "- show rules to everybody")
    register_concmd("rules_enable", "r_enable", ADMIN_KICK, "- <1|0> set automessagin on/off")
    register_cvar("rules_admin_only", "0")
    register_cvar("rules_join", "1")
    register_cvar("rules_join_timeout", "5")
    register_cvar("rules_hudmessage_time", "10")
    register_cvar("rules_interval", "600")
    register_clcmd("say /rules", "clientrules", ADMIN_ALL, "- show rules")
} 

public plugin_cfg() {
    
    if (!file_exists(base)) {
        write_file(base, "; This is the public rules file, put your rules below")
        write_file(base, "; Remember, max amount of characters is 439")
        console_print(0, "%s file not found. creating new ...", base)
    }
    
}

public client_authorized ( id ) {
    // on join display rules
    
    if (get_cvar_num("rules_join")) {
        new tmp[1]
        tmp[0] = id
        set_task(1.0, "showrules",id,tmp,1)
        console_print(0, "[user %d] client auth!", tmp[0])
    }
    
    return PLUGIN_HANDLED
}


public showrules (pid[]) {
    new id = pid[0]
    
    if ( get_user_team(id) != 1 && get_user_team(id) != 2 ) {
        if (id) {
            new tmp[1]
            tmp[0] = id
            set_task(2.0, "showrules",id,tmp,1)  // not yet in server
            console_print(0, "[user %d] wait for joining team ...", id)
        }
        return PLUGIN_HANDLED
    }
    
    new tmp[1]
    tmp[0] = id
    
    console_print(0, "[user %d] joined team : %d", id, get_user_team(id))
    console_print(0, "[user %d] printing rules after %d seconds", id, get_cvar_num("rules_join_timeout"))
    
    set_task(get_cvar_float("rules_join_timeout"), "printrules", id, tmp, 1)  // not yet in server
    
    return PLUGIN_HANDLED
}

public printrules(pid[])
{
    new id = pid[0]
    if (file_exists(base))
        {
        
        console_print(0, "[user] printing rules for user %d", id)
        
        set_hudmessage ( 200, 150, 0, 0.02, 0.25, 2, 0.1, get_cvar_float("rules_hudmessage_time"), 0.05, 1.0, 1)
        format(hudmsg, 439, "")
        
        // read all the rules
        for(i=0; read_file(base, i, text, 127, num); i++) {
            if (num > 0 && text[0] != ';') {
                // display with predefined delay
                add(hudmsg,439,text)
                add(hudmsg,439,"^n")
            }
        }
        
        // show hudmessages
        show_hudmessage(id, hudmsg)
        
    }
    
    return PLUGIN_HANDLED
}


public r_enable(id, level, cid)
{
    if (!cmd_access(id, level, cid, 0)) {  // NOT ADMIN
        return PLUGIN_HANDLED
    }
    
    new arg[3]
    
    read_argv(1, arg, 2)
    new value = str_to_num(arg)
    
    if (!isalnum(arg[0]))
        value = -1
    
    if (value == 0) {
        
        if (task_exists(2)) // close task
            remove_task(2)    
        
        console_print(id, "You have disabled automatic messages")
        return PLUGIN_HANDLED
        
    }
    if (value == 1) {
        // activate task, reload if already exist
        if (task_exists(2)) {
            change_task(2, get_cvar_float("rules_interval"))
            } else {
            set_task(get_cvar_float("rules_interval"), "rules", 2, "", 0, "b")
        }    
        console_print(id, "You have enabled automatic messages")
        return PLUGIN_HANDLED        
    }
    if (task_exists(2)) {
        console_print(id, "automessages is ON.")
        } else {
        console_print(id, "automessages is OFF.")
    }
    console_print(id, "rules_enable <1|0> (1 = ON, 0 = OFF)")
    return PLUGIN_HANDLED        
    
}

public clientrules(id, level, cid) {
    new pID[1]
    pID[0] = id
    
    console_print(0,"[user %d]Print rules for me only",pID[0])
    printrules(pID[0])
}

public rules(id, level, cid)
{
    new pID[1]
    pID[0] = id
            
    if (!cmd_access(id, level, cid, 0)) {  // NOT ADMIN
        return PLUGIN_HANDLED
    }
    
    // read file to all users
    pID[0] = 0
    console_print(0,"[user %d]Print rules for all",id)
    printrules(pID[0])
    
    // Reset scheduled task after display
    if (get_cvar_float("rules_interval") > 0) {
        if (task_exists(2)) {
            change_task(2, get_cvar_float("rules_interval"))
            } else {
            set_task(get_cvar_float("rules_interval"), "rules", 200, "", 0, "b")
        }
    }
    
    return PLUGIN_HANDLED
}
Popeye is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-30-2009 , 14:11   Re: [AMXX] Getting the mapname
Reply With Quote #8

Wow, you should not use "sizeof()" you must use "sizeof() - 1" for string lengths.
__________________
fysiks is offline
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 07-01-2009 , 02:55   Re: [AMXX] Getting the mapname
Reply With Quote #9

Quote:
Wow, you should not use "sizeof()" you must use "sizeof() - 1" for string lengths.
PHP Code:
/* Returns player name. */
native get_user_name(index,name[],len); 
len = length of string if i understood this well?

I can't understand this as long as i scripting pawn.

Why sizeof (name) -1 ?

Imagine that user name contains 4 chars:
PHP Code:
new name[4];
get_user_name(idnamesizeof (name) - 1// sizeof (name) - 1 = 3
get_user_name(idnamesizeof (name)) // sizeof (name) = 4 
PHP Code:
// name rofl for example
//first case (sizeof (name) - 1): 0 1 2 3 4
//                                r o f               // 3 is empty; 4 is null;

//second case (sizeof (name)): 0 1 2 3 4
//                             r o f l            // 4 is null; 
also from SourcePawn base plugins:
PHP Code:
decl String:name[64];
GetClientName(clientnamesizeof(name)); 
Can anyone explain this to stupid Radiance?
Thanks

Last edited by TheRadiance; 07-01-2009 at 02:58.
TheRadiance is offline
Send a message via ICQ to TheRadiance
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-01-2009 , 05:36   Re: [AMXX] Getting the mapname
Reply With Quote #10

Just because if 4th will be filled it will show index out of bounds debug
__________________
xPaw 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 15:32.


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