Forum

> > CS2D > Scripts > Wrong script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Wrong script

24 replies
Page
To the start Previous 1 2 Next To the start

old Wrong script

QuakeR
BANNED Off Offline

Quote
hi, i want to make afk script when say @afk then yourname change
1
"..player(id,"name").." [AFK]
and @back to back play
then
1
"..player(id,"name").."
but it still like that didn't changed please help me there are the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
------addHook----
addhook("say","afksay")
------------------------

function afksay(id,txt)
      if(string.sub(txt,1,4)=="@afk") then
        parse("makespec "..id)
           parse("setname "..id.." "..player(id,"name").." (afk) ")
           return 1;
		   elseif(string.sub(txt,1,5)=="@back") then
		   parse("setname "..player(id,"name").." ")
		   parse("maket "..id)
		   parse("makect "..id)
		   msg("©255255255"..player(id,"name").." is no longer afk.")
		   afk = false
		   return 1;
		   end
             end

old Re: Wrong script

Mami Tomoe
User Off Offline

Quote
Try this:
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
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

name=Array(32,Player)

addhook("join","afkjoin")
function afkjoin
	name[id]=player(id,"name")
end

addhook("say","afksay")
function afksay(id,txt)
	if(string.sub(txt,1,4)=="@afk") then
		name[id]=player(id,"name")
		parse("makespec "..id)
		parse("setname "..id.." "..player(id,"name").." [AFK]")
		return 1
	elseif(string.sub(txt,1,5)=="@back") then
		parse("setname "..id.." "..name[id])
		parse("maket "..id)
		parse("makect "..id)
		msg("©255255255"..player(id,"name").." is no longer afk.")
		afk = false
		return 1
	end
end

old Re: Wrong script

Mami Tomoe
User 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
25
26
27
28
29
30
31
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

name=Array(32,Player)

addhook("join","afkjoin")
function afkjoin()
	name[id]=player(id,"name")
end

addhook("say","afksay")
function afksay(id,txt)
	if(string.sub(txt,1,4)=="@afk") then
		name[id]=player(id,"name")
		parse("makespec "..id)
		parse("setname "..id.." "..player(id,"name").." [AFK]")
		return 1
	elseif(string.sub(txt,1,5)=="@back") then
		parse("setname "..id.." "..name[id])
		parse("maket "..id)
		parse("makect "..id)
		msg("©255255255"..player(id,"name").." is no longer afk.")
		afk = false
		return 1
	end
end

old Re: Wrong script

Waldin
User Off Offline

Quote
No, it doesnt work liar!

line 12:
function afkjoin()

Change to
function afkjoin(id)

old Re: Wrong script

Rainoth
Moderator Off Offline

Quote
@user Waldin: Should work regardless because he's looping everyone so the array is created, it just doesn't set it's value to player name.
Instead it's set when player goes "afk" or "back".
In other words, the join hook part is not needed since you do not need to set your name when you join the server

old Re: Wrong script

Waldin
User Off Offline

Quote
Im sorry, didnt saw the whole script, just the error.
wtf i just can see errors in the code...

name=Array(32,Player)


and some pointless things

afk = false

sorry, but i never saw other "code style" like this.

old Re: Wrong script

Mami Tomoe
User Off Offline

Quote
This is the fully fixed code, things like afk=false were made by him therefore I will leave them but I added a few more things and fixed the join hook.
Better safe than sorry

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
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

name=Array(32,Player)

addhook("join","afkjoin")
function afkjoin(id)
	name[id]=player(id,"name")
end

addhook("say","afksay")
function afksay(id,txt)
	if(string.sub(txt,1,4)=="@afk") then
		name[id]=player(id,"name")
		parse("makespec "..id)
		parse("setname "..id.." "..player(id,"name").." [AFK]")
		msg("©255255255"..player(id,"name").." is now afk.")
		afk = true --I added this because it made sense
		return 1
	elseif(string.sub(txt,1,5)=="@back") then
		parse("setname "..id.." "..name[id])
		parse("maket "..id)
		parse("makect "..id)
		msg("©255255255"..player(id,"name").." is no longer afk.")
		afk = false --He placed it here in the first place
		return 1
	end
end

old Re: Wrong script

Rainoth
Moderator Off Offline

Quote
@user Waldin: Yup. Tons of useless commands. Doesn't mean that it's not working. It does what user QuakeR asked for and much more stuff that's useless.

I'll take a go at it too.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
afk = {}
addhook("say","_s")
function _s(id,t)
	if t:sub(1,4) == "@afk" and not afk[id] then
		afk[id] = player(id,"team")
		parse("setname "..id.." "[AFK]"..player(id,"name"))
		parse("makespec "..id)
	else
		if afk[id] then
			parse("setname "..id.." "..player(id,"name"):sub(6,#player(id,"name")))
			if afk[id] == 1 then
				parse("maket "..id)
			else
				parse("makect "..id)
			end
			afk[id] = nil
		end
	end
end

In my case it'll make your name have [AFK] tag and move you into spectators and bring you back the moment you say anything else.
edited 1×, last 17.08.16 01:13:37 am

old Re: Wrong script

QuakeR
BANNED Off Offline

Quote
@user Rainoth: unless add anti-spam message players will spam :/.


PS: reviewed code there's error
1
LUA ERROR: sys/lua/hc/modules/afk.lua:6: ')' expected near '['

old Re: Wrong script

Rainoth
Moderator Off Offline

Quote
Added a slight tweak to prevent the command execution if a person spams "@afk". Should work as intended now.

For the error, it's probably something to do with HC admin script rather than mine. Since you get an error code in a place where I execute a simple 3 argument parse... Maybe HC thinks the '[ ]' brackets are trying to access by index or something. Never used or worked with that script so can't tell. Try to load this script separately outside of HC.

old Re: Wrong script

Mami Tomoe
User Off Offline

Quote
Also take a look at:
1
2
parse("maket "..id)
          parse("makect "..id)
In your code, it will ALWAYS make you ct so if you want me to add a feature to restore you to the original team you were in just ask...

old Re: Wrong script

Rainoth
Moderator Off Offline

Quote
@user Waldin: Oh yeah after looking at it again those " quotes aren't needed, you're right.
@user QuakeR: What kind of magic are you using where the author of the script says "that thing doesn't work" and you reply with "works as well, thanks I checked"
Dafuq
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview