AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Map check (https://forums.alliedmods.net/showthread.php?t=217657)

ke3ller 06-05-2013 14:55

Map check
 
Pls tell me how to check for a specific map, I want to give an item in a map
Ex:
PHP Code:

public fwHamPlayerSpawnPostid ) {
        if ( 
map_is_35hp ) {
                
give_itemid "weapon_m4a1" )
        }



YamiKaitou 06-05-2013 14:58

Re: Map check
 
Get the map name and then compare it

bibu 06-05-2013 15:00

Re: Map check
 
Seriously... search.

TheDS1337 06-05-2013 15:01

Re: Map check
 
Quote:

Originally Posted by YamiKaitou (Post 1965236)
Get the map name and then compare it

Code:
static MapName[ 32 ]; get_mapname( MapName, charsmax( MapName ) ); if( equal( MapName, "35hp" ) ) {         // Do something         give_item( id , "weapon_m4a1" ) }

fysiks 06-05-2013 16:16

Re: Map check
 
Only enable this plugin on that particular map using the map specific plugin files.

Backstabnoob 06-06-2013 02:23

Re: Map check
 
Quote:

Originally Posted by DeagLe.Studio (Post 1965240)
Code:
static MapName[ 32 ]; get_mapname( MapName, charsmax( MapName ) ); if( equal( MapName, "35hp" ) ) {         // Do something         give_item( id , "weapon_m4a1" ) }


Since the get_mapname function should be called only once, it's better to check it only once and save the result in a variable. You also shouldn't make the variable static but rather global and cache it only once; your way re-caches the value in MapName static each time the function is called, so either check if the first symbol has been set with

Code:
static MapName[ 32 ] if( !MapName[ 0 ] )    get_mapname( MapName, charsmax( MapName ) )


Or just do it this way, which is overally more efficient:

Code:
new bool: g_IsMap35Hp public plugin_init( ) {    new szMapName[ 32 ]    get_mapname( szMapName, charsmax( szMapName ) )    g_IsMap35Hp = equali( szMapName, "35hp" ) } // ... if( g_IsMap35Hp ) { }


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

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