Jump to content

How to shorten a string?


Recommended Posts

Posted

Hello, I want to shorten a string like, if one string (nickname from player) is too long, shorten it.

Like this:

-> original string: Nickname

-> remove it untill it is only 4 length.

-> returns Nick

Posted
One way is to split it in letters then create a new variable which will contain the four chars in a string

The function is here https://wiki.multitheftauto.com/wiki/RemoveHex

NOT CREATED BY ME

I think you need to read his question again.

RemoveHex(created By me) : This function is used to remove hex color codes from strings.

Hello, I want to shorten a string like, if one string (nickname from player) is too long, shorten it.

Like this:

-> original string: Nickname

-> remove it untill it is only 4 length.

-> returns Nick

All what you need string.len

if (string.len (name) > 4) then 
    -- change the player name  
end 

For more information about strings check my tuto Lua Strings

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

Generally to shorten a string, you should use string.sub

e.g:

  
local myString = "Nickname" 
  
outputChatBox( string.sub(myString, 1, 4) ) -- Returns 'Nick' 
  

Number 1 in there indicates where you want to shorten the string from, in case it's from N ( Nickname )

and Number 4 indicates where to you want to shorten the string, in this case to k ( Nickname )

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted
One way is to split it in letters then create a new variable which will contain the four chars in a string

The function is here https://wiki.multitheftauto.com/wiki/RemoveHex

NOT CREATED BY ME

I think you need to read his question again.

RemoveHex(created By me) : This function is used to remove hex color codes from strings.

Hello, I want to shorten a string like, if one string (nickname from player) is too long, shorten it.

Like this:

-> original string: Nickname

-> remove it untill it is only 4 length.

-> returns Nick

All what you need string.len

if (string.len (name) > 4) then 
    -- change the player name  
end 

For more information about strings check my tuto Lua Strings

removeHex, isn't removing the Hexs Today

These Days the only Solution to remove hexs, is to remove the Color of The Player When he chats.

Posted
removeHex, isn't removing the Hexs Today

These Days the only Solution to remove hexs, is to remove the Color of The Player When he chats.

Really lol ? simply to prevent players from using hex codes you can use it on:

onPlayerJoin 
onPlayerChangeNick 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

if you need to remove the colors in chat and in server use this

addEventHandler ( "onPlayerConnect", getRootElement(),function(nick) 
     if(string.find(nick,"#%x%x%x%x%x%x"))then 
          cancelEvent(true,"Remove your name colors for join the IP") 
     end 
end) 
  
addEventHandler ( "onPlayerConnect", getRootElement(),function(nick) 
     if(string.find(nick,"##%x%x%x%x%x%x"))then 
          cancelEvent(true,"Remove your name colors for join the IP") 
     end 
end) 
  
addEventHandler ( "onPlayerChat", getRootElement(),function(nick) 
     if(string.find(nick,"#%x%x%x%x%x%x"))then 
kickPlayer(source, getRootElement(), "Do not use colors in Chat!") 
     end 
end) 
  
addEventHandler ( "onPlayerChat", getRootElement(),function(nick) 
     if(string.find(nick,"##%x%x%x%x%x%x"))then 
kickPlayer(source, getRootElement(), "Do not use colors in Chat!") 
     end 
end)  

76561198387870432.png

ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003

560x95_FFFFFF_FF9900_000000_000000.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...