Raised This Month: $32 Target: $400
 8% 

how to use for loop in switch?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 07-19-2018 , 09:29   how to use for loop in switch?
Reply With Quote #1

Hello, I've made this script so far.

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "PM Message"
#define VERSION "1.0"
#define AUTHOR "Reddington"

new menu;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /pm""SendMessage");
}

public 
SendMessageid )
{
    new 
playerOnline ConnectedPeople();
    
menu menu_create("\ySelect a person to send message to""sendmessage_handler");
    for(new 
1playerOnline 1x++)
    {
        new 
name[70]; new msg[255];
        
get_user_name(xnamesizeof(name));
        
format(msgsizeof(msg), "%s"name);
        
menu_additem(menumsg"player"0);
    }
    
menu_display(idmenu0);
    return 
PLUGIN_HANDLED;
}

public 
sendmessage_handler(idmenuitem)
{
    new 
playerOnline ConnectedPeople();
    switch( 
item )
    {    
           for(new 
1playerOnline++) //Here's an error.. i thought i could do something like this.. it doesn't work.. help here.
           
{
                case 
x:
                {
                          
                }
           }

        
    }
    return 
1;
}

ConnectedPeople()
{
    new 
connectedPeople;
    for(new 
133x++)
    {
        if(
is_user_connected(x))
        {
            
connectedPeople++
        }
    }
    return 
connectedPeople;

Can you tell me how am I supposed to perfom some action according to their ID's when I select for example one player from the menu? I can't do anything, because if I try to use FOR loop then it says error. Any suggestions?

Last edited by LemoNSK; 07-19-2018 at 10:29.
LemoNSK is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 07-19-2018 , 09:44   Re: how to use for loop in switch?
Reply With Quote #2

What kind of help do you need ? Because most of this code is really bad, maybe you should brush up on some basic pawn tutorials, no offense

Anyway, you can't create a player menu without passing the uid for example, more info here https://forums.alliedmods.net/showthread.php?t=46364

Syntax for the switch in pawn is:
Code:
switch( condition ) {
    case 0: {
        // do something    
    }
    case 1: {
        // do something   
    }
    default: {
        // do something
    }
}
Also, a proper place for this is the Scripting Help section, just so u know in the future.
__________________
stuff

Last edited by maqi; 07-19-2018 at 09:46.
maqi is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 07-19-2018 , 10:25   Re: how to use for loop in switch?
Reply With Quote #3

Quote:
Originally Posted by maqi View Post
What kind of help do you need ? Because most of this code is really bad, maybe you should brush up on some basic pawn tutorials, no offense

Anyway, you can't create a player menu without passing the uid for example, more info here https://forums.alliedmods.net/showthread.php?t=46364

Syntax for the switch in pawn is:
Code:
switch( condition ) {
    case 0: {
        // do something    
    }
    case 1: {
        // do something   
    }
    default: {
        // do something
    }
}
Also, a proper place for this is the Scripting Help section, just so u know in the future.
I know about this, mate.. Look inside my code and properly.. I wanted to answer a question whether it is possible to for loop inside the switch because it says me error. As you can see, I tried to write all the players connected to the server in the menu, that works.. but If I click on the certain player after they've been loaded in menu, it should do some function according to the player's id.. but I can't for loop inside so I can't continue on...

PS: I've been programming in PHP and HTML,CSS for a long time.. that's why I almost forgot everything.

Last edited by LemoNSK; 07-19-2018 at 10:26.
LemoNSK is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 07-19-2018 , 10:32   Re: how to use for loop in switch?
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?t=46364
You'll find a lot of information here about how stuff are done the proper way.
__________________
Relaxing is offline
LemoNSK
Member
Join Date: Jul 2018
Location: Criminal Underworld
Old 07-19-2018 , 10:36   Re: how to use for loop in switch?
Reply With Quote #5

Quote:
Originally Posted by Relaxing View Post
https://forums.alliedmods.net/showthread.php?t=46364
You'll find a lot of information here about how stuff are done the proper way.
Alright, thank you. I'll look into it.

Edit: This is what I was asking. Thank you.

Last edited by LemoNSK; 07-19-2018 at 10:38.
LemoNSK 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 18:55.


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