Forum

> > CS2D > Scripts > How work the string.sub numbers
Forums overviewCS2D overview Scripts overviewLog in to reply

English How work the string.sub numbers

4 replies
To the start Previous 1 Next To the start

old Re: How work the string.sub numbers

ohaz
User Off Offline

Quote
There is this awesome thing called google where you can enter "lua string sub" and you will find cool pages like http://lua-users.org/wiki/StringLibraryTutorial that show you how it works.

Spoiler >

old Re: How work the string.sub numbers

princeofpersia
User Off Offline

Quote
its wrong > if string.sub(txt, 1,5) == "!ban" then

1 > ! & 2 > b & 3 > a & 4 > n

so its true > if string.sub(txt, 1,4) == "!ban" then

maybe you want use space after !ban . i mean if you use "!ban " insteat "!ban" then > if string.sub(txt, 1,5) == "!ban " then < is true

example :

if string.sub(txt, 1,5) == "!ban " then
pl=(math.floor(string.sub(txt,6,7)))
parse('banip '..pl)
end

now you can use !ban <id> for ban someone

old Re: How work the string.sub numbers

phalenkO
User Off Offline

Quote
@user princeofpersia:
example :
as far as I know it is true

1
2
if string.sub(txt, 1, 5)  == "!ban" then 
local adam = string.sub(txt, 7, 8)

but if

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if string.sub(txt, 1, 10) == "!ban" then 
local adam = string.sub(txt, 12, 13)
parse("banname "..adam)
return 1
end
elseif string.sub(txt, 1, 2) == "!kick" then 
local adam = string.sub(txt, 4, 5)
parse("kick"..adam)
return 1
elseif string.sub(txt, 1, 7) == "!makect" then 
local adam 0 string.sub(txt, 9, 10)
parse("makect"..adam)
return 1
end

does such excessive and irregular numbers prevent it from functioning?

old Re: How work the string.sub numbers

minos
User Off Offline

Quote
string.sub numbers are only positions of your word for example
this word : slap > we have here 4 letters and with sign ! it's 5
so the strin.sub(1"the first postion in ur cmd","your word letters number")
the commands is !slap
positions are : (1,5) => !(1) , s(2) , l(3) , a(4) , p(5)
then after !slap it will be a space (space's positionis 6) then
id comes after the space and it might be 2 numbers because the maxplayers are 32 then id position is i(7) and d(8)
so the code will be like this
1
2
3
4
5
6
if string.sub(txt,1,5)=="!slap" then 
local kid = tonumber(string.sub(txt,7,8))
parse("slap "..kid)
msg2(id, player(kid,"name").." is slaped")
return 1 
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview