String inside string?
6 replies



29.05.16 04:24:30 pm
I have no clue what to call it so I couldn't search for it too...
Results in
I know I'm doing it wrong but I just tried for like the past 10 minutes and I have no clue what to do
I would like to add there is no hc.SERVERNAME[id] since this is in a loop and I want to find 9 hc.SERVERNAME like that:
hc.SERVERNAME1
hc.SERVERNAME2
hc.SERVERNAME3
etc..
Pliz help me
oh my cat say hi
Code:
1
2
3
2
3
if hc.SERVERNAME ..id == nil then
hc.SERVERNAME ..id = '(Empty | '
end
hc.SERVERNAME ..id = '(Empty | '
end
Results in
Code:
1
2
3
2
3
LUA ERROR: sys/lua/server.lua:23: '=' expected near '..'
-> [C]: in function 'dofile'
-> [string "dofile("sys/lua/server.lua")"]:1: in main chunk
-> [C]: in function 'dofile'
-> [string "dofile("sys/lua/server.lua")"]:1: in main chunk
I know I'm doing it wrong but I just tried for like the past 10 minutes and I have no clue what to do

I would like to add there is no hc.SERVERNAME[id] since this is in a loop and I want to find 9 hc.SERVERNAME like that:
hc.SERVERNAME1
hc.SERVERNAME2
hc.SERVERNAME3
etc..
Pliz help me

oh my cat say hi

Look at me standing, here on my own again
You cannot concatenate the id string before the variable when it's assigned. You would normally do like this as it's shown below:
However there's something that you should be aware of. Since the strings in Lua are immutable, each new concatenation with the same variable string creates a new string object. That would result in a poor performance due to successive concatenations into a single string. Also, note that it might occur unexpected behaviours whilst you run the code since I don't have your script to test whether it gives optimal results with this fix or not.
Code:
1
hc.SERVERNAME = hc.SERVERNAME .. id '(Empty | '
However there's something that you should be aware of. Since the strings in Lua are immutable, each new concatenation with the same variable string creates a new string object. That would result in a poor performance due to successive concatenations into a single string. Also, note that it might occur unexpected behaviours whilst you run the code since I don't have your script to test whether it gives optimal results with this fix or not.
Edit: Problem solved
But I have a new problem, how to get the server IP in a script? (including port)
edited 2×, last 29.05.16 05:48:01 pm
Look at me standing, here on my own again
Set this to your choice
So, an example would be
You have to manually set the IP and port values of a server you want to reroute to.
Code:
1
hc.SERVERIP1 = "ip:port"
So, an example would be
Code:
1
hc.SERVERIP1 = "192.168.0.1:80"
You have to manually set the IP and port values of a server you want to reroute to.
Yes but I want the actual server's IP, like this:
Code:
1
game("sv_name")
Look at me standing, here on my own again
There's no way you can achieve this with the current CS2D library unfortunately. The IP and port of the server must be written manually by yourself for each indexed table.
Code:
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
addhook("say", "_say")
function _say(id, txt)
if txt:sub(1,4) == "!bla" then
local handle = io.popen("curl ipecho.net/plain; echo")
local result = handle:read("*a") .. ":" .. game("port")
msg(result)
handle:close()
end
end
function _say(id, txt)
if txt:sub(1,4) == "!bla" then
local handle = io.popen("curl ipecho.net/plain; echo")
local result = handle:read("*a") .. ":" .. game("port")
msg(result)
handle:close()
end
end
You will need "curl" installed on your machine.



