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

[ANY] Singular and Plural


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 02-19-2017 , 09:15   [ANY] Singular and Plural
Reply With Quote #1

I've seen lots of if statements because of this very problem. Here is an easy solution:


PHP Code:
int coins 10;
PrintToChat(client"You have %i Coin%s"coinscoins==1?"":"s"); 
__________________
Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...

Last edited by Totenfluch; 02-19-2017 at 09:15.
Totenfluch is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 02-19-2017 , 14:14   Re: [ANY] Singular and Plural
Reply With Quote #2

For anyone interested in learning more on how to use this in other situations it is called a ternary operator:

https://en.wikipedia.org/wiki/%3F:#Usage
Addicted. is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 02-19-2017 , 15:02   Re: [ANY] Singular and Plural
Reply With Quote #3

I love ternary operators. My recent discovery of how they work (the ternary operator being the ? symbol) has given me so many ways compressing small if statements like the one Totenfluch provided.

404UserNotFound is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 02-19-2017 , 15:04   Re: [ANY] Singular and Plural
Reply With Quote #4

Code:
//  Evaluates to a string of the ordinal suffix of a number (1st, 2nd, 3rd, etc)
#define NatSuf(%1)               ((%1 + 9) % 10 >= 3 || (%1 + 89) % 100 < 3 ? "th" : (%1 % 10) == 1 ? "st" : (%1 % 10) == 2 ? "nd" : "rd")
__________________

Last edited by Chdata; 02-19-2017 at 15:04.
Chdata is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 02-19-2017 , 17:38   Re: [ANY] Singular and Plural
Reply With Quote #5

Quote:
Originally Posted by Chdata View Post
Code:
//  Evaluates to a string of the ordinal suffix of a number (1st, 2nd, 3rd, etc)
#define NatSuf(%1)               ((%1 + 9) % 10 >= 3 || (%1 + 89) % 100 < 3 ? "th" : (%1 % 10) == 1 ? "st" : (%1 % 10) == 2 ? "nd" : "rd")
Woah. Are you a wizard?

Also, I challenge you to break the all down part by part and explain what each thing means and does
404UserNotFound is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 02-19-2017 , 19:52   Re: [ANY] Singular and Plural
Reply With Quote #6

Quote:
Originally Posted by Chdata View Post
Code:
//  Evaluates to a string of the ordinal suffix of a number (1st, 2nd, 3rd, etc)
#define NatSuf(%1)               ((%1 + 9) % 10 >= 3 || (%1 + 89) % 100 < 3 ? "th" : (%1 % 10) == 1 ? "st" : (%1 % 10) == 2 ? "nd" : "rd")
Ah yes, the 0th

Instead of going into macro, modulo, and ternary hell, try something untested like this:
PHP Code:
static stock NatStuf(number)
{
    static const 
String:InternalPrefix[][] = {"""st""nd""rd""th"};
    new 
mod = (number 10);
    if (
mod 3)
        
mod = (sizeof(InternalPrefix) - 1);
    
    return 
_:InternalPrefix[mod];

KyleS is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 02-20-2017 , 18:06   Re: [ANY] Singular and Plural
Reply With Quote #7

Ternary operators are usefull but can make code difficult to read.
__________________
Neuro Toxin is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-20-2017 , 20:13   Re: [ANY] Singular and Plural
Reply With Quote #8

You can make a translations phrase for single and plural.
Not all languages express plural the same
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-20-2017 , 20:22   Re: [ANY] Singular and Plural
Reply With Quote #9

Quote:
Originally Posted by friagram View Post
You can make a translations phrase for single and plural.
Not all languages express plural the same
Nor are all languages consistent with how words are pluralized, including English. Ex. "s" versus "es", not to mention English words that have origins in other languages.
psychonic is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 02-25-2017 , 13:34   Re: [ANY] Singular and Plural
Reply With Quote #10

It was funny when I made a bool for gender

And then realized that army tanks are an "it".
__________________
Chdata 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 09:51.


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