Raised This Month: $ Target: $400
 0% 

about constants and strings...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LucasFromDK
Member
Join Date: Sep 2016
Old 11-20-2016 , 15:33   about constants and strings...
Reply With Quote #1

I'm trying to create a plugin which checks the map name and if the map is in Maps[][] list to change it to a random one from LegalMaps[][] list.

PHP Code:
static const StringMaps[][] = {
    
"de_dust2",
    
"de_inferno",
    
"de_train",
    
"de_mirage"
}

static const 
StringLegalMaps[][] = {
    
"de_vertigo",
    
"de_dust",
    
"de_aztec",
    
"de_nuke"
}

public 
OnMapStart( ) {
    
decl StringMapName128 ]
    
GetCurrentMapMapNamesizeofMapName ) )
    
    if( 
StrContainsMapsMapName ) ) {
        new 
RandomLegalMap GetRandomInt0sizeofLegalMaps ) -)
        
ServerCommand"changelevel %s"RandomLegalMap )
    }

LucasFromDK is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 11-20-2016 , 15:39   Re: about constants and strings...
Reply With Quote #2

And your problem is...?
Michael Shoe Maker is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 11-20-2016 , 16:04   Re: about constants and strings...
Reply With Quote #3

Michael Shoe Maker, i think problem about iteration of array. (StrContains( Maps, MapName ))
PHP Code:
public OnMapStart( ) { 
    
decl StringMapName128 
    
GetCurrentMapMapNamesizeofMapName ) ) 
    
    for ( new 
0sizeofMaps ); i++ )
        if( 
StrEqualMaps[i], MapName ) )
            
ServerCommand"changelevel %s"LegalMapsGetRandomInt0sizeofLegalMaps ) - ) ] ) 

Kailo is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-20-2016 , 16:27   Re: about constants and strings...
Reply With Quote #4

The question should be "Why do something like that? Maplists are also a thing..."

As fo the code.. I would do something like
PHP Code:
new Handle:g_hBadMaps;
new 
Handle:g_hLegalMaps;

public 
OnPluginStart()
{
    
g_hBadMaps CreateArray(64);
    
g_hLegalMaps CreateArray(64);
    
    
PushArrayString(g_hBadMaps"de_dust2");
    
PushArrayString(g_hBadMaps"de_inferno");
    
PushArrayString(g_hBadMaps"de_train");
    
PushArrayString(g_hBadMaps"de_mirage");
    
    
PushArrayString(g_hLegalMaps"de_vertigo");
    
PushArrayString(g_hLegalMaps"de_dust");
    
PushArrayString(g_hLegalMaps"de_aztec");
    
PushArrayString(g_hLegalMaps"de_nuke");
}

public 
OnMapStart()
{
    new 
String:sMap[64];
    
GetCurrentMap(sMapsizeof(sMap));

    if (
FindStringInArray(g_hBadMapssMap) != -1) {
        new 
GetRandomInt(0GetArraySize(g_hLegalMaps));

        
GetArrayString(g_hLegalMapsisMapsizeof(sMap));
        
ForceChangeLevel(sMap);
    }

__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.

Last edited by KissLick; 11-20-2016 at 16:33.
KissLick is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-20-2016 , 16:34   Re: about constants and strings...
Reply With Quote #5

A hashmap would be better for the bad maps collection.
klippy is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-20-2016 , 16:46   Re: about constants and strings...
Reply With Quote #6

Quote:
Originally Posted by KliPPy View Post
A hashmap would be better for the bad maps collection.
+1

But I still use old/legacy syntax and there is no IsKeyInTrie function :-D
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-20-2016 , 23:24   Re: about constants and strings...
Reply With Quote #7

Quote:
Originally Posted by KissLick View Post
+1

But I still use old/legacy syntax and there is no IsKeyInTrie function :-D
A few things about this.

1. GetTrie* returns false when a key doesn't exist.
2. You can use a Trie snapshot to check for it:

PHP Code:
// Old Style
stock bool:IsKeyInTrie(Handle:trie, const String:key[])
{
    new 
Handle:snapshot CreateTrieSnapshot(trie);
    new 
snapShotLen TrieSnapshotLength(snapshot);
    new 
bool:found;

    for (new 
0snapShotLeni++)
    {
        new 
length TrieSnapshotKeyBufferSize(triei);
        new 
String:myKey[length];
        
GetTrieSnapshotKey(triei);
        if (
StrEqual(keymyKey))
        {
            
found true;
            break;
        }
    }

    
CloseHandle(snapshot);
    return 
found;
}

// New Style
stock bool IsKeyInTrie(StringMap trie, const char[] key)
{
    
StringMapSnapshot snapshot trie.Snapshot();
    
int snapShotLen snapshot.Length;
    
bool found;

    for (
int i 0snapShotLeni++)
    {
        
int length snapshot.KeyBufferSize(i);
        
char[] myKey = new char[length];
        
snapshot.GetKey(i);
        if (
StrEqual(keymyKey))
        {
            
found true;
            break;
        }
    }

    
delete snapshot;
    return 
found;

__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-21-2016 , 01:29   Re: about constants and strings...
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
A few things about this.

1. GetTrie* returns false when a key doesn't exist. - requires extra variable
2. You can use a Trie snapshot to check for it - this is SM 1.8+ or 1.7+ ?
Good to mention anyway
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-21-2016 , 02:28   Re: about constants and strings...
Reply With Quote #9

Quote:
Originally Posted by KissLick View Post
Good to mention anyway
The second is 1.7+.

Having said that, if you're not running 1.7 or newer by now, well...
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 02:29.


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