AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Maps in file (https://forums.alliedmods.net/showthread.php?t=174626)

extreem 12-23-2011 01:45

Maps in file
 
Help me please, I want create plugin which will send message in chat on samothing maps.
Here is code, I think you will understand what I want.
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Extreem"
#define MAX_MAPS 150

new lines[MAX_MAPS][20]
new 
mapsNam


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""testFunc")
}
public 
testFunc() {
    new 
mapsfile[128]
    
get_localinfo("amxx_configsdir"mapsfilecharsmax(mapsfile))
    
add(mapsfilecharsmax(mapsfile), "/allmaps.ini")
    
    new 
leni=0
    
while( MAX_MAPS && read_file(mapsfileilines[mapsNam], 19len))
    {
        
i++
        if( 
lines[mapsNam][0] == ';' || len == 0)
            continue
        
mapsNam++
    }

    new 
nameMap[30]
    
get_mapname(nameMapcharsmax(nameMap))
    if(
equal(nameMaplines[i++])){
        
client_print(0print_chat"Map name is aim_awp")
    }
    else{
        
client_print(0print_chat"Map name is NOT aim_awp")
    }


In file allmapsa.ini I wanna write maps aim_awp and awp_india. But on aim_awp server print Map name is NOT aim_awp

fysiks 12-23-2011 02:58

Re: Maps in file
 
Quote:

Originally Posted by extreem (Post 1618117)
Here is code, I think you will understand what I want.

Not really. Your code (when it works) will say that the map is aim_awp when it's actually awp_india.

However, I think you need to trim() the lines after you read them from the file. Also, I would recommend using the "newer" file function because they are more intuitive, IMO.

This is a quick version that basically does the same that you are trying to do in yours:

PHP Code:

#include <amxmodx>

public plugin_init()
{
    
register_clcmd("say /test""testFunc")
}
public 
testFunc()
{
    new 
mapsfile[128]
    
get_localinfo("amxx_configsdir"mapsfilecharsmax(mapsfile))
    
add(mapsfilecharsmax(mapsfile), "/allmaps.ini")

    new 
fopen(mapsfile"r")
    new 
data[32]
    new 
szMap[32]; get_mapname(szMapcharsmax(szMap));
        
    if(
f)
    {
        while( !
feof(f) )
        {
            
fgets(fdatacharsmax(data))
            
trim(data)
            
            if( 
equal(szMapdata) )
            {
                
client_print(0print_chat"This map is in the list.")
            }
            else
            {
                
client_print(0print_chat"This map is NOT in the list.")
            }
        }
        
fclose(f)
    }


If you explain extactly what you are trying to do (the ultimate goal of your project) we can either tell you how to do it eith a different method or elaborate on this method.

extreem 12-23-2011 10:37

Re: Maps in file
 
But I have some errors, if I have two maps in file, server print
  • This map is NOT in the list
  • This map is in the list
If I have 3 maps in file, server print
  • This map is NOT in the list
  • This map is in the list
  • This map is NOT in the list
what is it ? Maybe I must read lines ?

fysiks 12-23-2011 11:40

Re: Maps in file
 
1. That's not an error (technically).
2.
Quote:

Originally Posted by fysiks (Post 1618130)
If you explain extactly what you are trying to do (the ultimate goal of your project) we can either tell you how to do it with a different method or elaborate on this method.


extreem 12-24-2011 08:36

Re: Maps in file
 
I want make that on maps in file list player will have clcmd, on other maps player will not have clcmd

fysiks 12-24-2011 11:39

Re: Maps in file
 
Quote:

Originally Posted by extreem (Post 1618846)
I want make that on maps in file list player will have clcmd, on other maps player will not have clcmd

I would just disbale the plugin with map specific plugin files on maps that shouldn't have the command. If there are more maps that shouldn't have it than there are that should then you can just enable it with map specific plugin files on maps that should have it.

Documentation: Map Specific Plugins

As a last resort (or if you want the command en/disabled on half of your maps):

PHP Code:

#include <amxmodx>

public plugin_init()
{
    new 
mapsfile[128], bMapFound false
    get_localinfo
("amxx_configsdir"mapsfilecharsmax(mapsfile))
    
add(mapsfilecharsmax(mapsfile), "/allmaps.ini")

    new 
fopen(mapsfile"r")
    new 
data[32]
    new 
szMap[32]; get_mapname(szMapcharsmax(szMap));
        
    if(
f)
    {
        while( !
feof(f) )
        {
            
fgets(fdatacharsmax(data))
            
trim(data)
            
            if( 
equal(szMapdata) )
            {
                
bMapFound true
            
}
        }
        
fclose(f)
    }
    
    if( !
bMapFound )
    {
        
register_clcmd("say /test""testFunc")
    }




All times are GMT -4. The time now is 11:55.

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