AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help improving map-requester (https://forums.alliedmods.net/showthread.php?t=125836)

drekes 05-02-2010 17:31

Help improving map-requester
 
Hi,

I make this code where players can request new maps by typing "requestmap mapname" in console and it write the mapname , players name and steamid to a maprequests.ini file in data folder.
But i'm kinda new to read_argv, so if you guys could check if i can improve it.
Thanks

PHP Code:

#include <amxmodx>
#include <colorchat>

new g_szFile[64]

new 
cvar_advert

public plugin_init()
{
    
register_plugin("Map requests""1.0""Drekes")
    
    
register_concmd("requestmap""addmap")
    
    
cvar_advert register_cvar("amx_mapreq_advert""1")
    
register_cvar("amx_mapreq_advertdelay""400.0")            // Advert delay MUST BE A FLOAT

    
new datadir[64]
    
get_localinfo("amxx_datadir"datadir63)
    
format(g_szFile63"%s/maprequests.ini"datadir)
    
    if(!
file_exists(g_szFile))
        
log_amx("maprequests.ini not found, creating new file.")
        
    
    
set_task(get_cvar_float("amx_mapreq_advertdelay"), "advert"0// Thanks to GHW_Chronic
}

public 
advert()
{
    if(
get_pcvar_num(cvar_advert) != 1)
    {
        
remove_task()
        return 
PLUGIN_HANDLED
    
}
    
    
ColorChat(0NORMAL"[AMXX]: Want a map that isn't on the server? Typ ^x03requestmap mapname ^x01in console")
    return 
PLUGIN_HANDLED
}
        
public 
addmap(id)
{
    new 
szData[35], szWrite[128]
    new 
szName[33], szSteamID[35]
    
    
read_argv(1szDatacharsmax(szData))
    
get_user_name(idszName32)
    
get_user_authid(idszSteamID34)
    
    
formatex(szWrite127"%s ID: %s requests map: %s"szNameszSteamIDszData)
    
write_file(g_szFileszWrite)
    
    
console_print(id"Your map request has been succesfully added. We will add it to the server soon.")


Maprequests.ini:
Code:

Angel_Killer -*CF*- ID: STEAM_ID_LAN requests map: de_test
If this code is bad, please don't post like "I lolled at this code...", instead tell me what's wrong

fysiks 05-02-2010 18:04

Re: Help improving map-requester
 
Does it work?

If I haven't missed anything, the map requesting part looks fine. However, I would change the advert function to:

PHP Code:

public advert()
{
    if( 
get_pcvar_num(cvar_advert) )
    {
        
ColorChat(0NORMAL"[AMXX]: Want a map that isn't on the server? Typ ^x03requestmap mapname ^x01in console")
    }



drekes 05-02-2010 18:07

Re: Help improving map-requester
 
Yes, it works perfect. If you want i can give you a line from the maprequests.ini file.

But should'nt i remove the task if cvar_advert == 0, to avoid it been called all the time? Or won't that work because of plugin init?
PHP Code:

public advert() 

    if( 
get_pcvar_num(cvar_advert) ) 
    { 
        
ColorChat(0NORMAL"[AMXX]: Want a map that isn't on the server? Typ ^x03requestmap mapname ^x01in console"
    } 
    
    else
    {
        
remove_task
    
}


</span></span>

fysiks 05-02-2010 18:09

Re: Help improving map-requester
 
Quote:

Originally Posted by drekes (Post 1168327)
But should'nt i remove the task if cvar_advert == 0, to avoid it been called all the time?

I don't think I would because you can't turn it back on. I would make disabling the advert completely by setting the frequency to 0:


PHP Code:

    if( get_cvar_num("amx_mapreq_avertdelay") )
        
set_task(get_cvar_float("amx_mapreq_advertdelay"), "advert"0

(Not tested as is)

Actually, if it were me, I would just hard code it. Especially if it was just for my server.

drekes 05-02-2010 18:12

Re: Help improving map-requester
 
So i put that in plugin_init() under the register_cvar?

I didn't know that i could use
PHP Code:

if(get_pcvar_num(...)) 

in plugin_init()

Edit: should it be
Code:

get_cvar_num
or
Code:

get_pcvar_num

fysiks 05-02-2010 18:23

Re: Help improving map-requester
 
Ok, so I change my mind a little bit. This is what I think I might do:

PHP Code:

#include <amxmodx>
#include <colorchat>

new g_szFile[64]


public 
plugin_init()
{
    
register_plugin("Map requests""1.0""Drekes")
    
    
register_concmd("requestmap""addmap")
    
    new 
datadir[64]
    
get_localinfo("amxx_datadir"datadir63)
    
format(g_szFile63"%s/maprequests.ini"datadir)
    
    
// Advertisements
    
register_cvar("amx_mapreq_advertdelay""400"
    new 
Float:fDelay get_cvar_float("amx_mapreq_advertdelay")
    if( 
fDelay 0.1 )
        
set_task(fDelay"advert"___"b")
}

public 
advert()
{
    
ColorChat(0NORMAL"[AMXX]: Want a map that isn't on the server? Typ ^x03requestmap mapname ^x01in console")
}

public 
addmap(id)
{
    new 
szData[35], szWrite[128]
    new 
szName[33], szSteamID[35]
    
    
read_argv(1szDatacharsmax(szData))
    
get_user_name(idszName32)
    
get_user_authid(idszSteamID34)
    
    
formatex(szWrite127"%s ID: %s requests map: %s"szNameszSteamIDszData)
    
write_file(g_szFileszWrite)
    
    
console_print(id"Your map request has been succesfully added. We will add it to the server soon.")


So, it means that the advertisements are either on during the whole map or off during the whole map.

drekes 05-02-2010 18:27

Re: Help improving map-requester
 
i did the same, but in another way xD
PHP Code:

    if(get_pcvar_num(cvar_advert) == 1)
        
set_task(get_cvar_float("amx_mapreq_advertdelay"), "advert"0__"b"

correct me if i'm wrong, but shouldn't it be:
PHP Code:

register_cvar("amx_mapreq_advertdelay""400.0"

so the cvar is a float?

btw: i forgot to thank you in my previous posts, Thanks

fysiks 05-02-2010 18:35

Re: Help improving map-requester
 
Quote:

Originally Posted by drekes (Post 1168367)
i did the same, but in another way xD
PHP Code:

    if(get_pcvar_num(cvar_advert) == 1)
        
set_task(get_cvar_float("amx_mapreq_advertdelay"), "advert"0__"b"

correct me if i'm wrong, but shouldn't it be:
PHP Code:

register_cvar("amx_mapreq_advertdelay""400.0"

so the cvar is a float?

btw: i forgot to thank you in my previous posts, Thanks

1. You don't need to do the "== 1" operation.
2. It shouldn't matter. Test it out.

drekes 05-02-2010 18:41

Re: Help improving map-requester
 
i tryed it with the "amx_mapreq_advertdelay 400"
But it shows up every 8-10 seconds

Edit: with both 400 and 400.0, 10 seconds delay.
Strange?

fysiks 05-02-2010 19:46

Re: Help improving map-requester
 
Quote:

Originally Posted by drekes (Post 1168384)
i tryed it with the "amx_mapreq_advertdelay 400"
But it shows up every 8-10 seconds

Edit: with both 400 and 400.0, 10 seconds delay.
Strange?

It works fine for me. Try adding this code to advert():

PHP Code:

    static Float:fTime
    server_print
("Cvar: %f <<>> Actual = %f"get_cvar_float("amx_mapreq_advertdelay"), get_gametime() - fTime)
    
fTime get_gametime() 



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

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