Forum

> > CS2D > Scripts > What are the errors in my script?
Forums overviewCS2D overview Scripts overviewLog in to reply

English What are the errors in my script?

2 replies
To the start Previous 1 Next To the start

old What are the errors in my script?

foxfire
User Off Offline

Quote
Guys, please help me, Im trying to make a script that when you say "!test PlayerID" it shows the name of the player with this id, but when I try in-game it shows this in the console:

1
LUA ERROR: sys/lua/giveitems.lua:3: attempt to index local 'message' (a nil value)

But I could not fix it.

1
2
3
4
5
6
7
8
9
addhook("say","player_name")
function player_name(p,id,message)
if string.lower(message:sub(1,6))=="!test" then
local playerid = string.lower(message:sub(7))
if (player(playerid) > 0) and (player(playerid) <= 32) and player(playerid,"exists") then
msg("[Player Name: "..player(playerid,"name").."]")
end
end
end

Please can anyone explain it for me?

old Re: What are the errors in my script?

Apache uwu
User Off Offline

Quote
Please put tabs next time.


Fixed.

1
2
3
4
5
6
7
8
9
10
addhook("say","player_name")

function player_name(id,message)
	if string.lower(message:sub(1,6))=="!test " then
		local playerid = string.lower(message:sub(7))
		if (player(playerid) > 0) and (player(playerid) <= 32) and player(playerid,"exists") then
			msg("[Player Name: "..player(playerid,"name").."]")
		end
	end
end

old Re: What are the errors in my script?

CmDark
User Off Offline

Quote
Well, first of all: the say function will always only have 2 parameters, playerid and the text. Secondly, why do you have a string.lower for a number? (7)
Lastly, what's with you sticking playerid into player?
I wouldn't be able to understand what you were trying to do if you didn't clearly state it in your first line.
You put a decent amount of redundancy in there.
More >
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview