Forum

> > CS2D > Scripts > Function second not work
Forums overviewCS2D overview Scripts overviewLog in to reply

English Function second not work

5 replies
To the start Previous 1 Next To the start

old Function second not work

Gaios
Reviewer Off Offline

Quote
Why function secondhook not work?

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
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t,match) do
          table.insert(cmd,word)
     end
     return cmd
end

function init(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end

prison = init(32)
licznik = init(32)

addhook('say','sayhook')
addhook('spawn','spawnhook')
addhook('second','secondhook')

prisons = {
	[1] = {100,100},
	[2] = {500,500}}

function sayhook(id,txt)
local p = totable(txt)
local cmd = string.lower(p[1])
	if (txt:sub(1,1) == "@" or txt:sub(1,1) == "!") and txt ~= "rank" then
		if cmd == "@prison" then
			local pl = tonumber(p[2])
			local cell = tonumber(p[3])
			local times = tonumber(p[4])
			if pl ~= nil and cell ~= nil and times ~= nil then
				if player(pl,"exists") then
					parse("setpos "..pl.." "..prisons[cell][1].." "..prisons[cell][2])
					prison[pl] = true
					licznik[pl] = times
				end
			end
		end
	end
end

function secondhook(id)
	if prison[id] == true then
		if licznik[id] > 0 then
			licznik[id] = licznik[id] - 1
		end
	end
	if licznik[id] == 1 then
		prison[id] = false
		licznik[id] = 0
		parse("killplayer "..id)
	end
end
edited 1×, last 03.10.12 12:30:24 am

old Re: Function second not work

Gaios
Reviewer Off Offline

Quote
user EP has written
Second has no id parameter. You should use player(0,"table") or a for loop...

Thx how to use for?

Good?:
1
2
3
4
5
6
7
8
if prison[id] == true then
	local playerlist=player(0,"table")
	for _,id in pairs(playerlist) do
		if licznik[id] > 0 then
			licznik[id] = licznik[id] - 1
		end
	end
end

old Re: Function second not work

EP
User Off Offline

Quote
For example this:
1
2
3
4
5
for i = 1,32 do
	if player(i,"exists") then
		--Block
	end
end
In the last script you gave me (You did it wrong!, 1st you check the playertable and then you check the conditions) it's:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for id = 1,32 do
	if player(id,"exists") then
		if prison[id] == true then
			if licznik[id] > 0 then
				licznik[id] = licznik[id] - 1
			end
		end
		if licznik[id] == 1 then
			prison[id] = false
			licznik[id] = 0
			parse("killplayer "..id)
		end
	end
end
And I recommend you to use this code because it users playertable:
1
2
3
4
5
6
7
8
9
10
11
12
for _,id in pairs(player(0,"table")) do
	if prison[id] == true then
		if licznik[id] > 0 then
			licznik[id] = licznik[id] - 1
		end
	end
	if licznik[id] == 1 then
		prison[id] = false
		licznik[id] = 0
		parse("killplayer "..id)
	end
end

old Re: Function second not work

Gaios
Reviewer Off Offline

Quote
user EP has written
For example this:
1
2
3
4
5
for i = 1,32 do
	if player(i,"exists") then
		--Block
	end
end
In the last script you gave me (You did it wrong!, 1st you check the playertable and then you check the conditions) it's:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for id = 1,32 do
	if player(id,"exists") then
		if prison[id] == true then
			if licznik[id] > 0 then
				licznik[id] = licznik[id] - 1
			end
		end
		if licznik[id] == 1 then
			prison[id] = false
			licznik[id] = 0
			parse("killplayer "..id)
		end
	end
end
And I recommend you to use this code because it users playertable:
1
2
3
4
5
6
7
8
9
10
11
12
for _,id in pairs(player(0,"table")) do
	if prison[id] == true then
		if licznik[id] > 0 then
			licznik[id] = licznik[id] - 1
		end
	end
	if licznik[id] == 1 then
		prison[id] = false
		licznik[id] = 0
		parse("killplayer "..id)
	end
end


@user EP The script is ok?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview