G.STNDRD

From GMod Wiki

Revision as of 13:13, 10 May 2011 by Donkie (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax STNDRD( Number number )
Where is this used?
Description:
Returns the proper suffix for a number between 0 and 20.
Returns: String st nd rd th
Part of Library: Global Functions
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.STNDRD]G.STNDRD [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionDisplays a player's rank.
Used onNewerServer.png
Code
PrintMessage( HUD_PRINTTALK, string.format( "%s is in %d%s place!", Player(2):Name(), Player(2).Rank, STNDRD( Player(2).Rank) )
OutputMingeBag is in 2nd place!


Implementation

function STNDRD( num )
 
	if ( num == 1 ) then return "st" end
	if ( num == 2 ) then return "nd" end
	if ( num == 3 ) then return "rd" end
 
	return "th"
 
end

Fix

function STNDRD( num )
	if ( num > 3 and num < 21 ) then return "th"
 
	local n = num % 10
	elseif ( n == 1 ) then return "st"
	elseif ( n == 2 ) then return "nd"
	elseif ( n == 3 ) then return "rd" end
	return "th"
end

Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox