Forum

> > CS2D > Scripts > Lua question for newbie in lua (eof)
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Lua question for newbie in lua (eof)

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Lua question for newbie in lua (eof)

Phe0
User Off Offline

Zitieren
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?

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

JONY
User Off Offline

Zitieren
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
1× editiert, zuletzt 12.01.11 21:23:03

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

Banaan
User Off Offline

Zitieren
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

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

JONY
User Off Offline

Zitieren
Banaan hat geschrieben
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.

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

Phe0
User Off Offline

Zitieren
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.

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

Yasday
User Off Offline

Zitieren
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)

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

Banaan
User Off Offline

Zitieren
JONY hat geschrieben
Banaan hat geschrieben
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
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht