Raised This Month: $ Target: $400
 0% 

Get current Map and use 'if'


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Veggetta
Member
Join Date: Mar 2008
Location: Portugal
Old 07-08-2012 , 08:50   Get current Map and use 'if'
Reply With Quote #1

Hello everybody,

today i want to do something like:

PHP Code:
new Name[32]
get_mapname(Namecharsmax(Name))
// And now i'm stuck with an error
if(Name == "cs_")
{
    function
}
else if(
Name == "de_")
{
   
Other Funtion

"Error: Array must be indexed (variable "Name") on line ..."
So what do i do to correct this ?
Veggetta is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 07-08-2012 , 08:52   Re: Get current Map and use 'if'
Reply With Quote #2

Code:
new Name[32] get_mapname(Name, 31) if(equali(Name, "cs_") {     function } else if(equali(Name, "de_") {    Other Funtion }
__________________

Last edited by kiki33hun; 07-08-2012 at 11:42.
kiki33hun is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-08-2012 , 08:54   Re: Get current Map and use 'if'
Reply With Quote #3

You cannot use == operator with strings. Use equal(), equali(), contain(), containi() functions.
Backstabnoob is offline
Veggetta
Member
Join Date: Mar 2008
Location: Portugal
Old 07-08-2012 , 08:54   Re: Get current Map and use 'if'
Reply With Quote #4

ahhh yes i forgot that x).
Thanks
Veggetta is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 07-08-2012 , 08:55   Re: Get current Map and use 'if'
Reply With Quote #5

To be more specific:
if(equali(szMapName, "de_", 3))

It only checks the first three characters (for example, "de_", not the whole map name "de_inferno").
t3hNox is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 07-08-2012 , 11:34   Re: Get current Map and use 'if'
Reply With Quote #6

Quote:
Originally Posted by kiki33hun View Post
Code:
    new Name[32]
    get_mapname(Name, 31)
    if(equali(mapname, "cs_")
    {
        function
    }
    else if(equali(mapname, "de_")
    {
        Other Funtion
    }
Why you create the "Name" but then you use "mapname"?
You forget to close the parentheses in both "if"
t3hNox code is fine.

Last edited by guipatinador; 07-08-2012 at 11:42.
guipatinador is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 07-08-2012 , 11:42   Re: Get current Map and use 'if'
Reply With Quote #7

Quote:
Originally Posted by guipatinador View Post
Why you create the "Name" but then you use "mapname"?
You forget to close the parentheses in both "if"
t3hNox code is fine.
Edited^^
__________________
kiki33hun is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-08-2012 , 13:35   Re: Get current Map and use 'if'
Reply With Quote #8

Code:
if( name[ 0 ] == 'c' && name[ 1 ] == 's' && name[ 2 ] == '_' ) cs_* map                    // do stuff if( name[ 0 ] == 'd' && name[ 1 ] == 'e' && name[ 2 ] == '_' ) de_* map                    // do stuff
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-08-2012 , 13:38   Re: Get current Map and use 'if'
Reply With Quote #9

Quote:
Originally Posted by lucas_7_94 View Post
Code:
if( name[ 0 ] == 'c' && name[ 1 ] == 's' && name[ 2 ] == '_' ) cs_* map                    // do stuff if( name[ 0 ] == 'd' && name[ 1 ] == 'e' && name[ 2 ] == '_' ) de_* map                    // do stuff
The two events are mutually exclusive so you need to take that into account. Also, for many newer people, it's easier to tell them to use equal[i].
__________________
fysiks is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-08-2012 , 14:47   Re: Get current Map and use 'if'
Reply With Quote #10

But that way it would be more efficiant, wouldnt it?
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
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 05:23.


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