Raised This Month: $ Target: $400
 0% 

Can anyone check if there is a better way to do this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alahmoh
Member
Join Date: Jun 2018
Old 08-07-2022 , 16:26   Can anyone check if there is a better way to do this?
Reply With Quote #1

Code:
public plugin_init( ) {
register_menucmd(register_menuid("Show_HudMenu")(1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_HudMenu");
}
ShowHud( player ) {
		new R,G,B,X,Y;
		
		
		if( g_iUserStatus[ player ] == 1 ) {
			X = 0.02;
			Y = 0.158;
			R = 0;
			G = 255;
			B = 255;
		}
		
		if( g_iHudLcr[ player ] == 1 ) {
			X = 0.02;
		}else if( g_iHudLcr[ player ] == 2 ) {
			X = 0.30;
		}else if( g_iHudLcr[ player ] == 3 ) {
			X = 1.0;
		}
		if( g_iUserColor[ player ] == 1 ) {
			R = 0;
			G = 255;
			B = 255;
		}else if( g_iUserColor[ player ] == 2 ) {
			R = 255;
			G = 0;
			B = 0;
		}else if( g_iUserColor[ player ] == 3 ) {
			R = 0;
			G = 255;
			B = 0;
		}else if( g_iUserColor[ player ] == 4 ) {
			R = 210;
			G = 180;
			B = 140;
		}else if( g_iUserColor[ player ] == 5 ) {
			R = 255;
			G = 20;
			B = 147;
		}else if( g_iUserColor[ player ] == 6 ) {
			R = 255;
			G = 140;
			B = 0;
		}else if( g_iUserColor[ player ] == 7 ) {
			R = 75;
			G = 0;
			B = 130;
		}
			
			
		if( g_iHudUcd[ player ] == 1 ) {
			Y = 0.158;
		}else if( g_iHudUcd[ player ] == 2 ) {
			Y = 0.50;
		}else if( g_iHudUcd[ player ] == 3 ) {
			Y = 1.0;
		}

		set_hudmessage( R, G, B, is_user_alive( player ) ? X : 0.6, is_user_alive( player ) ? Y : 0.5, 0, 6.0, 0.1 );
}

public Show_HudMenu( player ) {
	new szText[ 64 ], iKeys = (1<<0|1<<9);
	formatex( szText, charsmax( szText ), "\r%L", iPlayer, "ML_HUDMENU" );

	new iMenu = menu_create( szText, "Handle_HudMenu" );
	formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, g_szHudCN[g_iUserStatus[ player ]][1] );
	menu_additem( iMenu, szText );
		
	if(g_iUserStatus[ player ]) {
		formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, g_szHudMenu[g_iUserColor[ player ]][1] );
		menu_additem( iMenu, szText );
		
		formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, g_szHudMenuLcr[g_iHudLcr[ player ]][1] );
		menu_additem( iMenu, szText );
		
		formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, g_szHudMenuUcd[g_iHudUcd[ player ]][1] );
		menu_additem( iMenu, szText );
		iKeys |= (1<<1|1<<2|1<<3|1<<4);
	}else { 
		formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, "ML_LOCKED" );
		menu_additem( iMenu, szText );
		
		formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, "ML_LOCKED" );
		menu_additem( iMenu, szText );
		
		formatex( szText, charsmax( szText ), "%L %L", player, "ML_HUDPREFIX", player, "ML_LOCKED" );
		menu_additem( iMenu, szText );
	}
	
	formatex( szText, charsmax( szText ), "%L", player, "ML_DEFAULT" );
	menu_additem( iMenu, szText );
	
	formatex( szText, charsmax( szText ), "%L", player, "ML_SAVE" );
	menu_additem( iMenu, szText );
	
	menu_display( player, iMenu );
}

public Handle_HudMenu( player, iMenu, iItem ) {
	client_cmd( player, "spk select" );
	
	if( iItem == MENU_EXIT ) {
		menu_destroy( iMenu );
		return PLUGIN_CONTINUE;
	}
	
	switch( iItem ) {
		case 0: g_iUserStatus[ player ] = !g_iUserStatus[ player ];
		
		case 1: if((sizeof(g_szHudMenu) - 1) <= g_iUserColor[ player ]) g_iUserColor[ player ] = 1;
			else if(g_iUserStatus[ player ]) {
				g_iUserColor[ player ]++;
			}else return Show_HudMenu(iPlayer);
			
		case 2: if((sizeof(g_szHudMenuLcr) - 1) <= g_iHudLcr[ player ]) g_iHudLcr[ player ] = 1;
			else if(g_iUserStatus[ iPlayer ]) {
				g_iHudLcr[ player ]++;
			}else return Show_HudMenu(iPlayer);
			
		case 3: if((sizeof(g_szHudMenuUcd) - 1) <= g_iHudUcd[ player ]) g_iHudUcd[ player ] = 1;
			else if(g_iUserStatus[ player ]) {
				g_iHudUcd[ player ]++;
			}else return Show_HudMenu(player);
		
		case 4: {
			g_iHudUcd[ player ] = 1;
			g_iHudLcr[ player ] = 1;
			g_iUserColor[ player ] = 1;
			
			ColorChat( player,NORMAL, "!g[CoD:Mw] !n%L", player, "ML_BACK_TO_DEFAULT" );
		}

		case 5: {
			SaveHud( player );
			
			ColorChat( iPlayer, NORMAL,"!g[CoD:Mw] !n%L", player, "ML_SAVED" );
		}
	}
	
	return Show_HudMenu(player);
}
it works perfectly fine but when i compile i get like 17 warnings.
so i wonder if there is a better way to get the same results without getting 17 warnings?

Last edited by Alahmoh; 08-07-2022 at 16:30.
Alahmoh is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-07-2022 , 16:45   Re: Can anyone check if there is a better way to do this?
Reply With Quote #2

You should post the full plugin so that we can easily test it since you didn't provide any information about the warnings. The easier you make it for us, the more likely you'll get a quick answer.
__________________
fysiks is offline
Alahmoh
Member
Join Date: Jun 2018
Old 08-07-2022 , 17:00   Re: Can anyone check if there is a better way to do this?
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
You should post the full plugin so that we can easily test it since you didn't provide any information about the warnings. The easier you make it for us, the more likely you'll get a quick answer.
the plugin is private, thou i will post the required natives to make it work.
Code:
#define Struct				enum

Struct _:StructIntPlayerInfo {	
	g_iHudSaved
}

new g_iPlayerInfo[ 33 ][ StructIntPlayerInfo ];

new g_iUserStatus[33],g_iUserColor[33],g_iHudLcr[33],g_iHudUcd[33];

new const g_szHudCN[ ][ ] = {
	"ML_NORMAL",
	"ML_CUSTOME"
};

new const g_szHudMenu[ ][ ] = {
	"ML_NORMAL",
	"ML_CYAN",
	"ML_RED",
	"ML_GREEN",
	"ML_TAN",
	"ML_PINK",
	"ML_ORANGE",
	"ML_PURPLE"
};

new const g_szHudMenuLcr[ ][ ] = {
	"ML_NORMAL",
	"ML_LEFT",
	"ML_CENTRE",
	"ML_RIGHT"
};

new const g_szHudMenuUcd[ ][ ] = {
	"ML_NORMAL",
	"ML_UP",
	"ML_CENTREE",
	"ML_DOWN"
};

public SaveHud( iPlayer ) {
	if( is_user_bot( iPlayer ) )
		return;
		
	new szKey[ 96 ], szData[ 96 ];
	formatex( szKey, charsmax( szKey ), "%s", g_szPlayerInfo[ iPlayer ][ g_szSteamID ] );
	formatex( szData, charsmax( szData ), "%i %i %i", g_iUserColor[ iPlayer ], g_iHudLcr[ iPlayer ], g_iHudUcd[ iPlayer ] );
		
	nvault_set( g_iVault, szKey, szData );
	
	g_szPlayerInfo[ iPlayer ][g_iHudSaved] = 1;
}
	
public LoadHud( iPlayer ) {
	if( is_user_bot( iPlayer ) )
		return;
		
	new szKey[ 96 ], szData[ 96 ], szDataPieces[ 6 ][ 10 ];
	formatex( szKey, charsmax( szKey ), "%s", g_szPlayerInfo[ iPlayer ][ g_szSteamID ] );
	nvault_get( g_iVault, szKey, szData, charsmax( szData ) );
		
	parse( szData, szDataPieces[ 0 ], charsmax( szDataPieces[ ] ), szDataPieces[ 1 ], charsmax( szDataPieces[ ] ), szDataPieces[ 2 ], charsmax( szDataPieces[ ] ) );
		
	g_iUserColor[ iPlayer ] = str_to_num( szDataPieces[ 0 ] );
	g_iHudLcr[ iPlayer ] =  str_to_num( szDataPieces[ 1 ] );
	g_iHudUcd[ iPlayer ] = str_to_num( szDataPieces[ 2 ] );
}
btw you dont need to test it because it works perfectly i only want to get rid of warnings.

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Warning: Tag mismatch on line 641
Warning: Tag mismatch on line 642
Warning: Tag mismatch on line 649
Warning: Tag mismatch on line 651
Warning: Tag mismatch on line 653
Warning: Tag mismatch on line 687
Warning: Tag mismatch on line 689
Warning: Tag mismatch on line 691
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 1394
Warning: Function "ChooseTeam" should return a value on line 2096
Warning: Function "Show_HudMenu" should return a value on line 2631
Warning: Function "Show_HudMenu" should return a value on line 2636
Warning: Function "Show_HudMenu" should return a value on line 2641
Warning: Function "Show_HudMenu" should return a value on line 2658
Header size: 6688 bytes
Code size: 120912 bytes
Data size: 405420 bytes
Stack/heap size: 16384 bytes; max. usage is unknown, due to recursion
Total requirements: 549404 bytes

18 Warnings.
Done.
Alahmoh is offline
Alahmoh
Member
Join Date: Jun 2018
Old 08-07-2022 , 17:05   Re: Can anyone check if there is a better way to do this?
Reply With Quote #4

btw the Warning: Tag mismatch on line.
happens on the lines of
X = something;
Y = something;

even thou if i make it two == it stops sends warning, it will make the plugin not work.

Last edited by Alahmoh; 08-07-2022 at 17:06.
Alahmoh is offline
lexzor
Senior Member
Join Date: Nov 2020
Old 08-08-2022 , 05:57   Re: Can anyone check if there is a better way to do this?
Reply With Quote #5

some changes i will do
PHP Code:
switch(g_iUserColor[player])
{
    case 
1:
    {
        
0;
        
255;
        
255;
    }

    case 
2:
    {
        
255;
        
0;
        
0;
    }

    
//and so on..

PHP Code:
formatexszTextcharsmaxszText ), "%L %L"player"ML_HUDPREFIX"playerg_szHudMenu[g_iUserColorplayer ]][1] ); 
to

PHP Code:
formatexszTextcharsmaxszText ), "%l %l""ML_HUDPREFIX"g_szHudMenu[g_iUserColorplayer ]][1] ); 
PHP Code:
nvault_getg_iVaultszKeyszDatacharsmaxszData ) );
        
    
parseszDataszDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ) );
        
    
g_iUserColoriPlayer ] = str_to_numszDataPieces] );
    
g_iHudLcriPlayer ] =  str_to_numszDataPieces] );
    
g_iHudUcdiPlayer ] = str_to_numszDataPieces] ); 
to

PHP Code:
new iTs;
    if(
nvault_lookup(g_iVaultszKeyszDatacharsmax(szData), iTs))
    {
        
parseszDataszDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ) );
        
g_iUserColoriPlayer ] = str_to_numszDataPieces] );
        
g_iHudLcriPlayer ] =  str_to_numszDataPieces] );
        
g_iHudUcdiPlayer ] = str_to_numszDataPieces] );
    } 
PHP Code:
menu_displayplayeriMenu ); 
to
PHP Code:
if(is_user_connected(id))
      
menu_displayplayeriMenu ); 
you don t need these if you are using new menus
PHP Code:
register_menucmd(register_menuid("Show_HudMenu")(1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_HudMenu");

iKeys |= (1<<1|1<<2|1<<3|1<<4); 
and
PHP Code:
new R,G,B,X,Y
should be declared as static

PHP Code:
static R,G,B,X,Y
Code:
Warning: Function "ChooseTeam" should return a value on line 2096
Warning: Function "Show_HudMenu" should return a value on line 2631
Warning: Function "Show_HudMenu" should return a value on line 2636
Warning: Function "Show_HudMenu" should return a value on line 2641
Warning: Function "Show_HudMenu" should return a value on line 2658
just add a return value at the end of the function

Code:
Warning: Tag mismatch on line 641
Warning: Tag mismatch on line 642
Warning: Tag mismatch on line 649
Warning: Tag mismatch on line 651
Warning: Tag mismatch on line 653
Warning: Tag mismatch on line 687
Warning: Tag mismatch on line 689
Warning: Tag mismatch on line 691
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 1394
this error appears when you give a variable a different type of value than the purpose in which the variable was created
example

you have a boolean variabile but you store in that variabile a int number
lexzor is offline
Alahmoh
Member
Join Date: Jun 2018
Old 08-08-2022 , 11:08   Re: Can anyone check if there is a better way to do this?
Reply With Quote #6

Quote:
Originally Posted by lexzor View Post
some changes i will do
PHP Code:
switch(g_iUserColor[player])
{
    case 
1:
    {
        
0;
        
255;
        
255;
    }

    case 
2:
    {
        
255;
        
0;
        
0;
    }

    
//and so on..

PHP Code:
formatexszTextcharsmaxszText ), "%L %L"player"ML_HUDPREFIX"playerg_szHudMenu[g_iUserColorplayer ]][1] ); 
to

PHP Code:
formatexszTextcharsmaxszText ), "%l %l""ML_HUDPREFIX"g_szHudMenu[g_iUserColorplayer ]][1] ); 
PHP Code:
nvault_getg_iVaultszKeyszDatacharsmaxszData ) );
        
    
parseszDataszDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ) );
        
    
g_iUserColoriPlayer ] = str_to_numszDataPieces] );
    
g_iHudLcriPlayer ] =  str_to_numszDataPieces] );
    
g_iHudUcdiPlayer ] = str_to_numszDataPieces] ); 
to

PHP Code:
new iTs;
    if(
nvault_lookup(g_iVaultszKeyszDatacharsmax(szData), iTs))
    {
        
parseszDataszDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ), szDataPieces], charsmaxszDataPieces[ ] ) );
        
g_iUserColoriPlayer ] = str_to_numszDataPieces] );
        
g_iHudLcriPlayer ] =  str_to_numszDataPieces] );
        
g_iHudUcdiPlayer ] = str_to_numszDataPieces] );
    } 
PHP Code:
menu_displayplayeriMenu ); 
to
PHP Code:
if(is_user_connected(id))
      
menu_displayplayeriMenu ); 
you don t need these if you are using new menus
PHP Code:
register_menucmd(register_menuid("Show_HudMenu")(1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_HudMenu");

iKeys |= (1<<1|1<<2|1<<3|1<<4); 
and
PHP Code:
new R,G,B,X,Y
should be declared as static

PHP Code:
static R,G,B,X,Y
Code:
Warning: Function "ChooseTeam" should return a value on line 2096
Warning: Function "Show_HudMenu" should return a value on line 2631
Warning: Function "Show_HudMenu" should return a value on line 2636
Warning: Function "Show_HudMenu" should return a value on line 2641
Warning: Function "Show_HudMenu" should return a value on line 2658
just add a return value at the end of the function

Code:
Warning: Tag mismatch on line 641
Warning: Tag mismatch on line 642
Warning: Tag mismatch on line 649
Warning: Tag mismatch on line 651
Warning: Tag mismatch on line 653
Warning: Tag mismatch on line 687
Warning: Tag mismatch on line 689
Warning: Tag mismatch on line 691
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 695
Warning: Tag mismatch on line 1394
this error appears when you give a variable a different type of value than the purpose in which the variable was created
example

you have a boolean variabile but you store in that variabile a int number
thanks for the help, its just i removed the warnings by simply making X,Y floats cuz they store int.
and for the other warnings i just removed the return. and all the warnings got removed still thanks for your help because when you told me static i knew that numbers should be stored to float variable.
Alahmoh is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-08-2022 , 22:45   Re: Can anyone check if there is a better way to do this?
Reply With Quote #7

Declaring those variables as static is not required at all. It is a trivial optimization that will not make any appreciable difference any in regard. The two exceptions are very large arrays or for large/many variables that are called very often (like on a think forward).

Quote:
Originally Posted by Alahmoh View Post
the plugin is private ... btw you dont need to test it because it works perfectly i only want to get rid of warnings.
I understand that some people don't want to post their whole plugin but if people do post it it makes it much easier for us to compile it ourselves to see the actual warnings. It's not always easy to see errors/warnings by scanning random source code.

So, having the errors/warnings along with the corresponding lines of code is important to make things easier and quicker for everybody.

In the event that you're wanting to only post a little code, it is helpful to post the code snippets with call outs to indicate the line numbers. One nice and easy way to do this is to post your code in [php][/php] tags (to get syntax highlighting) and then add a comment on the lines that have errors. For example:

[php]
ShowHud( player ) {
new R,G,B,X,Y; // Line 1394
[/php]

gives this:
PHP Code:
ShowHudplayer ) {
        new 
R,G,B,X,Y// Line 1394 
__________________
fysiks is offline
Alahmoh
Member
Join Date: Jun 2018
Old 08-09-2022 , 03:11   Re: Can anyone check if there is a better way to do this?
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
Declaring those variables as static is not required at all. It is a trivial optimization that will not make any appreciable difference any in regard. The two exceptions are very large arrays or for large/many variables that are called very often (like on a think forward).



I understand that some people don't want to post their whole plugin but if people do post it it makes it much easier for us to compile it ourselves to see the actual warnings. It's not always easy to see errors/warnings by scanning random source code.

So, having the errors/warnings along with the corresponding lines of code is important to make things easier and quicker for everybody.

In the event that you're wanting to only post a little code, it is helpful to post the code snippets with call outs to indicate the line numbers. One nice and easy way to do this is to post your code in [php][/php] tags (to get syntax highlighting) and then add a comment on the lines that have errors. For example:

[php]
ShowHud( player ) {
new R,G,B,X,Y; // Line 1394
[/php]

gives this:
PHP Code:
ShowHudplayer ) {
        new 
R,G,B,X,Y// Line 1394 
thanks for the advice, again.
Alahmoh is offline
Reply


Thread Tools
Display Modes

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:16.


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