Hud Draw - Using Variables to change an element

Post your scripting questions / solutions here

Moderator: Moderators

Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Hud Draw - Using Variables to change an element

Post by Ski »

I am kind of new at this level of scripting.

What I am trying to do is create a "push meter". What I would like it to do is change based on a trigger. The trigger will control spawn points and what shows on the hud.

All I have so far is the hud that I want to use for the start of the map. I do not know how to script in the variable part of the script to change it. I would apperciate any help you all have to offer.

I want to change the loadingbar shader.

Here is what I have:

huddraw:
while (1)
{
huddraw_alpha 25 1
huddraw_align 25 left bottom
huddraw_rect 25 298 -110 180 16
huddraw_shader 25 "textures/hud/healthmeter"
huddraw_alpha 26 1
huddraw_align 26 left bottom
huddraw_rect 26 298 -110 90 16
huddraw_shader 26 "textures/mohmenu/loadingbar"
huddraw_alpha 27 1
huddraw_align 27 left bottom
huddraw_rect 27 296 -110 185 18
huddraw_shader 27 "textures/mohmenu/loadingbar_border"
huddraw_alpha 28 1
huddraw_align 28 center
huddraw_font 28 "facfont-20"
huddraw_color 28 0.70 0.60 0.05
huddraw_rect 28 -95 200 100 20
huddraw_string 28 "Axis"
huddraw_alpha 29 1
huddraw_align 29 center
huddraw_font 29 "facfont-20"
huddraw_color 29 0.70 0.60 0.05
huddraw_rect 29 140 200 100 20
huddraw_string 29 "Allies"
huddraw_alpha 30 1
huddraw_align 30 center
huddraw_font 30 "facfont-20"
huddraw_color 30 0 1 0
huddraw_rect 30 0 180 100 20
huddraw_string 30 "Push Meter"
wait 1
}
end

It puts my push meter on the screen, but now I need to figure out how to change it.

Thanks
Ski
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

You can use huddraw_shader with any variable for index and shader... what exactly is your problem?
Image
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

Not sure what you mean.

Maybe I didn't explain it good enough. The script above just places my push meter on the screen at the start of the map like I want it....

But as triggers get activated I want to change the huddraw_rect size of the loadingbar shader... say for example the allies advance and set off a spawn trigger... I want the shader to become smaller... 298 -110 80 16 opposite if the axis advance... 298 -110 100 16 it would become bigger.

I don't know how to setup a variable to do this.

My thought is something like the health bar does when you get shot... and then goes back when you pick up health.

But I have no clue how to set it up to work with a variable.

Thanks
Ski
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

well, in ur script there ought to be a thread where the spawn points are reset. There u can set a variable level.barlength. It could be done by something like

Code: Select all

if (allies get further) //this is no working code of course
{
local.alliedprogress++
}
if (axis get further) //this is no working code of course
{
local.alliedprogress--
}
level.barlength = 90 + local.alliedprogress * 10
The variable local.alliedprogress would be 0 on startup and would raise when allies progress and get negative when axis become better. Something like that... Anyway, this variable u can use in the huddraw command like

Code: Select all

huddraw_rect 26 298 -110 level.barlength 16
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

Could I use triggers to change the level.barlength??

I have triggers to change the spawn points. Can I add a line to the spawn change thread to set level.barlength + 10 or something

Ski
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

Ski wrote:Could I use triggers to change the level.barlength??

I have triggers to change the spawn points. Can I add a line to the spawn change thread to set level.barlength + 10 or something

Ski
yes sure. just give it a try, the script won't bite :wink:
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post by Grassy »

Yeah as Wacko says, the looping thread can keep an eye on your spawn triggers. Do the triggers need to determine the team a player belongs to if they touch it? I am assuming they are trigger_multiples...
An ambiguous question will get a similar answer...
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

Yes the triggers do determine the players team.

for example: here is one of the triggers

Code: Select all

///Spawn Trigger 1.. allies pushing axis back - 1st change

   local.trig = spawn trigger_multiple "targetname" "allies1"
   local.trig.origin = ( 1216 -211 -255 ) // position it
   local.trig setsize ( 0 -5 0) ( 1 50 200) // give it some size
   local.trig setthread spawnchange1
   local.trig wait 1
   local.trig delay 0 // How long before trig acts

//this is the spawnchange1 thread

/// allies pushing axis back 1st change

spawnchange1:

local.player = parm.other
if ( local.player.dmteam=="allies" )
{

$allied1 disablespawn
$allied2 disablespawn
$allied3 disablespawn
$allied4 disablespawn
$allied5 disablespawn

$allied6 enablespawn
$allied7 enablespawn
$allied8 enablespawn
$allied9 enablespawn

$axis1 disablespawn
$axis2 disablespawn
$axis3 disablespawn
$axis4 disablespawn
$axis5 disablespawn

$axis6 enablespawn
$axis7 enablespawn
$axis8 enablespawn
$axis9 enablespawn

wait 1
}
end
But I am completely lost trying to get this Huddraw working right... everything I have tried bombs.

Ski
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

I was thinking of something like:

Code: Select all

spawnchange1: 
local.player = parm.other 
if ( local.player.dmteam=="allies" ) 
	{
	local.alliedprogress++ 
	for (local.i = 1; local.i <= 5; local.i++)
		{
		$("allied" + local.i) disablespawn
		$("allied" + (local.i + 5)) enablespawn
		$("axis" + local.i) disablespawn
		$("axis" + (local.i + 5)) enablespawn
		}
	wait 1 
	} 
if ( local.player.dmteam=="axis" ) 
	{ 
	local.alliedprogress-- 
	for (local.i = 1; local.i <= 5; local.i++)
		{
		$("allied" + local.i) enablespawn
		$("allied" + (local.i + 5)) disablespawn
		$("axis" + local.i) enablespawn
		$("axis" + (local.i + 5)) disablespawn
		}
	wait 1 
	}
level.barlength = 90 + local.alliedprogress * 10 
end 


huddraw:
...
huddraw_rect 26 298 -110 level.barlength 16
...
end
Dunno, though, whether this fits in ur script's logic, so take this just as an idea :wink: .
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post by Grassy »

The first problem I see is the multiple triggering of the trigger by players either standing on the trigger, or more than one player running through the trigger. How would you stop invalid increments? Disable the trigger until the axis trigger is set off?
An ambiguous question will get a similar answer...
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

I have about 12 triggers all over the map... 6 our allied triggers and 6 our axis triggers... Wacko Im not sure what you have will work... but I sure do appreaciate it. I think I maybe starting to get the idea of all of this... I would have to change all my triggers to use what you have... but if it works it will be worth the time. One question I have tho... If I am understanding this correctly the script disables the 1st 5 spawns and enables all spawns after number 5, or is it enabling the next 5 spawns??? so after this is triggered spawns 6 thru 10 would work??

Thanks
Ski
Last edited by Ski on Thu Mar 24, 2005 4:13 pm, edited 1 time in total.
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

Wacko wrote:I was thinking of something like:

Code: Select all

spawnchange1: 
local.player = parm.other 
if ( local.player.dmteam=="allies" ) 
	{
	local.alliedprogress++ 
	for (local.i = 1; local.i <= 5; local.i++)
		{
		$("allied" + local.i) disablespawn
		$("allied" + (local.i + 5)) enablespawn
		$("axis" + local.i) disablespawn
		$("axis" + (local.i + 5)) enablespawn
		}
	wait 1 
	} 
if ( local.player.dmteam=="axis" ) 
	{ 
	local.alliedprogress-- 
	for (local.i = 1; local.i <= 5; local.i++)
		{
		$("allied" + local.i) enablespawn
		$("allied" + (local.i + 5)) disablespawn
		$("axis" + local.i) enablespawn
		$("axis" + (local.i + 5)) disablespawn
		}
	wait 1 
	}
level.barlength = 90 + local.alliedprogress * 10 
end 


huddraw:
...
huddraw_rect 26 298 -110 level.barlength 16
...
end
Dunno, though, whether this fits in ur script's logic, so take this just as an idea :wink: .
Well I tried to add the code above to my script just to test it out and the bar disappeared from the huddraw completly. When I activated the trigger it did not show either.

I tired to add the this line to the huddraw script...
level.barlength = 90 + local.alliedprogress * 10

like this

Code: Select all

huddraw:
while (1)
{
level.barlength = 90 + local.alliedprogress * 10
huddraw_alpha 25 1
huddraw_align 25 left bottom
huddraw_rect 25 298 -110 180 16
huddraw_shader 25 "textures/hud/healthmeter"
huddraw_alpha 26 1
huddraw_align 26 left bottom
huddraw_rect 26 298 -110 level.barlength 16
huddraw_shader 26 "textures/mohmenu/loadingbar"
huddraw_alpha 27 1
huddraw_align 27 left bottom
huddraw_rect 27 296 -110 185 18
huddraw_shader 27 "textures/mohmenu/loadingbar_border"
huddraw_alpha 28 1
huddraw_align 28 center
huddraw_font 28 "facfont-20"
huddraw_color 28 0.70 0.60 0.05
huddraw_rect 28 -95 200 100 20
huddraw_string 28 "Axis"
huddraw_alpha 29 1
huddraw_align 29 center
huddraw_font 29 "facfont-20"
huddraw_color 29 0.70 0.60 0.05
huddraw_rect 29 140 200 100 20
huddraw_string 29 "Allies"
huddraw_alpha 30 1
huddraw_align 30 center
huddraw_font 30 "facfont-20"
huddraw_color 30 0 1 0
huddraw_rect 30 0 180 100 20
huddraw_string 30 "Push Meter"
wait 1
}
end
But it did not work either... my thought was I needed to set the initial level.barlength in the hud so it would show before trigger acted.. but bar doesn't show. What's wrong with the huddraw portion of this??

Thanks
Ski
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

I thought it to be like this:

Code: Select all

spawnchange1: 
local.player = parm.other 
if ( local.player.dmteam=="allies" ) 
	{
	local.alliedprogress++ 
	for (local.i = 1; local.i <= 5; local.i++)
		{
		$("allied" + local.i) disablespawn
		$("allied" + (local.i + 5)) enablespawn
		$("axis" + local.i) disablespawn
		$("axis" + (local.i + 5)) enablespawn
		}
	wait 1 
	} 
if ( local.player.dmteam=="axis" ) 
	{ 
	local.alliedprogress-- 
	for (local.i = 1; local.i <= 5; local.i++)
		{
		$("allied" + local.i) enablespawn
		$("allied" + (local.i + 5)) disablespawn
		$("axis" + local.i) enablespawn
		$("axis" + (local.i + 5)) disablespawn
		}
	wait 1 
	}
level.barlength = 90 + local.alliedprogress * 10 
end 

huddraw:
while (1)
{
huddraw_alpha 25 1
huddraw_align 25 left bottom
huddraw_rect 25 298 -110 180 16
huddraw_shader 25 "textures/hud/healthmeter"
huddraw_alpha 26 1
huddraw_align 26 left bottom
huddraw_rect 26 298 -110 level.barlength 16
huddraw_shader 26 "textures/mohmenu/loadingbar"
huddraw_alpha 27 1
huddraw_align 27 left bottom
huddraw_rect 27 296 -110 185 18
huddraw_shader 27 "textures/mohmenu/loadingbar_border"
huddraw_alpha 28 1
huddraw_align 28 center
huddraw_font 28 "facfont-20"
huddraw_color 28 0.70 0.60 0.05
huddraw_rect 28 -95 200 100 20
huddraw_string 28 "Axis"
huddraw_alpha 29 1
huddraw_align 29 center
huddraw_font 29 "facfont-20"
huddraw_color 29 0.70 0.60 0.05
huddraw_rect 29 140 200 100 20
huddraw_string 29 "Allies"
huddraw_alpha 30 1
huddraw_align 30 center
huddraw_font 30 "facfont-20"
huddraw_color 30 0 1 0
huddraw_rect 30 0 180 100 20
huddraw_string 30 "Push Meter"
wait 1
}
end
But err I didn't test it, so there might be a typo :oops: :wink:
For ur 2nd try, I can tell u, that local.variable just works inside one thread, in another thread it would be 0 again. So u would have to change local.alliedprogress to level.alliedprogress to make it a variable accessible for all threads.
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

Ok here is what I have now

For the Huddraw

Code: Select all

huddraw:
while (1)
{
local.viedisplay = level.alliedprogress * 10
local.barlength = 80 + local.viedisplay
huddraw_alpha 25 1
huddraw_align 25 left bottom
huddraw_rect 25 298 -110 180 16
huddraw_shader 25 "textures/hud/healthmeter"
huddraw_alpha 26 1
huddraw_align 26 left bottom
huddraw_rect 26 298 -110 local.barlength 16
huddraw_shader 26 "textures/mohmenu/loadingbar"
huddraw_alpha 27 1
huddraw_align 27 left bottom
huddraw_rect 27 296 -110 185 18
huddraw_shader 27 "textures/mohmenu/loadingbar_border"
huddraw_alpha 28 1
huddraw_align 28 center
huddraw_font 28 "facfont-20"
huddraw_color 28 0.70 0.60 0.05
huddraw_rect 28 -95 200 100 20
huddraw_string 28 "Axis"
huddraw_alpha 29 1
huddraw_align 29 center
huddraw_font 29 "facfont-20"
huddraw_color 29 0.70 0.60 0.05
huddraw_rect 29 140 200 100 20
huddraw_string 29 "Allies"
huddraw_alpha 30 1
huddraw_align 30 center
huddraw_font 30 "facfont-20"
huddraw_color 30 0 1 0
huddraw_rect 30 0 180 100 20
huddraw_string 30 "Push Meter"
wait 1
}
end
Which puts the meter up

In the spawns thread I added the line
level.alliedprogress = 1
to set it initally

Then in the spawntrigger1 I have this

Code: Select all

spawnchange1: 
local.player = parm.other 
if ( local.player.dmteam=="allies" ) 
   { 
   level.alliedprogress++ 
   for (local.i = 1; local.i <= 5; local.i++) 
      { 
      $("allied" + local.i) disablespawn 
      $("allied" + (local.i + 5)) enablespawn 
      $("axis" + local.i) disablespawn 
      $("axis" + (local.i + 5)) enablespawn 
      } 
   wait 1 
   } 
if ( local.player.dmteam=="axis" ) 
   { 
   level.alliedprogress-- 
   for (local.i = 1; local.i <= 5; local.i++) 
      { 
      $("allied" + local.i) enablespawn 
      $("allied" + (local.i + 5)) disablespawn 
      $("axis" + local.i) enablespawn 
      $("axis" + (local.i + 5)) disablespawn 
      } 
   wait 1 
   }  
end 
With this setup I have the bar moving... but as someone previously pointed out as long as the trigger is being activated the bar keeps growing and growing.

1st question... how do I disable the trigger after it is activated once??

What I would like to do is take the thread above and break it apart.. take the 1st portion.. if allies trigger it moves the bar up and deactivates until the axis trigger is used... that in turn would turn the 1st trigger back on. Hope you know what I mean.... and can help me out.

Thanks
Ski
Last edited by Ski on Thu Mar 24, 2005 9:54 pm, edited 1 time in total.
Ski
Lance Corporal
Posts: 24
Joined: Tue Dec 07, 2004 12:51 am

Post by Ski »

Grassy wrote:The first problem I see is the multiple triggering of the trigger by players either standing on the trigger, or more than one player running through the trigger. How would you stop invalid increments? Disable the trigger until the axis trigger is set off?
Yes I think that is what I need to do... any suggestions??

Ski
Post Reply