Forum

> > CS2D > Scripts > leave hook bug...
Forums overviewCS2D overview Scripts overviewLog in to reply

English leave hook bug...

6 replies
To the start Previous 1 Next To the start

old leave hook bug...

loldlold123
User Off Offline

Quote
Hello

There are few jobs in my script and they are limited (exemple: police/limit2)
im using these codes(exemple)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end

playerjob=initArray(32)
police=0

addhook("leave","hhleave")
function hhleave(id)
if playerjob[id]>0 then
police=police-1
end
end

But it has bug...When player get lag and he lost connection, leave hook isnt working and there is no player but it shows there is 1 police...do you understant me?How can i solve this problem?

old Re: leave hook bug...

Apache uwu
User Off Offline

Quote
Why not manually count the number of police instead of with a variable.

Go through all the "living" players with "jobs" and see how many people have the job 'police'...

old Re: leave hook bug...

Starkkz
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
function police()
	local policeCount = 0
	for _, id in pairs(player(0,"table")) do
		if playerjob[id] == 1 then -- Police job
			policeCount = policeCount + 1
		end
	end
	return policeCount
end

should be something like that

old Re: leave hook bug...

loldlold123
User Off Offline

Quote
hmm you made,what i made... this is..
when playerjob=1
policecounter=policecounter+1

but

my problem is:

If player get lag,he lost connection and there is no police but it shows there is one police...

i mean:
POLICE LIMIT = 1
PLAYER JOIN TO POLICE JOB

POLICE LIMIT=POLICE LIMIT+ 1
AND THIS MEANS,POLICE JOB FULL...

PLAYER GET LAG AND HE LOST CONNECTION.
AND LEAVE HOOK CANT WORKED...

THERE IS NO PLAYER IN POLICE JOB,

BUT POLICE LIMIT STILL FULL...

old Re: leave hook bug...

DC
Admin Off Offline

Quote
you have to call the function that starkzz posted constantly (or once per second or something like that). it will automatically correct the policecount variable.
1
policecounter=police()

I'll also try to fix the leave hook problem for the next version so that it is called whenever a player leaves the server, no matter how.

old Re: leave hook bug...

Apache uwu
User Off Offline

Quote
user DC has written
you have to call the function that starkzz posted constantly (or once per second or something like that). it will automatically correct the policecount variable.
1
policecounter=police()

I'll also try to fix the leave hook problem for the next version so that it is called whenever a player leaves the server, no matter how.


I believe the player name DOES disappear form the [tab] menu however the hud message at the top never shows, the hook is also never triggered.

More >

old Re: leave hook bug...

loldlold123
User Off Offline

Quote
Btw the join hook is sometimes triggered on map download, which is very bad!!


you are right...dc should fix it too...
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview