Trigger Help!

Discussions about Coding and Scripting
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

Never, ever use this check for player identification:

Code: Select all

if ( P.IsA('PlayerPawn') || P.IsA('Bot') )
Instead go with:

Code: Select all

if ( P.bIsPlayer && (P.PlayerReplicationInfo != none) && !P.PlayerReplicationInfo.IsSpectator )
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

Higor do you live on the west coast? I'd love to sit down and have a beer with you sometime. BTW, you should explain why since this sort of discussion gets archived and google searched pretty often since ut99.org is #1 or #2 in UT searches.
So long, and thanks for all the fish
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

I'm from Uruguay :tongue: , a bit far away from the west coast.

Back on topic, doing the player check using PlayerPawn or Bot as main references will cause problems with Botz, U1 Bots and theoretically any extraneous pawn with a PRI.
Will also cause problems with non-player playerpawns and bots (that don't show up on scoreboard).

Best method does checks are done AND operator, which is always better for speed reasons:
- bIsPlayer > Fast check, used by most default Unreal objects, set to True on anything capable of picking up items.
- PlayerReplicationInfo != none > Sanity check, lets us know if this item picking pawn isn't something casually embedded into a map.
- !PlayerReplicationInfo.bIsSpectator > Playing the game.


Citing a real example where Epic royally screwed up their code, ScriptedPawn's SetEnemy:

Code: Select all

	if ( (PlayerPawn(NewEnemy) == None) && (ScriptedPawn(NewEnemy) == None) )
		return false;
Monsters do not attack any kind of bot because of this, and do attack spectators.
Makes me wonder why this was never patched for 451.
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, conText was too bland for me, N++ seems to work fine because I'm also learning some c++.

@Higor when i use the

Code: Select all

P.bIsPlayer && (P.PlayerReplicationInfo != none) && !P.PlayerReplicationInfo.IsSpectator )
Why not put

Code: Select all

!=false
or

Code: Select all

 !=true
instead of having none? Booleans only give true or false or 1 or 0 ....
For the error I'm going to check to see if everything spelled correctly and all the files have the correct file names and directories.

EDIT: I found the problem, in the default properties I didn't put an ending " at the end of the message that I put.

By the way, Jack you should have stayed in the TS for a bit longer, had lot's of questions! Even though Hitman said you were busy, I understand that.
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'm sorry, my time is kinda tight. In short I developed a by-product of my cancer called 'cachexia'. Because of this I have to do a full work-out every day no matter what. It's 30 minutes hard running, resistance training, some weights. It's honestly exhausting but serious exercise is the only real way to combat this damn thing. It dominates my afternoon too, by the time I get home from work and fix dinner, then workout and shower, it just eats my free time all up. That's why I had to jet so fast last night, I was running behind but Hitty is just so much fun to talk to I spent too long.

OK, now schools in....You ask why you need to use !=none and not true or false. This is really important concept to learn so I'm going to explain it in some detail. Let's pretend I have a cat and a box...

What? Shrod-who? No, never heard of him.

So I have this box and maybe the cat is in it and maybe it isn't. If the cat is in the box then the box is full (true) and if I take the cat out the box is empty (false). The cat has had enough of this silliness and decides to go play outside. Now I have a box and no cat. How would you quantify the contents of the box now? It wouldn't be false since there is no opposite true, you would say the contents are now 'none'. The same principle applies to UScript. Say someone fires a rocket across the map. The moment he fires the rocket it inherits the value of the shooter (we'll use papercoffee). Now pretend that at the moment paper fired his rocket he got disconnected. He probably got banned for his continual verbal abuse of the other players, but that's no surprise. He's like that. Anyway if you look at the rocket and log it's owner it will return an error since paper is now gone. The log went from reading:

Code: Select all

GuidedWarshell7.Owner = papercoffee
to

Code: Select all

GuidedWarshell7.Owner = none
Do you see now why false/true and none are not the same thing? None is the total lack of information while true/false *is* information. That's why I added a wrapper to the code:

Code: Select all

if (EventInstigator != none)
   {
to prevent an error being written to the code in the event that whomever instigated the trigger was somehow removed before the code could be ran. This is where Accessed None errors come from you see in logs.
So long, and thanks for all the fish
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

Also, Open up Object and Actor UScript source in UnrealEd and see the function and operator lists.
Second, booleans don't need (bX == True) checks, (bX) does it.
Unfortunately we can't do those in INT, FLOAT, etc (other datatypes), as it can be done in c++.


( ! ) is a bool preoperator and you can use it to reverse the value before the condition is read.
( !P.bIsPlayer ) >> this returns true if player has bIsPlayer set to false.

Code: Select all

native static final preoperator bool ! (bool Other)
{
     if ( Other )
           return false;
     return true;
}

Now for ++ operators (pre and post), both actually alter the input (because function parameter has OUT)

(++i) this returns i+1, and sets i to i+1 as well.

Code: Select all

native static final preoperator int ++ (out int A)
{
     A = A + 1;
     return A;
}

(i++) this returns i, but sets i to i+1 after the check returns.

Code: Select all

native static final postoperator int ++ (out int A)
{
     local int B;
     B = A;
     A = A + 1;
     return B;
}
Seriously, check Object class for STRING operators as well.
User avatar
papercoffee
Godlike
Posts: 10451
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 »

JackGriffin wrote:(we'll use papercoffee)
:|
JackGriffin wrote:He probably got banned for his continual verbal abuse of the other players, but that's no surprise. He's like that.
:evil:
JackGriffin wrote:it will return an error since paper is now gone.
:confused2:




:loool:
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

I love you paper, you know that my brother. It really helps when trying to get UScript ideas across to keep it from becoming too dry. I like to mix a little humor in so it doesn't read like very bland instructions. Higor's post is spot on (isn't he just friggin incredible?) but it's a bit....boring (no offense). If we are going to keep people excited about creation then the process should be enjoyable too.
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 for the examples and help Jack and Higor. I understand it now, so thanks for clearing that up there.
Now one thing I'm now onto is to create a ' wildcard string ' for the %p or the name ( if it's needed ).
I see that the Playername is put in with the string message so it shows that player name then the message, but when testing it doesn't work, just says the message string that I put ( before and after the small change you put Jack )
Prophunt for UT99!!!
Image
Github
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

If you know how to properly iterate, this will solve your player wildcard thing, consider this a riddle and try and fix your own issue:

function int Len( string Test)
Returns length of (Test)

s: "IAmAString"
Len( s) returns 10



function int InStr( string Test, string Find)
This function returns the starting position of first instance of (Find) inside (Test)

s: "IAmAString"
p: 0123456789

InStr( s, "mA") returns 2
InStr( s, "A") returns 1
InStr( s, "nope") returns -1
if ( InStr( s, otherS) >= 0 ) //(otherS) string was found in (s)



function string Left( string Test, int n)
Returns the first (n) characters of (Test) into a new string.

s: "ITS-A-ME-MARIO"

Left( s, 4) returns "ITS-"
Left( s, 9001) returns (s) (does not add new characters)
Left( s, 0) returns ""



function string Right( string Test, int n)
Returns the last (n) characters of (Test) into a new string.

s: "ITS-A-ME-MARIO"

Right( s, 4) returns "ARIO"
Right( s, 9001) returns (s) (does not add new characters)
Right( s, 0) returns ""



function string Mid( string Test, int start, optional int count)
Returns (count, or all if count = 0) characters of (Test), starting from (start) into a new string.

s: "ITS-A-ME-MARIO"

Mid( s, 4, 4) returns "A-ME"
Mid( s, 9001) returns "" (start beyond string end)
Mid( s, 9) = Right(s, Len(s) - 9) returns "MARIO" (no count added, return all strings after start)
Mid( s, 0, 5) = Left( s, 5) returns "ITS-A"
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 »

I can't even comprehend what I'm looking at
I'll just look into other codes and see if I can do it myself in another way. Thanks for trying though Higor
Prophunt for UT99!!!
Image
Github
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

class FString : public TArray

TArray is a dynamic array in Unreal, in other words, the ONLY dynamic array type you can handle in Unreal's stock code.
The data type of FString array is TChar, that when define in Unicode UT, it's a 2 byte character (unsigned integer, 0-65535).

In Windows, you may use any value for each character in the strings, in Linux you're only limited to 0-127
(whoever built UT's Linux version was ape and disregarded cross-platform consistency over a stupid ideal, or it's simply a compiler bug, whatever...)

What am I getting at?

Just like you can do:
var byte Char[256];

In a dynamic array, you can do:
var <array> byte Char;
With the above one being entirely unusable from unrealscript.

The string is a sub-type of said dynamic arrays, with it's own function set (protected by manual manipulation, you need to use string functions).
var string CharSet;
That is exactly the same as the one above, but completely differently handled.


WHEN YOU THINK OF STRINGS, THINK OF AN ARRAY
var string S;
S = "You Are Noob";
Each letter corresponds to it's corresponding ASCII character index, just google any character map and it's corresponding index and you'll know what I mean.
This one below contains the 127 cross platform compatible chars.
Image

The array certainly contains 12 (13 with nullterminated string? haven't checked that) elements:
{ 89, 111, .... etc }
(or in HEX)
{ 0x59, 0x6F, .... etc }

Len() in a string is the same as Num() in dynamic array, returns the count.
Left returns the initial X objects belonging to this array, grouped up into a new string array.
and so on...

You need to convert a wildcard character into a player name in runtime and avoid any kind of bug or infinite loop.
Let's say your string is:
Message = "The lower deck has been breached by %p"

You need to print a message where %p is replaced by a player name.
That's what i'm trying to help you achieve.

Instead of coding or whatever, try seeing the actions in your mind.
If you were a computer handling a strip full of numbers (chars), how would you operate to replace %p with a player name?
If you get this right, you will never, ever have to ask a question about UT strings.

EDIT:
Forgot to mention, that the ( $ ) operator returns a united string:
native static final string operator $ (string A, string B);
A = "you "
B = "suck"
C = A $ B;
C > "you suck"
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

We really should take the time to build a proper searchable wiki. This sort of information presented like this belongs front-and-center someplace that everyone could use. Dane, maybe you could host it? You've got the technical knowledge to set it up properly and you would host sharing it so everyone could download the thing. I'd be happy to spend a lot of time writing response pages in the wiki then referencing them in threads here. I'd wager a lot of others would do the same. Lots of knowledge just sits idle instead of being shared, I mean just look at Higor's post. He just took String to school....So well done. +Karma for Higor.
So long, and thanks for all the fish
User avatar
Hellkeeper
Inhuman
Posts: 905
Joined: Tue Feb 25, 2014 12:32 pm
Personal rank: Soulless Automaton
Location: France
Contact:

Re: Trigger Help!

Post by Hellkeeper »

OldUnreal has a wiki which could handle all that. I'm sure Smirftsch would be glad to host all that.
You must construct additional pylons.
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 »

I sort of understand what Higor's saying about strings. What I think a computer needs to do to convert %P into a player name is by making a making %P a variable player name, but replace it with the actual player name?
Prophunt for UT99!!!
Image
Github
Post Reply