Forum

> > CS2D > Scripts > About say hook
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch About say hook

2 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt About say hook

Devil-Thanh
GAME BANNED Off Offline

Zitieren
i know that when we say a text like "123", it can be changed to number by tonumber(text) but i don't know if we can set a number to 0 if it cant be changed to number.

1
2
3
4
5
6
7
8
9
addhook("say","say")
function say(id,txt)
local number
--if its cant be changed to number such as "123a" or "asd154"
	number = 0
else
	number = tonumber(txt)
end
end

alt Re: About say hook

MikuAuahDark
User Off Offline

Zitieren
this is the code to complete your script
1
if tonumber(txt)==nil then	-- It's cannot changed to number

Re-written code:
1
2
3
4
addhook("say","say")
function say(id,txt)
	local number=tonumber(txt) or 0	-- It gonna try to convert "txt" to number, and if it's not possible, it sets the value to 0
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht