AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Solved ]switch string (https://forums.alliedmods.net/showthread.php?t=255015)

Freezo Begin 01-09-2015 12:52

[ Solved ]switch string
 
How to ?
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define ADMIN_KICK_RANK "Basic Moderator"
#define ADMIN_BAN_RANK "Co Moderator"

#define GetPlayerBits(%1,%2)    ( %1 &     1 << ( %2 & 31 ) )

new g_Adminrank[20],
    
i_xtrem

public plugin_init() {
        
register_plugin(PLUGINVERSIONAUTHOR)
        
register_clcmd("say test","Just_try")
}
public 
client_connect(id) {
    
    new 
szName[32]
    
get_user_name(id,szName,charsmax(szName))
    if(
GetPlayerBits(id,i_xtrem)){
        
        if(
check_flg(id,ADMIN_KICK)){
            
                
g_Adminrank ADMIN_KICK_RANK

        
}

        else if (
check_flg(id,ADMIN_KICK))
        {
                
g_Adminrank ADMIN_BAN_RANK
        
}
    }
}
public 
Just_try(id){
    
/*
    switch(g_Adminrank){
        case '':
        //  Nothing yet :v
        
    }
    */
}
stock check_flg(idFLAG
{
    return (
get_user_flags(id) & FLAG)



yan1255 01-09-2015 12:57

Re: switch string
 
Please explain more accuratly what do you want...

Freezo Begin 01-09-2015 13:06

Re: switch string
 
how to switch a string value like

PHP Code:

g_Adminrank 

With statement

if(equal(g_Adminrank,"Basic Moderator")){
// Bla bla
}

i wan't to make it in a switch like this
switch(g_Adminrank){
case 'Basic Moderator': // Bla bla

mottzi 01-09-2015 13:11

Re: switch string
 
You can not, as the switch statement only accepts integer values.

Freezo Begin 01-09-2015 13:19

Re: switch string
 
how about doing it with enum ?

RateX 01-09-2015 13:33

Re: switch string
 
How about testing it before asking for help?

Freezo Begin 01-09-2015 13:35

Re: switch string
 
how about shut the fuck up . and don't put a post just for spam or '...' .

RateX 01-09-2015 13:53

Re: switch string
 
Dude, I haven't insulted you in anyway.
If you test it yourself you would have had the result. Should it be a success, you got for yourself a solution. If no, you can post what you have done and others can help you with an appropriate and efficient way to solve your problem. You win in anyway and definitely faster than just waiting for someone to answer your random question.
So stop being a dick and start testing.

Freezo Begin 01-09-2015 16:25

Re: switch string
 
If you wan't to help just post it i will be appreciated . but if its out of the object just leave .
Because you don't help me at all .


Thanks ,

[ Solved using enumeration ] .

fysiks 01-09-2015 18:25

Re: [ Solved ]switch string
 
An enum doesn't satisfy what you are requesting in post #3. However, the best you could do is use a Trie to get an integer (that is associated with the input string) to use in your switch.

Based on the purpose of the code in post #1, you should be using integers or enums anyways. I'm glad you found the answer.

All 'good' scripters try stuff on their own before asking "will this work" unless it's extremely complicated.


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

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