Trigger Help!

Discussions about Coding and Scripting
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Trigger Help!

Post by 'Zac »

I'm trying to create a trigger that says the person that triggered it on a map. I know that weapons have a similar function that I would think should be the same with triggers like %k and %o. I tried a lot of different combinations of letters to %a to %z and everything, but can't find the right variable. Is there one that can be shown? Do I need to create a trigger from scratch and create function that do this sort of thing? Thank to anyone that can help...
Prophunt for UT99!!!
Image
Github
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

I find that when you need something like this the best way to work it out is to find the closest existing 'thing' that does what I want to do. You need a player's real name so where is that used already? I'd go look at scoreboard, since it lists everyone. The code there ought to help you see what you need.

So here's a section out of TournamentScoreBoard:
function DrawNameAndPing(Canvas Canvas, PlayerReplicationInfo PRI, float XOffset, float YOffset, bool bCompressed)
{
local float XL, YL, XL2, YL2, XL3, YL3;
local Font CanvasFont;
local bool bLocalPlayer;
local PlayerPawn PlayerOwner;
local int Time;

PlayerOwner = PlayerPawn(Owner);

bLocalPlayer = (PRI.PlayerName == PlayerOwner.PlayerReplicationInfo.PlayerName);
Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);

<clipped some code>

Canvas.SetPos(Canvas.ClipX * 0.1875, YOffset);
Canvas.DrawText(PRI.PlayerName, False);
So now you know how to draw someone's real player name (as opposed to their player slot number). Now you just create your own subclass of trigger that spits out the instigator but does it by saying the player's name.

