Raised This Month: $51 Target: $400
 12% 

Suggestion for SM


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 04-08-2015 , 18:04   Suggestion for SM
Reply With Quote #1

Hi,

would like to suggest that the AddMenuItems natives support format specifiers.

example:
PHP Code:
AddMenuItem(Handle:menu,const String:info[],const String:display[],any:...); 
It wouldnt break the compatibility with previous versions.

xerox8521 is offline
Bara
AlliedModders Donor
Join Date: Apr 2012
Location: Germany
Old 04-08-2015 , 18:51   Re: Suggestion for SM
Reply With Quote #2

Code:
stock bool:AddMenuItemEx(Handle:menu, style, String:info[], String:display[], any:...)
{
	decl String:m_display[256];
	VFormat(m_display, sizeof(m_display), display, 5);
	return (AddMenuItem(menu, info, m_display, style)?true:false);
}
__________________
Discord (Bara#5006) | My Plugins (GitHub)
You like my work? Support is not a crime.
Bara is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 04-08-2015 , 18:58   Re: Suggestion for SM
Reply With Quote #3

The ternary return is pointless.
__________________

Last edited by Impact123; 04-08-2015 at 19:02.
Impact123 is offline
Bara
AlliedModders Donor
Join Date: Apr 2012
Location: Germany
Old 04-08-2015 , 19:02   Re: Suggestion for SM
Reply With Quote #4

Snippet isn't from me.
https://www.dropbox.com/s/cuen066k5v80qjj/gangs.zip (gangs\source\core\include\basestock.inc)
__________________
Discord (Bara#5006) | My Plugins (GitHub)
You like my work? Support is not a crime.
Bara is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-08-2015 , 19:53   Re: Suggestion for SM
Reply With Quote #5

This probably hasn't already been added (and is kind of useless) because you could as well want to format the info string (multiply "any"s aren't possible), and also you will probably want to have multiple items and therefore would continue reallocating and freeing (the same) space for each call. If you want it, use it, if you want it to be added to sm, PRs welcome I guess, I doubt it will be added though due to the aforementioned points.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-08-2015 , 20:11   Re: Suggestion for SM
Reply With Quote #6

If you want to do translation phrases for menus, the MenuAction_DisplayItem callback exists for this reason.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 04-09-2015 , 08:54   Re: Suggestion for SM
Reply With Quote #7

Quote:
Originally Posted by Impact123 View Post
... ternary ...
Thank you for this - now I know the proper term for this operation that I've used a few times... LoL

Have you ever used multiple ternary evaluations in SM plugins?

PHP Code:
bool firstCheck false,
bool secondCheck false,
char access[] = firstCheck "Access denied" secondCheck "Access denied" "Access granted";
  
PrintToServer(access); // Prints "Access granted" 
Or, more than on single operation separated by a comma?
__________________
View my Plugins | Donate

Last edited by TnTSCS; 04-09-2015 at 08:58.
TnTSCS is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 04-09-2015 , 09:06   Re: Suggestion for SM
Reply With Quote #8

I do multiple ternaries sometimes. Just read it left to right.

firstcheck ? true = do this : else trythischeck ? true = do this : else do this
__________________
Chdata is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 04-09-2015 , 09:42   Re: Suggestion for SM
Reply With Quote #9

@TnTSCS
No. I tend to change my mind on how code should be formatted over time, but I always though that doing this greatly hinders the readability of code.
I understand that your code is a simple example, but you could avoid the stacking by writing the code like this.
PHP Code:
char access[] = (firstCheck || secondCheck) ? "Access denied" "Access granted"
__________________

Last edited by Impact123; 04-09-2015 at 10:28.
Impact123 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 04-12-2015 , 08:27   Re: Suggestion for SM
Reply With Quote #10

Quote:
Originally Posted by TnTSCS View Post
Thank you for this - now I know the proper term for this operation that I've used a few times... LoL

Have you ever used multiple ternary evaluations in SM plugins?
I guess its proper name is the Conditional Operator. Ternary is just an adjective to say it takes three operands, in the same way that +/-/* are binary and ++/-- are unary.

Granted that SourcePawn only has one ternary operator I can think of though...

Resize Players has about 19 of these operators, the most basic being the GetMax function:
PHP Code:
GetMax(const iValA, const iValB)
{
  return (
iValA iValB iValB iValA);

__________________
11530 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 12:29.


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