Forum

> > CS2D > General > Read : Freeimage Function Only Works Temporary !
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Read : Freeimage Function Only Works Temporary !

22 replies
Page
To the start Previous 1 2 Next To the start

old Read : Freeimage Function Only Works Temporary !

DaisukeOno
User Off Offline

Quote
Hello everyone, i have some bugs in my scripts. This is hats lua, i used "freeimage(id)" to remove old hat and wear new hat, but it's only works temporary. After that, i can't remove old hat ( freeimage function is not working again ), but i not change it ! Please Help
I don't know how to post image to show you what is the problem.
edited 1×, last 18.06.15 02:29:25 am

old Re: Read : Freeimage Function Only Works Temporary !

The Gajos
BANNED Off Offline

Quote
You need to store image id in table of player eg. hat[id] = image()
And after that when you want to remove hat: freeimage(hat[id]) hat[id] = nil

Don't forget remove hat when player leaves server
edited 1×, last 18.06.15 11:12:55 am

old Re: Read : Freeimage Function Only Works Temporary !

GeoB99
Moderator Off Offline

Quote
To take a screenshot read faq" How to take a screenshot? guide.
By the way there's not reason to post the screenshot, just copy the code of the lua hats script and post/paste it here.
Oh and also don't forget to post the code in the code tag by clicking the "Code" tag function near the other buttons like other tags,smiles,etc. in the left.

old @ZxC

DaisukeOno
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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
-------------------------------
-----     Player Menu     -----
-----     By Mommy123     -----
-------------------------------

addhook("serveraction","action")
addhook("menu","hats")
addhook("menu","list")
addhook("menu","bind")
addhook("menu","glow")
addhook("minute","ads")


function action(id,key)
if key == 1 then
	menu(id,"Player Menu,Add Hats,Add Bind,Add Glow,Close Menu")
	end
end



function list(id,title,button)
if title == "Player Menu" then
if button == 5 then
                parse ("setscore "..id.." ..0")
	parse ("setdeaths "..id.." ..0")
	elseif button == 1 then
	menu(id,"Add Hats,Angel,Bonnie Hat,Chapeu,Headcrab,Kid Hat,Santa Hat,Spear,Valentine Hat,Remove")                     	elseif button == 2 then
	menu(id,"Add Bind,Laser Sight,Flashlight,Arrow,Remove")
elseif button == 3 then
	menu(id,"Add Glow,Star,Heart,Circle,Remove")                                                                                                 
end
end
end

function hats(id,title,button)
if title == "Add Hats" then
if button == 1 then
	freeimage(id)
	id=image("gfx/player menu/hats/angel.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end
                        
 if button == 2 then
	freeimage(id)
	id=image("gfx/player menu/hats/bonnie.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end

if button == 3 then
	freeimage(id)
	id=image("gfx/player menu/hats/chapeu.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end

 if button == 4 then
	freeimage(id)
	id=image("gfx/player menu/hats/headcrab.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end

if button == 5 then
	freeimage(id)
	id=image("gfx/player menu/hats/kid.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end
if button == 6 then
	freeimage(id)
	id=image("gfx/player menu/hats/santa_hat.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end

if button == 7 then
	freeimage(id)
	id=image("gfx/player menu/hats/spear.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)
    
             end

if button == 8 then
	freeimage(id)
	id=image("gfx/player menu/hats/valentine.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1)

             end

if button == 9 then
	freeimage(id)
end
end
end


function bind(id,title,button)
if title == "Add Bind" then
if button == 1 then
	freeimage(id)
	id=image("gfx/player menu/bind/laser.png",1,1,200+id)
	imagealpha(id1,1.0)
	imageblend(id,1.5)

             end

if button == 2 then
	freeimage(id)
	id=image("gfx/player menu/bind/flashlight.png",1,1,200+id)
	imagealpha(id,0.5)
	imageblend(id,1)

             end

if button == 3 then
	freeimage(id)
	id=image("gfx/player menu/bind/arrow.png",1,1,200+id)
	imagealpha(id,1,1.0)
	imageblend(id,1)

             end

if button == 4 then
	freeimage(id)
end
end
end

function glow(id,title,button)
if title == "Add Glow" then
if button == 1 then
	freeimage(id)
	id=image("gfx/player menu/glow/star.png",0,0,100+id)
	imagealpha(id,0.3)
	imageblend(id,1)

             end

if button == 2 then
	freeimage(id)
	id=image("gfx/player menu/glow/heart.png",0,0,100+id)
	imagealpha(id,0.3)
	imageblend(id,1)

             end

if button == 3 then
	freeimage(id)
	id=image("gfx/player menu/glow/circle.png",0,0,100+id)
	imagealpha(id,0.3)
	imageblend(id,1)

             end

if button == 4 then
	freeimage(id)
end
end
end

-----------------------------------
---     Sorry For Spamming      ---
-----------------------------------
--- Don't Remove This Function  ---
-----------------------------------

function ads()
	msg("©000255000Press F2 To Open Player Menu !")
	msg("©255000255Scripts By Mommy123 !")
end
So You know what need i do ?
Well... this is not 100% only hat mod, i add bind and glow image feature.

Note : For everyone see this my lua. don't copy and claim it your scripts. If you do that, better hope you will be not banned. if you want... just download and like, this opened coming soon. ( of crouse after i can fix the bug )
edited 1×, last 17.06.15 12:31:16 pm

old @Yuki Usagi

DaisukeOno
User Off Offline

Quote
Sorry, Don't write not important text, just tell to me how to fix this bug !

old Re: Read : Freeimage Function Only Works Temporary !

Rainoth
Moderator Off Offline

Quote
Your code with mistakes marked. Read it and correct them! >

I've posted a fixed code but I want you to try fixing the mistakes I pointed out if you want to improve.
If you don't do it I can tell you what will happen. You will ask once. You will ask twice. You will ask 3, 4, 5 times. Finally, we will all get pissed and you will no longer get any help. So it's best to learn from mistakes.
Don't worry, if you don't understand something, read my code or ask us here, we'll explain. Just don't expect that we'll do everything for you
Here's the code I've looked through and edited >

Please note that there's a ton of ways that you can optimize it but you probably wouldn't understand what I've done so I didn't do it.

Good luck
edited 1×, last 17.06.15 01:54:34 pm

old Re: Read : Freeimage Function Only Works Temporary !

Dousea
User Off Offline

Quote
user Dousea to the rescue!
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
-- This variable is to store the image.
-- You didn't store the image so technically you can't remove the image.
playerimage = {}

for id = 1, 32 do
	playerimage[id] = {}
end

function removeimage(index)
	if (playerimage[id][index]) then
		freeimage(playerimage[id][index])
		
		playerimage[id][index] = nil
	end
end

for index, hook in pairs({"serveraction", "menu", "minute"}) do
	addhook(hook, hook .. "hook")
end

function serveractionhook(id, action)
	if (action == 1) then
		menu(id, "Player Menu,Add hat,Add bind,Add glow") -- "Close Menu" button is really useless
	end
end

function menuhook(id, title, button)
	if (title == "Player Menu") then
		-- There's no button 5 in your menu. "Close Menu" is button 4.
		if (button == 1) then
			menu(id, "Add Hat,Angel,Bonnie Hat,Chapeu,Headcrab,Kid Hat,Santa Hat,Spear,Valentine Hat,Remove hat")
		elseif (button == 2) then
			menu(id, "Add Bind,Laser Sight,Flashlight,Arrow,Remove bind")
		elseif (button == 3) then
			menu(id, "Add Glow,Star,Heart,Circle,Remove glow")
		end
	elseif (title == "Add Hat") then
		if (button ~= 0) then
			removeimage("hat")
		end
		
		local hat = {"angel", "bonnie", "chapeu", "headcrab", "kid", "santa_hat", "spear", "valentine"}
		
		if (button >= 1 and button <= 8) then
			playerimage[id].hat = image("gfx/player menu/hats/" .. hat[button] .. ".png", 1, 1, 200 + id)
		end
	elseif (title == "Add Bind") then
		if (button ~= 0) then
			removeimage("bind")
		end
		
		local bind = {"laser", "flashlight", "arrow"}
		
		if (button >= 1 and button <= 3) then
			playerimage[id].bind = image("gfx/player menu/bind/" .. bind[button] .. ".png", 1, 1, 200 + id)
		end
	elseif (title == "Add Glow") then
		if (button ~= 0) then
			removeimage("glow")
		end
		
		local glow = {"star", "heart", "circle"}
		
		if (button >= 1 and button <= 3) then
			playerimage[id].glow = image("gfx/player menu/glow/" .. glow[button] .. ".png", 1, 1, 200 + id)
		end
	end
end

function minutehook()
	msg("\169000255000Press F2 to open Player Menu!")
	msg("\169255000255Script originally by Mommy123..")
	msg("\169255000255because all issues have been fixed by Cozen!")
end
That code may work. I didn't test it though. And guess what, ~58% of original lines have been saved.
edited 1×, last 17.06.15 02:22:48 pm

old @Rainoth & Cozen

DaisukeOno
User Off Offline

Quote
Rainoth :

Thanks, Free Image Function problem was fixed, i happy. But, you make new problem : The hats image is glowing too, i want my hats in solid color. I only want glowing color for bind ( Add bind ) and glow image ( Add glow ).
Can you fix it ? if you can. It will give you big thanks and gift ( Don't tell me what is the gift, you will be know soon )
Please help !

Cozen :

That's did not working. The menu is not show up, but thanks to help !

old @Cozen

DaisukeOno
User Off Offline

Quote
Quote
He/she will copy it anyway without understanding it.


> I am boy, with "Squid Girl" profile image.
> I Understand it, you know ? i not beginner. i study how to make lua scripts before i have USGN account.
> My amazing scripts is Multigame lua scripts, i will be use it for my custom server coming soon ! make multigame lua scripts is does not easy.

Admin/mod comment

Fixed your bad use of tags /user Rainoth

old Re: Read : Freeimage Function Only Works Temporary !

Rainoth
Moderator Off Offline

Quote
@user DaisukeOno: That's because you're using
1
imageblend
with mode 1 which is "light". I do not know what you need exactly so I can't fix it perfectly without additional info. Now that you said it, just remove line 66 in my code.

// If what you say is true then me and user Dousea have nothing to worry about. I advise to read user Dousea's code as it's more advanced than mine but a bit harder to read.

@user Dousea: What is that last message ? I couldn't grasp the grammar of it, only the meaning.

/// @user DaisukeOno: This is a bit OT but your "Squid Girl" avatar is low quality. You might want to find a better image.
edited 2×, last 17.06.15 02:42:34 pm
To the start Previous 1 2 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview