Template:Server client function: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Removed redirect to Template:Shared function)
Tag: Removed redirect
(Undo revision 78887 by RubyCommunity (talk))
Tags: New redirect Undo
 
Line 1: Line 1:
{{Useful Function}}
#REDIRECT [[Template:Shared function]]
<lowercasetitle></lowercasetitle>
__NOTOC__
This function returns a fixed sorted bilingual RTL for strings consisting of Persian/Arabic and English.
 
just copy & paste and see the magic ;D
 
==Syntax==
<syntaxhighlight lang="lua">str fixPersianString ( string text )</syntaxhighlight>
 
===Required Arguments===
* '''text''': The bilingual string.
 
===Returns===
Returns a fixed string .
 
==Code==
{{RequiredFunctions|Check}}
<section name="Server/Client side Script" class="both" show="true">
<syntaxhighlight lang="lua">
function fixPersianString(str)
    if type(str) ~= 'string' then
        error("bad argument at argument 1 got "..type(str)..", use string or call tostring")
    end
        local function reverseEN(word)
            return word:gsub("(%w+)", function(w) return w:reverse() end)
        end
    return ('‮'..str:gsub("%f[%a]%w+%f[%A]", reverseEN))
end
 
</syntaxhighlight>
</section>
 
==Example==
<section name="client" class="client" show="true">
This example print a message with persian and english words without any problem
<syntaxhighlight lang="lua">
local PersianSTR = fixPersianString("خب اینطوری به نظرم behtar شد و دیگه کلمات باهمدیگه قاطی نمیشن goodluck وقت بخیر ")
local screenWidth, screenHeight = guiGetScreenSize ( )
addEventHandler ( "onClientRender", root, function ()
    dxDrawText ( PersianSTR, 200, screenHeight - 500, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 3, "default-bold" )
end)
print(PersianSTR)
outputChatBox (PersianSTR)
</syntaxhighlight>
</section>
 
Author: RubyCommunity
 
==See Also==
{{Useful_Functions}}

Latest revision as of 18:47, 13 March 2024