Forum

> > CS2D > Scripts > Addhook error with closing game
Forums overviewCS2D overview Scripts overviewLog in to reply

English Addhook error with closing game

6 replies
To the start Previous 1 Next To the start

old Addhook error with closing game

phalenkO
User Off Offline

Quote
Hi, I made to my lua but error during the trial founded the error
Where I make a mistake?
Spoiler >




I guess i did somethings wrong
>
1
2
3
4
addhook("say","pha.says")
function pha.says(id,txt)
if c == "!anycode" then 
parse(...

old Re: Addhook error with closing game

DC
Admin Off Offline

Quote
Did you declare the table
pha
anywhere?
If not do this in the very first line in your script and everything afterwards. It creates an empty table called pha.
pha = {}


Explanation:
Lua does not allow you to put stuff in tables which do not exist. In your case you're declaring the function "says" inside the table "pha" but "pha" does not exist because you did not declare it.

Another fix would be to not use a table at all:
1
2
3
4
addhook("say","says")
function says(id,txt)
if c == "!anycode" then 
parse(...
Your function would then be stored in the global Lua table.

old Re: Addhook error with closing game

phalenkO
User Off Offline

Quote
@user DC: There is my question, How to represent the error or unavaible command?
1
2
3
4
5
6
7
8
....
elseif c == "!name" then 
 parse("name "....
else 
 msg2(id,"(error msg))
return 1
end
...

..I think dont there is error but not working

old Re: Addhook error with closing game

DC
Admin Off Offline

Quote
You have to be more precise. "not working" is not an accurate description of you problem. Tell us what you expect to happen and what actually happens.

Your general approach looks right. Just check all commands with if / elseif and in case nothing matches show an error in the last else branch.

In your above code however I don't see that you set the variable
c
anywhere. It will have the value
nil
(which means "undefined"/"no value" in Lua).

You have to set c properly. What you probably want to do is finding the first space in the chat message and store everything before that in c. If there is no space you probably want to store the whole chat message in c. The chat message is passed in as the variable
txt
because you called the second function parameter in the hooked function like that.

old Re: Addhook error with closing game

phalenkO
User Off Offline

Quote
@user DC:
Why do not working color for admin chat?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
elseif komutlar == "!slap" and svadmin(id) then 
        if not args[2] then msg2(id,"\169255000000ERROR: You did not type the ID") return 1 end
            parse("slap "..args[2])
            msg("\169255255255SERVER: dddkdk")
        return 1
	   else
		msg2(id,"\169250000000ERROR: That command isnt true "..args[1])
		return 1
		end
		return 1
		else 
		if svadmin(id) then
          msg("\169"..player(id,"name").." : "..txt)
     end
     return 1
end
	
end
edited 2×, last 06.04.19 10:43:51 pm

old Re: Addhook error with closing game

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
elseif komutlar == "!slap" and svadmin(id) then 
			if not args[2] then msg2(id,"\169255000000ERROR: You did not type the ID") return 1 end
			parse("slap "..args[2])
			msg("\169255255255SERVER: dddkdk")
		else
			msg2(id,"\169250000000ERROR: That command isnt true "..args[1])
		end
		return 1
	else 
		if svadmin(id) then
			msg("\169255255255"..player(id,"name").." : "..txt)
			return 1
		end
	end
end
Try this.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview