Forum

> > CS2D > Scripts > Script not working!
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Script not working!

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Script not working!

NanuPlayer
User Off Offline

Zitieren
Hi guys i taked this code from user Zeik

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
function new_players_array()
  local players = {}
  for id=1,32 do
    players[id] = {image = nil} -- player's "properties"
  end
  return players
end

players = new_players_array()

addhook("say","anything")
function anything(id, txt)
  
  local player = players[id]
  
  if (txt=="!hat") then
    if player.image then
      freeimage(player.image)
      player.image = nil
    end
    player.image = image("gfx/hats_menu/hat1.png",1,1,200+id)
    return 1
  end
  
  if (txt=="!hat2") then
    if player.image then
      freeimage(player.image)
      player.image = nil
    end
    player.image = image("gfx/hats_menu/hat2.png",1,1,200+id)
    return 1
  end
  
end

And it won't remove the hat after adding a new one! so any one of you guys have any other codes for removing hats?

alt Re: Script not working!

Yates
Reviewer Off Offline

Zitieren
1
local player = players[id]

*sigh*

Don't "override" functions (cs2d lua cmd player) or use the same name for your own variables.

The problem is because you're using the local
player.image
and not changing the main
players
variable used to keep track of images.
2× editiert, zuletzt 16.05.18 11:53:51

alt Re: Script not working!

NanuPlayer
User Off Offline

Zitieren
@user Yates:

I edited Zeik code and here is mine:

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function new_players_array()
  local players = {}
  for id=1,32 do
    players[id] = {image = nil} -- player's "properties"
  end
  return players
end

players = new_players_array()

addhook('serveraction', 'mainmenu')
function mainmenu(id,action)
if ( action == 1 ) then
menu(id,"Hats,Hat #1|FREE,Hat #2|FREE,Hat #3|FREE,Hat #4|FREE,Hat #5|FREE,Hat #6|FREE,Hat #7|FREE,Hat #8|FREE")
end
end

addhook("menu", "mainmenu2")
function mainmenu2(id, title, but)
  local player = players[id]
if title == "Hats" then
if (but==1) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/1.png",1,1,200+id)
return 1
end
if (but==2) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/2.png",1,1,200+id)
    return 1
end
if (but==3) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/3.png",1,1,200+id)
    return 1
end
if (but==4) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/4.png",1,1,200+id)
    return 1
end
if (but==5) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/5.png",1,1,200+id)
    return 1
end
if (but==6) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/6.png",1,1,200+id)
    return 1
end
if (but==7) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/7.png",1,1,200+id)
    return 1
end
if (but==8) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
	  end
id=image("gfx/hats_menu/8.png",1,1,200+id)
    return 1
end
end
end

Still not working...

alt Re: Script not working!

Yates
Reviewer Off Offline

Zitieren
Here:
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
addhook("say","anything")
function anything(id, txt)

    if (txt=="!hat") then

        if players[id].image then
            freeimage(players[id].image)
            players[id].image = nil
        end

        players[id].image = image("gfx/hats_menu/hat1.png",1,1,200+id)
        return 1
    end

    if (txt=="!hat2") then

        if players[id].image then
            freeimage(players[id].image)
            players[id].image = nil
        end

        players[id].image = image("gfx/hats_menu/hat2.png",1,1,200+id)
        return 1
    end
end

Edit this.

alt Re: Script not working!

NanuPlayer
User Off Offline

Zitieren
@user Yates:

It's works but with this no

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function new_players_array()
  local players = {}
  for id=1,32 do
    players[id] = {image = nil} -- player's "properties"
  end
  return players
end

players = new_players_array()

addhook('serveraction', 'mainmenu')
function mainmenu(id,action)
if ( action == 1 ) then
menu(id,"Hats,Hat #1|FREE,Hat #2|FREE,Hat #3|FREE,Hat #4|FREE,Hat #5|FREE,Hat #6|FREE,Hat #7|FREE,Hat #8|FREE")
end
end

addhook("menu", "mainmenu2")
function mainmenu2(id, title, but)
  local player = players[id]
if title == "Hats" then
if (but==1) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/1.png",1,1,200+id)
return 1
end
if (but==2) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/2.png",1,1,200+id)
    return 1
end
if (but==3) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/3.png",1,1,200+id)
    return 1
end
if (but==4) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/4.png",1,1,200+id)
    return 1
end
if (but==5) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/5.png",1,1,200+id)
    return 1
end
if (but==6) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/6.png",1,1,200+id)
    return 1
end
if (but==7) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/7.png",1,1,200+id)
    return 1
end
if (but==8) then
   if ( player.image ) then
      freeimage(player.image)
      player.image = nil
       end
id=image("gfx/hats_menu/8.png",1,1,200+id)
    return 1
end
end
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht