Forum

> > CS2D > Scripts > Gfx disappear
Forums overviewCS2D overview Scripts overviewLog in to reply

English Gfx disappear

1 reply
To the start Previous 1 Next To the start

old Gfx disappear

NanuPlayer
User Off Offline

Quote
Hi us
sometimes hat disappear... im not sure if its because Worn Weapons script or because there is too much gfx in the server but someone help me please the problem is annoying

My hats script :
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
addhook("say","say_hat")
function say_hat(id,txt)
	if (txt=="!angel") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/angel.png",1,1,200+id)
	end
	if (txt=="!dangerous") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/dangerous.png",1,1,200+id) 
	end
	if (txt=="!devil") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/devil.png",1,1,200+id)
	end
	if (txt=="!headphones") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/headphones.png",1,1,200+id)
	end
	if (txt=="!nohat") then
		freeimage(id) 
	end
	if (txt=="!rock") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/rock.png",1,1,200+id) 
	end
	if (txt=="!santa") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/santa.png",1,1,200+id) 
	end
	if (txt=="!snowman") then
		freeimage(id) 
		id=image("gfx/~{Zombie}~/Hats/snowman.png",1,1,200+id) 
	end
end
edited 1×, last 22.05.21 04:22:05 pm

old Re: Gfx disappear

DC
Admin Off Offline

Quote
freeimage(id)

will try to remove the image which has the same ID as the player. This can work in some cases by coincidence but it's a bug in your script. "id" is always the player ID in this case because the cs2d lua hook say-hook sets it like this as it's the first parameter of the hooked function.

That you're assigning the result of cs2d lua cmd image to the "id"-variable has no effect for two reasons:
• it's just a local variable (value is lost as soon as the function ends) - see https://www.lua.org/pil/4.2.html
• as described above the hook sets the value to the player ID when opening the function

What you actually would have to do is creating a global array and saving the image ID of the hat image per player.

There are like 1000 hat scripts in the file archive. Take a look there.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview