English How work the string.sub numbers

4 replies
Goto Page
To the start Previous 1 Next To the start
Up
phalenkO
User
Offline Off
Code:
1
if string.sub(txt, 1,5) == "!ban" then

Can you tell how to use numbers when writing this code?
02.06.18 12:20:21 pm
Up
ohaz
User
Offline Off
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 >
https://ohaz.engineer - Software Engineering
02.06.18 12:48:09 pm
Up
princeofpersia
User
Offline Off
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
02.06.18 11:32:00 pm
Up
phalenkO
User
Offline Off
@user princeofpersia:
example :
as far as I know it is true

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


but if

Code:
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?
03.06.18 12:00:53 am
Up
minos
User
Offline Off
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
Code:
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
l
To the start Previous 1 Next To the start