Forum

> > CS2D > Scripts > Stolen flag HUD image
Forums overviewCS2D overview Scripts overviewLog in to reply

English Stolen flag HUD image

5 replies
To the start Previous 1 Next To the start

old Stolen flag HUD image

En-Kay
User Off Offline

Quote
Ok here is the problem.I made a simple script which creates a hud image of a stolen flag:if red flag is stolen,a red flag image will appear for every player.It is removed when it is captured or when it is droped on the ground,but the problem is that the image is not created when player picks up dropped flag.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
addhook("flagtake","ftake")
function ftake (id,team)

	if player(id,"team")==1 then
		bflag=image("gfx/weapons/blueflag.bmp<m>" ,20,380,2)
	else
		rflag=image("gfx/weapons/redflag.bmp<m>" ,50,380,2)
	end
end

addhook("flagcapture","fcap")
function fcap (id,team)
	
	if player(id,"team")==1 then
		freeimage(bflag)
	else
		freeimage(rflag)
	end
end

addhook("kill","fdrop")
function fdrop (killer,victim)

	if player(victim,"flag")==true then
		if player(victim,"team")==1 then
			freeimage(bflag)
		else
			freeimage(rflag)
		end
	end
end

addhook("collect","fcollect")
function fcollect (id,iid)

	if player(id,"team")==1 then
		if iid==71 then
			bflag=image("gfx/weapons/blueflag.bmp<m>" ,20,380,2)
		else
			return 0
		end

	elseif player(id,"team")==2 then
		if iid==70 then
			rflag=image("gfx/weapons/redflag.bmp<m>" ,50,380,2)
		else
			return 0
		end
	end
end

old Re: Stolen flag HUD image

_oops
User Off Offline

Quote
at the line 4 , try this but I'm not sure
1
if (team == 1) then
and i think you should use cs2d lua hook die instead of cs2d lua hook kill
1
2
3
4
5
6
7
8
addhook("die","fldrp")
function fldrop(id)
  if player(id,"flag")== true and player(id,"team") == 1 then
freeimage(bflag)
elseif player(id,"flag")== true and player(id,"team")== 2 then
freeimage(rflag)
end
end

old Re: Stolen flag HUD image

En-Kay
User Off Offline

Quote
The code you wrote works,but the problem is with collect hook.So when the flag is dropped,image is removed.When someone picks it up,it should pop out again but it doesn't.

old Re: Stolen flag HUD image

Rainoth
Moderator Off Offline

Quote
Didn't look too much into it but I'd like to ask why you need values like
1
bflag=image("gfx/weapons/blueflag.bmp<m>" ,20,380,2)
20 and 380? It does not set position of the images, just changes how it draws the image so 0-1 is fine.

old Re: Stolen flag HUD image

En-Kay
User Off Offline

Quote
Well if I change those values,image will appear elsewhere.What i'm trying to say is that this is a hud image.It pops up when someone steals a flag so everyone knows the flag is missing.When the carrier dies,he drops the flag and the hud image is removed.When someone picks up dropped flag,the image that the flag is stolen should pop out again,but it doesn't.That is the problem.Let's just stick to this part of the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("collect","fcollect")
function fcollect (id,iid)

     if player(id,"team")==1 then
          if iid==71 then
               bflag=image("gfx/weapons/blueflag.bmp<m>" ,20,380,2)
          else
               return 0
          end

     elseif player(id,"team")==2 then
          if iid==70 then
               rflag=image("gfx/weapons/redflag.bmp<m>" ,50,380,2)
          else
               return 0
          end
     end
end
edited 1×, last 28.08.14 09:45:20 am

old Re: Stolen flag HUD image

Rainoth
Moderator Off Offline

Quote
Uhm, you messed up the arguments.
1
function fcollect(playerID,object_ID_for_that_item,item_type_ID)

What you need is item_type_ID.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview