Forum

> > CS2D > Scripts > Player glow (what is up with this script??)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Player glow (what is up with this script??)

3 replies
To the start Previous 1 Next To the start

old Player glow (what is up with this script??)

olieo
User Off Offline

Quote
It works perfectly when i start a server on my home pc but when i upload to the vps and run it the glow comes out 100% solid and unable to see through and it doesn't change color when it goes past cyan (level 30).

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
function glowing(id)
parse("sethealth "..id.." 250")
imgs[id]=image("gfx/sprites/flare4.bmp",0,0,id+100)
imageblend(imgs[id],1)
imagealpha(imgs[id],1)
glowcolourcheck(id)
end

function glowcolourcheck(id)
playercolour[id] = playerlevel[id]*17
playercolour2[id] = playerlevel[id]*17-255
playercolour3[id] = playerlevel[id]*17-765
playercolour4[id] = playerlevel[id]*17-1020
playercolour5[id] = playerlevel[id]*17-765
playercolour6[id] = playerlevel[id]*17-1020
	if playerlevel[id] <= 15 then
	imagecolor(imgs[id],0,playercolour[id],0)
	end
	if playerlevel[id] > 15 then
		if playerlevel[id] <= 30 then
		imagecolor(imgs[id],0,255,playercolour2[id])
		end
	end
	if playerlevel[id] > 30 then
		if playerlevel[id] <= 45 then
		imagecolor(imgs[id],0,-playercolour3[id],255)
		end
	end
	if playerlevel[id] > 45 then
		if playerlevel[id] <= 60 then
		imagecolor(imgs[id],playercolour5[id],0,-playercolour4[id])
		end
	end
	if playerlevel[id] > 60 then
	imagecolor(imgs[id],255,0,-playercolour6[id])
	end
end

function notglow(id)
deathscore[id] = player(id,"score")-playerlevel[id]
parse ("setscore "..id.." "..deathscore[id].."")
msg2(id,"©255000000-"..playerlevel[id].." EXP")
setlevel(id)
	if imgs[id]~=0 then
     	freeimage(imgs[id])
     	imgs[id]=0
	end
end

old Re: Player glow (what is up with this script??)

VADemon
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function glowing(id)
	parse("sethealth "..id.." 250")
	imgs[id] = image("gfx/sprites/flare4.bmp", 0, 0, id + 100)
	imageblend(imgs[id], 1)
	imagealpha(imgs[id], 1)	-- image alpha (transparency) and blend mode should be 1 by default. why do you set it to 1 again?
	glowcolourcheck(id)
end

function glowcolourcheck(id)
	playercolour[id] = playerlevel[id]*17
	playercolour2[id] = playerlevel[id]*17-255
	playercolour3[id] = playerlevel[id]*17-765
	playercolour4[id] = playerlevel[id]*17-1020
	playercolour5[id] = playerlevel[id]*17-765
	playercolour6[id] = playerlevel[id]*17-1020
	
	if playerlevel[id] <= 15 then
		imagecolor(imgs[id],0,playercolour[id],0)
		
	elseif playerlevel[id] > 15 then
		imagecolor(imgs[id], 0, 255, playercolour2[id])
		
	elseif playerlevel[id] > 30 then
		imagecolor(imgs[id], 0, -playercolour3[id],255)	-- why do you negate the color value here and below but not for level 15 and below (lvl > 15)?
		
	elseif playerlevel[id] > 45 then
		imagecolor(imgs[id],playercolour5[id],0,-playercolour4[id])
		
	elseif playerlevel[id] > 60 then
		imagecolor(imgs[id],255,0,-playercolour6[id])
		
	end
end

function notglow(id)
	deathscore[id] = player(id,"score")-playerlevel[id]
	parse ("setscore "..id.." "..deathscore[id])	-- you don't need to add an empty string to the end:  ..""
	msg2(id,"©255000000-"..playerlevel[id].." EXP")
	setlevel(id)
	
	if imgs[id]~=0 then
     	freeimage(imgs[id])
     	imgs[id]=0
	end
end
1) Read the comments in the code
2) Use if-elseif where appropriate (it was the case)

Now, tell me how do you call these functions? I guess it could be you call glowcolourcheck(id) multiple times without clearing the previous image thus adding up images and that results in a pure color around the player.

old Re: Player glow (what is up with this script??)

olieo
User Off Offline

Quote
@user VADemon: I think that must be it, ill try to edit it tonight.

I've also noticed another problem where players spawn in with a higher level colour than they are, is this also a problem where I need to clear the image if a player leaves?

I negate the colour value to turn it into a positive --100 = 100, this way one colour value can fall as another rises.

for example:
between level 45 and 60

playercolour4[id] = playerlevel[id]*17-1020
playercolour4[id] = 46*17-1020 = -238
playercolour4[id] = 47*17-1020 = -221
etc.
playercolour5[id] = playerlevel[id]*17-765
playercolour5[id] = 46*17-765 = 17
playercolour5[id] = 47*17-765 = 34

imagecolor(imgs[id],playercolour5[id],0,-playercolour4[id])
imagecolor(imgs[id],17,0,--238)
imagecolor(imgs[id],34,0,--221)

Oh and thanks for the thing about strings, i wasn't sure if i needed to there.

glowing was called through a spawn hook
notglow was called through a die hook
checkglow was called through the glowing function and the setlevel function(which sets the playerlevel[id] value based on score - which is called every time a player picks up money or kills someone or spawns or dies )0

The odd thing is, when im playing on my home server it doesn't seem to get brighter at all and the colours all work as intended...

I'm guessing it should fix itself if i put a hook to notglow just before the setlevels checkglow then hook leave to not glow also.

(just realised i can switch the 17 for -17 and make it +1020 to end up with a positive figure to make sure that isnt what's causing the issue)
edited 13×, last 24.05.15 11:24:47 am

old Re: Player glow (what is up with this script??)

VADemon
User Off Offline

Quote
I read your message twice and I still don't understand it as well as the math behind.
Anyway, the possible color values are ranged from 0 to 255, there're no negative values and you should then set a zero value instead a negative one.
One thing I now noticed: you don't have a check inside glowcolourcheck(id) whether the image for the player exists (I would then print an error message)

If you want me to fix your code, send it in a PM.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview