English Gfx disappear

1 reply
Goto Page
To the start Previous 1 Next To the start
22.05.21 04:09:04 pm
Up
NanuPlayer
User
Offline Off
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 :
Code:
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
Bad Life
22.05.21 05:01:42 pm
Up
DC
Admin
Online On
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
To the start Previous 1 Next To the start