Bonus points if you script it so there are no errors when it is triggered by a bot (who won't have a player name).

<If you are still lost, just reply and I'll keep helping you. Some of this stuff is a bit confusing at first. You can do it though! >
So long, and thanks for all the fish
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Trigger Help!

Post by Chamberly »

I had went through something similar what Zac was looking for. I just had to add specialevent, and trigger to make it work, changes some blank line to some message so it'll work.

But the above... I just don't get it. We are newbie mappers... lol.
Image
Image
Image Edit: Why does my sig not work anymore?
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

No need to make a trigger, make an event target instead.

Trigger Actor:
Touch( Other) > Checks valid touch (player?, bot?) > Loops all actors with matching tag > Call Trigger( Other, self) function on them.

Trigger function is defined like this:

Code: Select all

event Trigger( actor Other, pawn EventInstigator )
Yes, you KNOW what pawn touched the trigger, and what trigger was touched.

SpecialEvent actor has this trigger function:

Code: Select all

function Trigger( actor Other, pawn EventInstigator )
{
	local pawn P;
	if( bBroadcast )
		BroadcastMessage(Message, true, 'CriticalEvent'); // Broadcast message to all players.
	else if( EventInstigator!=None && len(Message)!=0 )
	{
		// Send message to instigator only.
		EventInstigator.ClientMessage( Message );
	}
}
That's what SpecialEvent does, now focus on BroadcastMessage function.

Code: Select all

event BroadcastMessage( coerce string Msg, optional bool bBeep, optional name Type )
> 'CriticalEvent' message type as seen in the example displays a big UT onscreen message.
> When calling BroadcastMessage with only the message argument you get a typical white message on player's consoles.
Whatever does what you want, use that.

Create your custom actor (subclass it from either KeyPoint, Triggers, Info).
Define your custom trigger event where you:
> Check that EventInstigator is a valid player.
> Check that you have a valid string message defined (create a new variable).
> Replace a wildcard string (example: "%p") with said EventInstigator's name (above post shows you how to do that, make sure that PlayerReplicationInfo exists as well)
> Broadcast the message.
> Insert your new actor in map and specify the message to broadcast.



TRIVIA:
Mappers make the common mistake of putting a trigger next to a Kicker to play a sound... Kickers ARE triggers and do call events as well, you don't even need the trigger in the first place.
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: Trigger Help!

Post by 'Zac »

Thanks for the help guys, I was thinking about creating another trigger actor instead anyway.

Edit--------------------- by papercoffee

To check if the eventinstigator is a player, how the hell do i do that? Do I need to create a bool to show if the class is a player or not?
Prophunt for UT99!!!
Image
Github
User avatar
Sp0ngeb0b
Adept
Posts: 376
Joined: Wed Feb 13, 2008 9:16 pm
Location: Cologne
Contact:

Re: Trigger Help!

Post by Sp0ngeb0b »

Code: Select all

if(EventInstigator.isA('PlayerPawn') || EventInstigator.isA('Bot')) {

}
Website, Forum & UTStats

Image
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: Trigger Help!

Post by 'Zac »

Oh thanks Spongebob! Forgot about the isA part.

Edit---------------------- by papercoffee

I got to the point where it checks if the instigator is a player and created a string message variable but I do not understand what you mean by
" Replace a wildcard string (example: "%p") with said EventInstigator's name "
The hell is a wildcard string?
Prophunt for UT99!!!
Image
Github
User avatar
papercoffee
Godlike
Posts: 10447
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Trigger Help!

Post by papercoffee »

Please avoid double posts!
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

Post your current code so far and we'll feed you the next line.
So long, and thanks for all the fish
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: Trigger Help!

Post by 'Zac »

Yes, sorry about the multiple posts at once.

I don't think I have it correct, a

var() localized string Message;
var() bool bBroadcast;

function Trigger( actor Other, pawn EventInstigator )
{
local pawn P;
if( bBroadcast )
BroadcastMessage(Message, true, 'CriticalEvent'); // Broadcast message to all players.
else if( EventInstigator!=None && len(Message)!=0 )
{
// Send message to instigator only.
EventInstigator.ClientMessage( Message );
}
}

event BroadcastMessage( coerce string Message, optional bool bBeep, optional name Type )
{
local PlayerPawn %p;
if(EventInstigator.isA('%p')
{

This is all the code that it's in it so far. I do not know what to put after the last line with the instigator and the playerpawn check.
Prophunt for UT99!!!
Image
Github
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

First off, what are you coding with? Second, post code in code tags. Third, you are getting it, don't give up.

Here's what I would consider doing:

Code: Select all

var() localized string Message;
var() bool bBroadcast;

function Trigger( actor Other, pawn EventInstigator )
{
	local pawn P;
	
	if( bBroadcast )
	
	if (EventInstigator != none)
	{
		if(EventInstigator.isA('PlayerPawn'))  //Spongebob's :)
		{
			BroadcastMessage(EventInstigator.PlayerReplicationInfo.PlayerName @ " " @ Message, True); //false will turn off the message beep
		}
		else if(EventInstigator.isA('Bot'))
		{
			BroadcastMessage(EventInstigator.XXXXXX.XXXXXX @ " " @ Message, True); //false will turn off the message beep
		}
	}
}
I added the wrapper ( !=none ) to prevent any access nones. These happen with triggers a lot. Anyway see how it triggers a global message when hit? I removed the individual message because you don't need it. I left the bot section for you to fill in with the proper information. You had the right idea but you are overthinking things (something I am incredibly prone to doing also). Remember the motto of UScript: Keep it as simple as possible. It's a very old engine and we ask only as much of it as we have to.

Edit: added the space in the broadcast message line so there is a proper space between name and message. Otherwise it might read:

Code: Select all

gopostalhas opened the portal!
The space will make it read:

Code: Select all

gopostal has opened the portal! 
So long, and thanks for all the fish
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: Trigger Help!

Post by 'Zac »

Thanks Jack!
I code with notepad...sadly. I have a visual studio c++ but you need to download a lot of nonsense to code with uscript.

I'm starting to understand this actually I can read right through it lol, but do the bots use the PlayerReplicationInfo like human players do? I've seen in the default gametype codes and it's used a lot in them for bots that I see so I don't know why you put the Xs there.

I can see that when you use the @ it puts the PLayerName -a space- then the message to broadcast, right?

EDIT: When I compile it, I get a weird error that I've never seen before.

Warning, ReadToken: Bad quoted string
It says that this error twice, at the last brace } and at the beginning of my defaultproperties.
I googled it but nothing good came up. Any idea?

Thanks for the help Jack, as you can see I'm an amateur :P
Prophunt for UT99!!!
Image
Github
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

codingschool.7z
(1.51 MiB) Downloaded 66 times
Download, follow directions, install, use. ConTEXT is a good UScript tool and the included compiler will function way better.

I just did a quick and dirty test compile of the posted code and it did fine for me. I'd suggest you do the above and try again. BTW, this back-and-forth is so slowwww. We should chat on someone's TS. It'll go way faster.
So long, and thanks for all the fish
User avatar
papercoffee
Godlike
Posts: 10447
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Trigger Help!

Post by papercoffee »

I recommend this ... http://notepad-plus-plus.org/
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

N++ is the absolute bomb for searching through folders and folders of code. I use it all the time for that but I think conTEXT is visually better with the UScript highlighter especially for newer coders. You can click any brace and it will show you the corresponding brace (or if you messed up and don't have one). The functions are colored as well as classes so they really pop out, making it easy reading.

That being said N++ is the superior product, it's just missing the training wheels.
So long, and thanks for all the fish
Post Reply