Raised This Month: $51 Target: $400
 12% 

Maps in file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
extreem
Member
Join Date: Apr 2011
Location: Czech Republick
Old 12-23-2011 , 01:45   Maps in file
Reply With Quote #1

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
__________________
extreem is offline
Send a message via Skype™ to extreem
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-23-2011 , 02:58   Re: Maps in file
Reply With Quote #2

Quote:
Originally Posted by extreem View Post
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.
__________________

Last edited by fysiks; 12-23-2011 at 02:59.
fysiks is offline
extreem
Member
Join Date: Apr 2011
Location: Czech Republick
Old 12-23-2011 , 10:37   Re: Maps in file
Reply With Quote #3

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 ?
__________________
extreem is offline
Send a message via Skype™ to extreem
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-23-2011 , 11:40   Re: Maps in file
Reply With Quote #4

1. That's not an error (technically).
2.
Quote:
Originally Posted by fysiks View Post
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.
__________________

Last edited by fysiks; 12-23-2011 at 11:40.
fysiks is offline
extreem
Member
Join Date: Apr 2011
Location: Czech Republick
Old 12-24-2011 , 08:36   Re: Maps in file
Reply With Quote #5

I want make that on maps in file list player will have clcmd, on other maps player will not have clcmd
__________________
extreem is offline
Send a message via Skype™ to extreem
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-24-2011 , 11:39   Re: Maps in file
Reply With Quote #6

Quote:
Originally Posted by extreem View Post
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")
    }

__________________

Last edited by fysiks; 12-24-2011 at 11:44.
fysiks 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:52.


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