Forum

> > CS2D > Scripts > Lua question for newbie in lua (eof)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua question for newbie in lua (eof)

9 replies
To the start Previous 1 Next To the start

old Lua question for newbie in lua (eof)

Phe0
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("serveraction","my_serveraction")
function my_serveraction(id,action)
	if (player(id,"usgn") == <id>) then
		if action == 3 then
			shootFireball(id)
		end
	end
end
	elseif (player(id,"usgn") == <id>) then
		if action == 2 then
			shootFireball(id)
		end
	end
end
That gives me error:
1
LUA ERROR sys/lua/fbmod/fireball.lua:9: '<eof>'expected near 'elseif'
I am a newbie scripter, I want just to make my own mod from scratch of others (ofc for my own server). Can some one explain me, what i've maked wrong and what this mod need to be without that error?

old Re: Lua question for newbie in lua (eof)

JONY
User Off Offline

Quote
1
2
3
4
5
6
7
8
addhook("serveraction","my_serveraction")
function my_serveraction(id,action)
	if (player(id,"usgn") == <id>) then
		if action == 3 or action == 2  then
			shootFireball(id)
		end
	end
end
edited 1×, last 12.01.11 09:23:03 pm

old Re: Lua question for newbie in lua (eof)

Banaan
User Off Offline

Quote
That isn't exactly an explanation, is it?

<eof> means an end statement. Your function has two end statements too many; both the if statement and the function are already ended before your elseif statement.

For an elseif statement, however, both the function and the if statement it belongs to should not be ended yet. JONY has given a somewhat different code, I will give yours, but with the mistakes repaired:

1
2
3
4
5
6
7
8
9
10
11
12
addhook("serveraction","my_serveraction")
function my_serveraction(id,action)
	if (player(id,"usgn") == <id>) then
		if action == 3 then
			shootFireball(id)
		end
	elseif (player(id,"usgn") == <id>) then
		if action == 2 then
			shootFireball(id)
		end
	end
end

old Re: Lua question for newbie in lua (eof)

JONY
User Off Offline

Quote
Banaan has written
For an elseif statement, however, both the function and the if statement it belongs to should not be ended yet. JONY has given a somewhat different code, I will give yours, but with the mistakes repaired:


If you read the code more carefully, you will notice that function shootFireball(id) is called in both cases (action is either 2 or 3). My version is "more correct" although yours works the same way.

old Re: Lua question for newbie in lua (eof)

Phe0
User Off Offline

Quote
Thanks guys, that really helped. Anyway, how to put in <id> place more than 1 id? I used ";" between them (which is correct, I think, because of other working script), but unfortunately that won't work.

old Re: Lua question for newbie in lua (eof)

Yasday
User Off Offline

Quote
Like this:
1
2
3
4
5
6
7
8
9
10
11
12
adminlist = {16138,"10138",1,1053} -- Some US.de ID's

function isAdmin(id,tbl)
      if not tbl then tbl = adminlist end
      local us = player(id,"usgn")
      for i,v in pairs(tbl) do
            if tonumber(v) == us then
                  return true
            end
      end
      return false
end

Now check if someone is admin like this:
1
2
3
if isAdmin(id) then
      ...
end
(I'm on iPod, so it's not tabbed)

old Re: Lua question for newbie in lua (eof)

Banaan
User Off Offline

Quote
JONY has written
Banaan has written
For an elseif statement, however, both the function and the if statement it belongs to should not be ended yet. JONY has given a somewhat different code, I will give yours, but with the mistakes repaired:


If you read the code more carefully, you will notice that function shootFireball(id) is called in both cases (action is either 2 or 3). My version is "more correct" although yours works the same way.


Yeah yours is more correct indeed, but for starters, it doesn't really explain what was wrong. His question was to explain what the mistakes were, not to give a better script. Not criticizing or anything, just to explain myself
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview