Trigger Help!
Trigger Help!
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...
-
- Godlike
- Posts: 3774
- Joined: Fri Jan 14, 2011 1:53 pm
- Personal rank: -Retired-
Re: Trigger Help!
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:
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 here's a section out of TournamentScoreBoard:
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.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);
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
- Chamberly
- Godlike
- Posts: 1963
- Joined: Sat Sep 17, 2011 4:32 pm
- Personal rank: Dame. Vandora
- Location: TN, USA
- Contact:
Re: Trigger Help!
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.
But the above... I just don't get it. We are newbie mappers... lol.
Re: Trigger Help!
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:
Yes, you KNOW what pawn touched the trigger, and what trigger was touched.
SpecialEvent actor has this trigger function:
That's what SpecialEvent does, now focus on BroadcastMessage function.
> '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.
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 )
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 );
}
}
Code: Select all
event BroadcastMessage( coerce string Msg, optional bool bBeep, optional name Type )
> 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.
Re: Trigger Help!
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?
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?
Re: Trigger Help!
Code: Select all
if(EventInstigator.isA('PlayerPawn') || EventInstigator.isA('Bot')) {
}
Website, Forum & UTStats
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
Re: Trigger Help!
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?
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?
- 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:
-
- Godlike
- Posts: 3774
- Joined: Fri Jan 14, 2011 1:53 pm
- Personal rank: -Retired-
Re: Trigger Help!
Post your current code so far and we'll feed you the next line.
So long, and thanks for all the fish
Re: Trigger Help!
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.
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.
-
- Godlike
- Posts: 3774
- Joined: Fri Jan 14, 2011 1:53 pm
- Personal rank: -Retired-
Re: Trigger Help!
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:
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: The space will make it read:
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
}
}
}
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!
Code: Select all
gopostal has opened the portal!
So long, and thanks for all the fish
Re: Trigger Help!
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
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
-
- Godlike
- Posts: 3774
- Joined: Fri Jan 14, 2011 1:53 pm
- Personal rank: -Retired-
Re: Trigger Help!
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
- 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:
-
- Godlike
- Posts: 3774
- Joined: Fri Jan 14, 2011 1:53 pm
- Personal rank: -Retired-
Re: Trigger Help!
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.
That being said N++ is the superior product, it's just missing the training wheels.
So long, and thanks for all the fish