Identifiying a particular player to use a trigger use

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Waylander76
Sergeant Major
Posts: 122
Joined: Wed Jun 01, 2005 10:03 am

Identifiying a particular player to use a trigger use

Post by Waylander76 »

Basically the allies need to steal a crate and put it onto a truck.
For this I have two threads

the first checks to see if it is an Ally that has triggered the trigger and sets
the local.player to local.thief.
This seems to work fine.

Code: Select all


crate: 

$crate_trigger waittill trigger 
local.player = parm.other 
if (local.player.dmteam == "axis") 
{ 
print "You must protect the crate not steal it!!" 
goto crate 
} 
if (local.player.dmteam == "allies") 
{ 
$crate hide 
$crate_trigger nontriggerable 
iprintlnbold_noloc "The crate has been stolen!" 
level.allies_have_crate++ 
local.player = local.thief 
while (level.allies_have_crate>0) 
{ 
if (! isAlive local.thief ) 
{ 
level.allies_have_crate-- 
$crate show 
$crate_trigger triggerable 
break 
} 
wait 1 
} 
} 
} 
end 

The problem is when it is comes to putting the crate on the truck.
Obviously I want the player who got the crate ( local.thief )
to be the only one who can use the trigger.
this is the thread I have but it doesn't seem to recognise the local.thief
and therefore the crate doesn't appear on the back of the truck.
If I remove the check for local thief anyone can trigger the truck_trigger
and it all works.

Code: Select all

$truck_trigger waittill trigger 

local.player = parm.other 
if (local.player.dmteam == "axis") 
{ 
print "You cannot use this!!" 
goto truck 
} 
if (local.player.dmteam == "allies") 
{ 
iprintlnbold_noloc "You do not have the crate!!" 
goto truck 
} 
if (local.player.dmteam == "allies") &&  (level.allies_have crate == 1 ) && (Isalive local.thief) 
{ 

$truck play loopsound opeltruck_snd_idle 
$crate_on_truck show 
iprintlnbold_noloc "The Truck is escaping!" 
$truck anim idlelights 
$truck stop loopsound 

while ($truck.health > 0) 
{ 
$truck drive $truckwap1 
$truck start loopsound opeltruck_snd_run 
$truck waittill drive 
$truck stop   
$truck stop loopsound   
level.targets_destroyed ++   
thread allies_win 
} 
if ($truck.health < 0) 
{ 
local.Exp2 = spawn animate/fx_explosion_tank.tik 
local.Exp2.origin = $truck.origin 
local.Exp2 anim start 
wait 1 
local.Exp2 anim stop 
local.Exp2 remove   
$truck remove 
truck_health == 500 
level.allies_have_crate-- 
$crate_on_truck hide 
$crate show 
$crate_trigger triggerable 
goto spawn_truck 
} 
} 
end 

Where am I going wrong??
How do I script it so it identifes the player who triggered the crate_trigger
to be the only player who can activate the truck trigger as long as
he is alive?
If he dies the crate reappears and has to be stolen again.

Thanks in advance
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

local

Post by tltrude »

The name "local" means the variable (local.theif) only works in the therad where it was assigned to a player. If another thread uses that same variable, it will not know what it is for -- unless the variable is transfered to that thread.

So, how do we transfer a local variable?

If we start the "truck" thread by calling it in the "crate" thread, it would look like this.

thread truck

But we can add this to it.

thread truck local.theif

Then we can add this to the name of the truck thread.

truck local.thief:

Now the variable can be used in the truck thread as well. However, there may be an easier way. Just make him "level.thief" and all threads will know who he is.

if (local.player == level.thief) // equals

or

if (local.player != level.thief) // does not equal

Hope that helps!
Tom Trude,

Image
Waylander76
Sergeant Major
Posts: 122
Joined: Wed Jun 01, 2005 10:03 am

Post by Waylander76 »

Tom thanks for explaing that...it does help but the script doesn't quite work :(

The crate thread is fine up until the while (level.allieshascrate>0)
The player who is the thief gets the message 'take the carte to the truck'
I'm not sure if it's working after that.

Code: Select all

/////////////////////////////
// Steal the crate        //
///////////////////////////

allies_get_crate:


$crate_trigger waittill trigger
local.player = parm.other
if (local.player.dmteam == "axis")
{
print "You must protect the crate!"
goto crate
}
if (local.player.dmteam == "allies")
{
$crate hide
$crate_trigger hide
$crate_trigger nottriggerable
iprintlnbold_noloc "The crate has been stolen!"
level.allieshascrate++
level.thief = local.player 
level.thief iprint "Take the crate to the truck!"

while (level.allieshascrate>0)
{
if (!isAlive level.thief )
{
level.allieshascrate--
$crate show
$crate_trigger show
$crate_trigger triggerable
break
}
wait 1
}
}
 
goto allies_get_crate
end
But the truck thread doesn't work

Code: Select all


truck:

$truck_trigger waittill trigger
local.player = parm.other
if (local.player.dmteam == "axis")
{
local.player iprint "You cannot use this!"
goto truck
}
if ((local.player.dmteam == "allies") && (level.allieshascrate == 1))
{
local.player iprint "You do not have the crate!"
goto truck
}
if ((local.player.dmteam == "allies") && (level.allieshascrate == 0))
{
local.player iprint "You do not have the crate!"
goto truck
}
if ((local.player == level.thief) && (level.allieshascrate == 1))
{
$truck_speaker stop loopsound
wait .1
$truck_speaker playsound opeltruck_snd_on
$crate_on_truck show
$crate_on_truck solid
$crate_on_truck bind $truck
//level.targets_destroyed++
iprintlnbold_noloc "The Truck is escaping!"
iprintlnbold_noloc "Stop the truck!!"
$truck removeimmune bullet
$truck removeimmune fast_bullet
$truck removeimmune mg
$truck vehicleanim idlelights
$truck.health = 1500
$truck_speaker loopsound opeltruck_snd_run
$truck thread truckdeath
$truck drive $truckwap1 
$truck waittill drive
$truck stop  
$truck_speaker stop loopsound  
end
}
end
The checks work apart from the one involving level.thief he gets the message "You do not have the crate!" and the crate doesn't appear on the truck.
the variable level.thief is not set anywhere previously should I be setting it
before the crate thread is run??
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

test

Post by tltrude »

Test this thread to see if the message pops up when you get the crate and then blow yourself up.

Code: Select all

///////////////////////////// 
// Steal the crate     // 
/////////////////////////// 

allies_get_crate: 

	$crate_trigger waittill trigger 
	local.player = parm.other 
	if (local.player.dmteam == "axis") 
		{ 
			local.player iprint "You must protect the crate!" 
			goto allies_get_crate
		} 
	if (local.player.dmteam == "allies") 
		{ 
			$crate hide 
			$crate_trigger nottriggerable 
			iprintlnbold_noloc "The crate has been stolen!"  
			level.thief = local.player
			level.thief iprint "Take the crate to the truck!" 
		
			while (1) 
				{ 
					if  !(isAlive level.thief ) 
						{ 
							$crate show
							$crate_trigger triggerable
							iprintlnbold_noloc "The crate thief has been killed!" 
							break 
						} 
					wait 1 
				}
		}
 
	goto allies_get_crate 
end 
In the truck thread, I think the line "local.player = parm.other" might be killing the "level.thief" variable. So, test this thread.

Code: Select all

truck: 

	$truck_trigger waittill trigger 
	local.player = parm.other 
		if (local.player != level.thief)
			{ 
				local.player iprint "You cannot use this!" 
				goto truck 
			}
		if (local.player == level.thief) 
			{ 
				$crate_on_truck show
				$crate_on_truck solid 
				$crate_on_truck bind $truck  
				level.thief iprint "The crate has been loaded!"
				$truck_speaker stop loopsound 
				wait .1 
				$truck_speaker playsound opeltruck_snd_on 
				//level.targets_destroyed++ 
				iprintlnbold_noloc "The Truck is escaping!" 
				iprintlnbold_noloc "Stop the truck!!" 
				$truck removeimmune bullet 
				$truck removeimmune fast_bullet 
				$truck removeimmune mg 
				$truck vehicleanim idlelights 
				$truck.health = 1500 
				$truck_speaker loopsound opeltruck_snd_run 
				$truck thread truckdeath 
				$truck drive $truckwap1 
				$truck waittill drive 
				$truck stop  
				$truck_speaker stop loopsound  
				end 
			}
iprintlnbold_noloc "You are not the level.thief!"  // debug line
end 
Tom Trude,

Image
Waylander76
Sergeant Major
Posts: 122
Joined: Wed Jun 01, 2005 10:03 am

Post by Waylander76 »

Tom...works perfectly :D Thank you
Post Reply