Hey ho
This is my very first day with LUA.
I have made a code, but it don´t start!
I did put 1
dofile("sys/lua/Tutorial_Script.lua)
in the end of the server.lua (And my server starts with that file in CS2D)
This is the code that I made:
More 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- Debug with "debuglua 1"
addhook("join", "joinscript")
function joinscript(id)
msg("Player "..player(id, "name").." joined the game :D")
end
addhook("say", "said")
function said(id)
	msg(..played(id, "name").. " said something!")
end
addhook("say","die")
function die(player, text)
if (text == "die")then
msg(..player(player, "name").." wants somebody to die! :O")
end
end
-- Send Message With Names to Player --
addhook ("minute", "tutorialadvertise")
function tutorialadvertise()
for (i = 1, 32, 1) do
if (player(i, "exists")) then
msg2(i, "Hello, "..player(player, "name")..", Enjoy this Awesome Server :P")
end
end
end
NOTHING that is in that code do something in the server
What am i doing wrong? Admin/mod comment
Please use The Lua Scripts/Questions/Help thread for Lua related questions. /Lee Nem User Offline
Maybe something with quotes ?
1
dofile("sys/lua/Tutorial_Script.lua")
actually dunno, dont know lua xd Lee Moderator Offline
Along with Nemesis' suggestion, apply the following edits:
Ln10:
1
msg(..played(id, "name").. " said something!")
Change to
1
msg(played(id, "name").. " said something!")
Repeat the above for Ln15:
1
msg(..played(id, "name").. " said something!")
Ln23
Lua doesn't allow for (...) do style, you need to ungroup the parameters:
Change to
There's a problem at minute hook.
Isn't player(player,"name")..
it's player(i,"name")..
I prefer use the pairs of the player table.
1
2
3
4
5
6
addhook ("minute", "tutorialadvertise")
function tutorialadvertise()
	for _, id in pairs(player(0,"table")) do
		msg2(id, "Hello, "..player(id, "name")..", Enjoy this Awesome Server :P")
	end
end
Well, Thank You
Can´t test it now cuz my other computer is broken
I´m on my iphone now well, i tell you, never use player like value.
It was like a function.
You can get names, pings, positions, health, and more things with player function. If you use it like a value you will confuse the lua script. That will give you an error at console.