Forum

> > CS2D > Scripts > wrong freeimage
Forums overviewCS2D overview Scripts overviewLog in to reply

English wrong freeimage

5 replies
To the start Previous 1 Next To the start

old wrong freeimage

En-Kay
User Off Offline

Quote
Hi.I have problem.I made this script so when i collect defuse kit,I get mroe speed and a flare like a buff.But the problem is with freeimage.When I die,the flares on all players who have this buff are removed.Please help me solve this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook ("collect","buffbanner")
function buffbanner(id,iid,type,ain,a,mode)

	if player(id,"team")==2 then
		if type==56 then
			parse ("speedmod "..id.." 15")
			buff = image("gfx/sprites/flare2.bmp",0,0,id+100)
			imagecolor(buff,0,0,255)
			imageblend(buff,1)
			imagealpha(buff,0.5)
		end
	end
end

addhook ("die","buffremove")
function buffremove(victim,killer,weapon,x,y)

	freeimage(buff)
end

old Re: wrong freeimage

En-Kay
User Off Offline

Quote
Actually,image doesn't delete on all player.But i want to make it delete on player who died.

old Re: wrong freeimage

Tobey
User Off Offline

Quote
You need to make up a single picture for each player. for-loops would help you greatly doing this.

old Re: wrong freeimage

En-Kay
User Off Offline

Quote
Can you show me how to do this?I'm actually terrible at modding.(except for the eaasy ones)

old Re: wrong freeimage

EngiN33R
Moderator Off Offline

Quote
Here's commented code that should work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
buff = {} -- This is the table we created, and it will contain data about images for each player

addhook ("collect","buffbanner")
function buffbanner(id,iid,type) -- You don't have to declare every argument, by the way - just the ones you need

     if player(id,"team")==2 then
          if type==56 then
               parse ("speedmod "..id.." 15")
               buff[id] = image("gfx/sprites/flare2.bmp",0,0,id+100) -- Now we don't assign the image ID to the buff variable, but insert it into the buff table
               imagecolor(buff[id],0,0,255) -- And reference it like so from now on
               imageblend(buff[id],1)
               imagealpha(buff[id],0.5)
          end
     end
end

addhook ("die","buffremove")
function buffremove(victim) -- Same here

     freeimage(buff[victim]) -- I assume the victim's image has to go?
     buff[victim] = nil -- Puts less strain on the server
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview