AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   HELP Best way to do (https://forums.alliedmods.net/showthread.php?t=242785)

Toallin 06-24-2014 15:48

HELP Best way to do
 
Good for all.
What happens is I search the best way to do this code
not what you think if you could improve or if they stay well.

PHP Code:

#include <amxmodx>
#include <amxmisc>

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

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /lr""ShowMenuLR")
}

public 
ShowMenuLR(id)
{
    new 
menu menu_create("last request""CmdMenuLR")
    
    
menu_additem(menu"Duel Knife""1")
    
menu_additem(menu"Duel Scouts""2")
    
    
menu_display(idmenu)
}

public 
CmdMenuLR(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED;
    }
    
    switch(
item)
    {
        case 
0ShowListCT(id)
        case 
1ShowListCT(id)
    }
    return 
PLUGIN_HANDLED;
}

public 
ShowListCT(id)
{
    new 
menu menu_create("go to fight""CmdListCT")
    
    new 
iPlayers[32], pnumtempid
    
new iName[32], szTempid[10]
    
    
get_players(iPlayerspnum"aeh""CT")
    
    for(new 
0pnumi++)
    {
        
tempid iPlayers[i]
        
        
get_user_name(tempidiNamecharsmax(iName))
        
num_to_str(tempidszTempidcharsmax(szTempid))
        
menu_additem(menuiNameszTempid)
    }
    
    
menu_display(idmenu)
    return 
PLUGIN_HANDLED;
}

public 
CmdListCT(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), iNamecharsmax(iName), callback)
    
    
// bla bla


The plugin is a menu of modes all have a list of players to fight with each mode is different but not if they could do any better Thank you.

Flick3rR 06-24-2014 15:59

Re: HELP Best way to do
 
Why you switch the item, where all the results are the same?
PHP Code:

    switch(item)
    {
        case 
0ShowListCT(id)
        case 
1ShowListCT(id)
    } 

Doesn't make any sense, just call the function in the handler.
Also you have to put many checks in those functions, because if the guy, who is calling the duel is dead, the duel won't be achieved, right?

Toallin 06-24-2014 19:40

Re: HELP Best way to do
 
understand then only have to call the function 1 time for all options and if the player is not live function not met.
Thanks Flick3rR.

Aprobechando the thread Might help to identify each mode? for example if you choose the knife so you open the menu of players and the player to select the knife so start on these 2 players and if you choose the same mode but scout the scout mode is enabled.

PHP Code:

enum {
    
DUEL_NONE,
    
DUEL_KNIFE,
    
DUEL_SCOUTS



HamletEagle 06-25-2014 05:13

Re: HELP Best way to do
 
You want to know which duel is currently running ? Then, do it with a simple boolean.

PHP Code:

enum _eDuels
{
    
DUEL_NONE,
    
DUEL_SCOUT,
    
DUEL_KNIFE

}

new 
boolIsDuel eDuels 

When he choose knife duel:
PHP Code:

IsDuel DUEL_NONE   ] = false
IsDuel 
DUEL_SCOUT  ] = false
IsDuel 
DUEL_KNIFE  ] = true 

When he choose a scout duel:
PHP Code:

IsDuel DUEL_NONE   ] = false
IsDuel 
DUEL_SCOUT  ] = true
IsDuel 
DUEL_KNIFE  ] = false 

When a duel ends:
PHP Code:

IsDuel DUEL_NONE   ] = true
IsDuel 
DUEL_SCOUT  ] = false
IsDuel 
DUEL_KNIFE  ] = false 

When you give weapons or sth like this, just check which bool is true.

PHP Code:

if ( ! IsDuel DUEL_NONE ] ) {

    if ( 
IsDuel DUEL_SCOUT ] ) {
        
//we have a scout duel
        
        
    
}   
    
    if ( 
IsDuel DUEL_KNIFE ] ){
       
//we have a knife duel
    
    
    
}


I don't know what you want to do with duel_none, but based on your previous example, this is how you should do it, whatever it is.

GuskiS 06-25-2014 06:00

Re: HELP Best way to do
 
Quote:

Originally Posted by HamletEagle (Post 2157024)
You want to know which duel is currently running ? Then, do it with a simple boolean.

PHP Code:

enum _eDuels
{
    
DUEL_NONE,
    
DUEL_SCOUT,
    
DUEL_KNIFE

}

new 
boolIsDuel eDuels 

When he choose knife duel:
PHP Code:

IsDuel DUEL_NONE   ] = false
IsDuel 
DUEL_SCOUT  ] = false
IsDuel 
DUEL_KNIFE  ] = true 

When he choose a scout duel:
PHP Code:

IsDuel DUEL_NONE   ] = false
IsDuel 
DUEL_SCOUT  ] = true
IsDuel 
DUEL_KNIFE  ] = false 

When a duel ends:
PHP Code:

IsDuel DUEL_NONE   ] = true
IsDuel 
DUEL_SCOUT  ] = false
IsDuel 
DUEL_KNIFE  ] = false 

When you give weapons or sth like this, just check which bool is true.

PHP Code:

if ( ! IsDuel DUEL_NONE ] ) {

    if ( 
IsDuel DUEL_SCOUT ] ) {
        
//we have a scout duel
        
        
    
}   
    
    if ( 
IsDuel DUEL_KNIFE ] ){
       
//we have a knife duel
    
    
    
}


I don't know what you want to do with duel_none, but based on your previous example, this is how you should do it, whatever it is.

Stupid and wrong.
PHP Code:

enum _eDuels
{
    
DUEL_NONE,
    
DUEL_SCOUT,
    
DUEL_KNIFE

}

new 
IsDuel;

// when you need, set duel
IsDuel DUEL_SCOUT;

// when you need, check duel
if(IsDuel == DUEL_SCOUT


HamletEagle 06-25-2014 06:41

Re: HELP Best way to do
 
Quote:

Originally Posted by GuskiS (Post 2157037)
Stupid and wrong.
PHP Code:

enum _eDuels
{
    
DUEL_NONE,
    
DUEL_SCOUT,
    
DUEL_KNIFE

}

new 
IsDuel;

// when you need, set duel
IsDuel DUEL_SCOUT;

// when you need, check duel
if(IsDuel == DUEL_SCOUT


It's not stupid and it's not wrong. May not be what he wanted, cause I didn't understand his post.

ironskillz1 06-25-2014 06:48

Re: HELP Best way to do
 
Just look on a approved last request code on alliedmodders.
It will show you how to do it the best way

Toallin 06-25-2014 12:23

Re: HELP Best way to do
 
is that by choosing any option opens the menu to choose to play with
I was looking knife selecting mode by selecting the player to play with the knife mode is activated by selecting scout mode equals.

GuskiS 06-25-2014 13:38

Re: HELP Best way to do
 
Quote:

Originally Posted by HamletEagle (Post 2157049)
It's not stupid and it's not wrong. May not be what he wanted, cause I didn't understand his post.

How is that right? Allocating more memory then you need is right? Then doing those things x times?


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

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