Forum

> > CS2D > Scripts > freeimage not removing images
Forums overviewCS2D overview Scripts overviewLog in to reply

English freeimage not removing images

No replies
To the start Previous 1 Next To the start

old freeimage not removing images

En-Kay
User Off Offline

Quote
Good evening,everyone!
I've been messing around with some scripts and i thought of recreating tf2 scout's drink, but instead of vulnerability, it increases speed for a short amount of time. when activated, it should play drinking sound and after 1 second speed buff will start with a nice blur like effect which is basically randomplayer.bmp image being constantly created behind player. Tested it and it works fine, although i believe there may be some bugs when a player dies at a certain point. Here is the problem: when blur images are created every 100ms, they change alpha to 0 with imagealpha, but they dont get removed since i haven't added freeimage because when i did, only last image gets removed. I guess freeimage recognises id of the last image created. How is this problem solved? Should i use timer instead of a 100ms hook?
Here is the 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
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
hasscoutjuice=initArray(32)
scout_juice_hud=initArray(32)
isbonkeffectactive=initArray(32)
bonk_effect_blur=initArray(32)

red_bonk_img_path="gfx/scout_juice/red_bonk.png"
blue_bonk_img_path="gfx/scout_juice/blue_bonk.png"
critacola_img_path="gfx/scout_juice/crit_a_cola.png"
bonk_effect_blur_path="gfx/player/randomplayer.bmp"

function scout_juice(id)  --SCOUT JUICE UNIVERSAL FUNCTION--
	if player(id,"team")==1 then
		if (sample.subclasses.class[id]==11) then
			scout_juice_hud[id]=image(red_bonk_img_path,75,650,2,id)
			imagescale(scout_juice_hud[id],0.45,0.45)
		elseif (sample.subclasses.class[id]==12) then
			scout_juice_hud[id]=image(critacola_img_path,75,650,2,id)
			imagescale(scout_juice_hud[id],0.45,0.45)
		end
	elseif player(id,"team")==2 then
		if (sample.subclasses.class[id]==11) then
			scout_juice_hud[id]=image(blue_bonk_img_path,75,650,2,id)
			imagescale(scout_juice_hud[id],0.45,0.45)
		elseif (sample.subclasses.class[id]==12) then
			scout_juice_hud[id]=image(critacola_img_path,75,650,2,id)
			imagescale(scout_juice_hud[id],0.45,0.45)
		end
	end
end

addhook("say","scout_juice_activate")
function scout_juice_activate(id,txt)
	if hasscoutjuice[id]==1 then
		if (txt=="special") then
			if (sample.subclasses.class[id]==11) then
				hasscoutjuice[id]=0
				bonk_effect_inittimer(id)
			end
		end
	end
end
				
function bonk_effect_inittimer(id)  --A FUNCTION THAT ACTIVATES INITIAL TIMER (1 SECOND FOR CAN OPEN EFFECT)--
timer(1000,"bonk_effect_maintimer",id)
end

function bonk_effect_maintimer(id)  --A FUNCTION THAT ACTIVATE MAIN TIMER (EFFECT DURATION AND RECHARGE)--
	id=tonumber(id)
	freeimage(scout_juice_hud[id])
	isbonkeffectactive[id]=1
	parse("speedmod "..id.." 20")
	timer(8000,"bonk_effect_end",id)
	timer(30000,"bonk_effect_recharge",id)
end

function bonk_effect_end(id)  --A FUNCTION THAT REMOVES THE BONK EFFECT--
	id=tonumber(id)
	isbonkeffectactive[id]=0
	parse("speedmod "..id.." 10")
end

function bonk_effect_recharge(id)  --A FUNCTION THAT RECHARGES BONK FOR USE--
	id=tonumber(id)
	hasscoutjuice[id]=1
	scout_juice(id)
end

addhook("ms100","bonk_effect_gfx")  --A FUNCTION THAT CREATES BLUR EFFECT--
function bonk_effect_gfx()
	for i=1,32,1 do
		if (sample.subclasses.class[i]==11) then
			if isbonkeffectactive[i]==1 then
				bonk_effect_blur[i]=image(bonk_effect_blur_path,player(i,"x"),player(i,"y"),0,i)
				imageblend(bonk_effect_blur[i],1)
				imagealpha(bonk_effect_blur[i],0.25)
				tween_rotate(bonk_effect_blur[i],1,player(i,"rot"))
				tween_alpha(bonk_effect_blur[i],400,0)
			end
		end
	end
end
	

function scout_ondeath_function(id)
	if sample.subclasses.class[id]==11 then
		if hasscoutjuice[id]==0 then
			if isbonkeffectactive[id]==1 then
				freetimer("bonk_effect_end",id)
				freetimer("bonk_effect_recharge",id)
				isbonkeffectactive[id]=0
			elseif isbonkeffectactive[id]==0 then
				freetimer("bonk_effect_recharge",id)
			end
		else
			freeimage(scout_juice_hud[id])
		end
	end
	if sample.subclasses.class[id]==12 then
		freeimage(scout_juice_hud[id])
	end
end

This is a part of classes.lua where i added subclasses to classes so you see sample.subclasses.
It is still wip and there are missing things. I'm doing it for practice and i would really appreciate any advice for the other parts written here if they could be written more efficiently. I thank you all very much and have a nice day!

EDIT:
So i fixed an error in die function by using object command to check if hud image exists or not so it can remove it. That way i eliminated the possibility of hud remaining when changing classes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function scout_ondeath_function(id)
	if object(scout_juice_hud[id],"exists")==true then
		freeimage(scout_juice_hud[id])
	end
	if sample.subclasses.class[id]==11 then
		if hasscoutjuice[id]==0 then
			if isbonkeffectactive[id]==1 then
				freetimer("bonk_effect_end",id)
				freetimer("bonk_effect_recharge",id)
				isbonkeffectactive[id]=0
			elseif isbonkeffectactive[id]==0 then
				freetimer("bonk_effect_recharge",id)
			end
		end
	end
end

EDIT #2:
Nevermind, figured it out.
edited 2×, last 21.04.20 01:55:04 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview