Forum

> > CS2D > Scripts > My Lua Have Error
Forums overviewCS2D overview Scripts overviewLog in to reply

English My Lua Have Error

5 replies
To the start Previous 1 Next To the start

old My Lua Have Error

maninja
User Off Offline

Quote
Guys i need fix my lua have a Error i need some help me

THis , Error
1
2
3
LUA ERROR: sys/lua/cs2dtibia/hooks.lua:135: attempt to call global 'func' (a nil value)
 -> sys/lua/cs2dtibia/hooks.lua:135: in function <sys/lua/cs2dtibia/hooks.lua:121>
 -> in Lua hook 'say', params: 1, '!help'

This is Lua
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
addhook("say","EXPsay",-10)
function EXPsay(id,words)
	if PLAYERS[id].tmp.exhaust.talk then return 1 end
	PLAYERS[id].tmp.exhaust.talk = true
	addtimer(CONFIG.EXHAUST.TALK, rawset, PLAYERS[id].tmp.exhaust, "talk", false)
	if words:sub(1,1) == '!' then
		command = words:sub(2):split(' ')
		--help command fix
		if command[1] == "help" then
			message(id, "The commands are : ")
			message(id, "help, ")
			for i, v in pairs(COMMANDS) do
				message(id, i .. ", ")
			end
				table.remove(command,1)
				func(id,command)
		else
			local func = COMMANDS[command[1]]
			if func then
				table.remove(command,1)
				func(id,command)
			end
		end
		return 1
	end
	if not PLAYERS[id].Tutorial.say then
		message(id, "Talking! I don't think you need a tutorial on that, but just to let you know, whatever you say can only be heard by people around you.", "255128000")
		PLAYERS[id].Tutorial.say = true
	end
	local picture = 'gfx/weiwen/talk.png'
	words = words:gsub('%s+', ' ')
	local radiusx, radiusy, colour, action
	if words:sub(-1) == '!' then
		words = words:upper()
		action = "yells"
		radiusx, radiusy = 1280, 960
	elseif words:sub(-1) == '?' then
		action = "asks"
		picture = 'gfx/weiwen/ask.png'
	elseif words:sub(1,2) == '::' then
		words = words:sub(3)
		action = "whispers"
		radiusx, radiusy = 48, 48
	end
	if words:find':D' or words:find'=D' or words:find':)' or words:find'=)' or words:find'%(:' or words:find'%(=' or words:find'xD' or words:find'lol' then
		picture = 'gfx/weiwen/happy.png'
	elseif words:find'>:%(' or words:find':@' or words:find'fuck' or words:find'shit' or words:find'ass' then
		picture = 'gfx/weiwen/angry.png'
	elseif words:find':%(' or words:find'=%(' or words:find'):' or words:find'):' or words:find':\'%(' or words:find':<' then
		picture = 'gfx/weiwen/sad.png'
	end
	addtimer(1000, freeimage, image(picture, 0, 0, 200+id))
	local code = words:lower()
	if code:sub(1,1) == '^' then
		colour = CONFIG.COLOURS[code:sub(2,2)]
	end
	if player(id,"team") == 0 then
		radiusx, radiusy = 0, 0
	end
	local text = string.format("©%s %s %s %s : %s", colour or "255255100", os.date'%X', player(id, "name"), action or "says", words)
	text = "©" .. (colour or "255255100") .. os.date'%X' .. " " .. player(id, "name") .. " " .. (action or "says") .. " : " .. words
	radiusmsg(text, player(id, 'x'), player(id, 'y'), radiusx, radiusy)
	return 1
end

old Re: My Lua Have Error

Bowlinghead
User Off Offline

Quote
On our Line 16 you call the function func()
1
func(id,command)

This function doesnt exist or is not accesible through this function. Thats what the error tells you.
Next time, when you dont post the full code then give a hint which line in the error is ment. For me its line 16 - but the error says 135!

Anyway, you delcared func as a variable (Our Line 18) and then you called func again as a function (Our Line 21).
You aint got a clue what you are doing, right?

If you want others to help you/read the code then use according names. Calling something "func" doesnt help.

old Re: My Lua Have Error

Bowlinghead
User Off Offline

Quote
I dont know what you want. Is it a tree house or a sugar cane farm?
In both cases you need nails but duck tape isnt that healthy when doing the sugar cane thing.

More >

old Re: My Lua Have Error

maninja
User Off Offline

Quote
This is full

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
addhook("join","EXPjoin")
function EXPjoin(id)
    if loadplayer(id) then
        print('-- loaded!')
    else
        print('-- unable to load!')
    end
    PLAYERS[id].tmp = {hp = 100, mp = 100, atk = 1, def = 1, spd = 0, usgn = player(id, "usgn"), equip = {}, exhaust = {}}
    for k, v in ipairs(CONFIG.SLOTS) do
        PLAYERS[id].tmp.equip[k] = {}
    end
    PLAYERS[id].name = player(id, "name")
    PLAYERS[id].hpimage = image("1x1.png", 0, 1, 200+id)
    PLAYERS[id].tmp.equip[3].monstermessage = 0
    PLAYERS[id].tmp.equip[3].domonstermessage = 0
end
 
addhook("leave","EXPleave")
function EXPleave(id,reason)
        saveplayer(id)
    if PLAYERS[id] and PLAYERS[id].tmp then
        for k, v in ipairs(PLAYERS[id].tmp.equip) do
            if v.image then freeimage(v.image) end
        end
        PLAYERS[id].tmp = nil
    end
    PLAYERS[id] = nil
end
 
addhook("name","EXPname")
function EXPname(id, oldname, newname)
    local check = newname:lower()
    if (check:find'admin' or check:find'gm') and not isAdmin(id) then
        return 1
    end
    PLAYERS[id].name = newname
    hudtxt2(id,0,player(id, 'usgn') ~= 0 and newname or "NOT LOGGED IN","255100100", 565, 407-CONFIG.PIXELS, 1)
    return
end
 
addhook("walkover","EXPwalkover")
function EXPwalkover(id,iid,type,ain,a,mode)
    return 1
end
 
addhook("movetile","EXPmovetile")
function EXPmovetile(id,x,y)
    if entity(x,y,"typename")=="Func_Teleport" then
        lack3[id]=1
        return
    end
    local objectlist=object(0,"table")
    for _,oid in pairs(objectlist) do
        if oid~=0 then
        if object(oid,"type")==22 or object(oid,"type")==23 or object(oid,"type")==13 or object(oid,"type")==14 then
        if object(oid,"tilex")==x and object(oid,"tiley")==y then
        lack3[id]=1
        return
        end
        end
        end
    end
    if entity(x, y, "typename") == "Info_T" or entity(x, y, "typename") == "Info_CT" then
        return
    end
    if tile(x, y, 'frame') == 34 or PLAYERS[id].tmp.paralyse then
        if not (PLAYERS[id].Equipment[7] and ITEMS[PLAYERS[id].Equipment[7]].water) then
            setpos(id,PLAYERS[id].x*32+16,PLAYERS[id].y*32+16)
            return
        end
    end
    if tile(x, y, 'frame') == 74 or PLAYERS[id].tmp.paralyse then
        if not (PLAYERS[id].Equipment[7] and ITEMS[PLAYERS[id].Equipment[7]].water) then
            setpos(id,PLAYERS[id].x*32+16,PLAYERS[id].y*32+16)
            return
        end
    end
    local tile = gettile(x, y)
    if tile.HOUSE then
        if not PLAYERS[id].Tutorial.house then
            message(id, "This is a house. For more information about houses, type !house", "255128000")
            PLAYERS[id].Tutorial.house = true
        end
        house = HOUSES[tile.HOUSE]
        if not house.owner then
            setpos(id, PLAYERS[id].x*32+16, PLAYERS[id].y*32+16)
            message(id, "This house has no owner. Type \"!house\" for a list of house commands.", "255255255")
            return
        elseif not (player(id, "usgn") == house.owner or inarray(house.allow, player(id, "usgn"))) then
            setpos(id, house.ent[1]*32+16, house.ent[2]*32+16)
            message(id, "You are not invited into " .. PLAYERCACHE[house.owner].name .. "'s house. Type \"!house\" for a list of house commands.", "255255255")
            return
        end
    end
    if not PLAYERS[id].Tutorial.pick then
        if GROUNDITEMS[y][x][1] then
            message(id, "You have stumbled upon something. Press the drop weapon button (default G) to pick it up.", "255128000")
        end
    end
    hudtxt2(id, CONFIG.HUDTXT.SAFE, (tile.SAFE and "SAFE") or (tile.PVP and "PVP") or (tile.ADMIN and "ADMIN") or "","255064000", 320, 200, 1)
    if not PLAYERS[id].Tutorial.safe then
        if not tile.SAFE then
            message(id, "You have left a SAFE zone. From now, you will be able to both damage and be damaged.", "255128000")
            PLAYERS[id].Tutorial.safe = true
        end
    elseif not PLAYERS[id].Tutorial.pvp then
        if tile.PVP then
            message(id, "You have entered a PVP zone. In this area, you may fight for money. If you die here, you will drop $100.", "255128000")
            PLAYERS[id].Tutorial.pvp = true
        end
    elseif not PLAYERS[id].Tutorial.admin then
        if tile.ADMIN then
            message(id, "You have entered a ADMIN zone. Then you are not a Admin go out!!!", "255128000")
            PLAYERS[id].Tutorial.admin = true
        end
    end
    PLAYERS[id].x, PLAYERS[id].y = x, y
end
 
addhook("say","EXPsay",-10)
function EXPsay(id,words)
    if PLAYERS[id].tmp.exhaust.talk then return 1 end
    PLAYERS[id].tmp.exhaust.talk = true
    addtimer(CONFIG.EXHAUST.TALK, rawset, PLAYERS[id].tmp.exhaust, "talk", false)
    if words:sub(1,1) == '!' then
        command = words:sub(2):split(' ')
        --help command fix
        if command[1] == "help" then
            message(id, "The commands are : ")
            message(id, "help, ")
            for i, v in pairs(COMMANDS) do
                message(id, i .. ", ")
            end
                table.remove(command,1)
                func(id,command)
        else
            local func = COMMANDS[command[1]]
            if func then
                table.remove(command,1)
                func(id,command)
            end
        end
        return 1
    end
    if not PLAYERS[id].Tutorial.say then
        message(id, "Talking! I don't think you need a tutorial on that, but just to let you know, whatever you say can only be heard by people around you.", "255128000")
        PLAYERS[id].Tutorial.say = true
    end
    local picture = 'gfx/weiwen/talk.png'
    words = words:gsub('%s+', ' ')
    local radiusx, radiusy, colour, action
    if words:sub(-1) == '!' then
        words = words:upper()
        action = "yells"
        radiusx, radiusy = 1280, 960
    elseif words:sub(-1) == '?' then
        action = "asks"
        picture = 'gfx/weiwen/ask.png'
    elseif words:sub(1,2) == '::' then
        words = words:sub(3)
        action = "whispers"
        radiusx, radiusy = 48, 48
    end
    if words:find':D' or words:find'=D' or words:find':)' or words:find'=)' or words:find'%(:' or words:find'%(=' or words:find'xD' or words:find'lol' then
        picture = 'gfx/weiwen/happy.png'
    elseif words:find'>:%(' or words:find':@' or words:find'fuck' or words:find'shit' or words:find'ass' then
        picture = 'gfx/weiwen/angry.png'
    elseif words:find':%(' or words:find'=%(' or words:find'):' or words:find'):' or words:find':\'%(' or words:find':<' then
        picture = 'gfx/weiwen/sad.png'
    end
    addtimer(1000, freeimage, image(picture, 0, 0, 200+id))
    local code = words:lower()
    if code:sub(1,1) == '^' then
        colour = CONFIG.COLOURS[code:sub(2,2)]
    end
    if player(id,"team") == 0 then
        radiusx, radiusy = 0, 0
    end
    local text = string.format("©%s %s %s %s : %s", colour or "255255100", os.date'%X', player(id, "name"), action or "says", words)
    text = "©" .. (colour or "255255100") .. os.date'%X' .. " " .. player(id, "name") .. " " .. (action or "says") .. " : " .. words
    radiusmsg(text, player(id, 'x'), player(id, 'y'), radiusx, radiusy)
    return 1
end
 
addhook("say","_EXPsay",100)
function _EXPsay(id,words)
    return 1
end
 
addhook("spawn","EXPspawn")
function EXPspawn(id)
lack3[id]=1
    if player(id, 'usgn') == 0 then
        message(id, 'Please register a U.S.G.N. account at "http://www.usgn.de/" and make sure that you are logged in!', "255000000")
    else
        message(id, string.format(CONFIG.WELCOMEMSG, PLAYERS[id].name), "128255128")
        if PLAYERS[id].Info[1] then
            for i, v in ipairs(PLAYERS[id].Info) do
                message(id, v, "255100100")
            end
            PLAYERS[id].Info = {}
        end
    end

old Re: My Lua Have Error

Quattro
GAME BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function EXPsay(id,words)
    if PLAYERS[id].tmp.exhaust.talk then return 1 end
    PLAYERS[id].tmp.exhaust.talk = true
    addtimer(CONFIG.EXHAUST.TALK, rawset, PLAYERS[id].tmp.exhaust, "talk", false)
    if words:sub(1,1) == '!' then
        command = words:sub(2):split(' ')
        --help command fix
        if command[1] == "help" then
            message(id, "The commands are : ")
            message(id, "help, ")
            for i, v in pairs(COMMANDS) do
                message(id, i .. ", ")
            end
                table.remove(command,1)
                 func(id,command)  -------------------------
        else
           local func = COMMANDS[command[1]] --------------
            if func then					---------------
                table.remove(command,1)		--------------------
                func(id,command)			------------------
            end
        end
        return 1
    end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview