"Friendly" ScriptedPawn Keeps Attacking Me

Discussions about Coding and Scripting
Post Reply
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

"Friendly" ScriptedPawn Keeps Attacking Me

Post by Peamole »

Recently I made a ScriptedPawn called MercBlasta and changed its code, in an attempt, to make it friendly to PlayerPawns, Nalis and Cows. As you can see, I changed eAttitude code to have a "Friendly" attitude towards me(or so I thought *gulp*). I even tried fooling around with other parts of the code, of course, to no avail. The results:
  • When I shoot it once,(purposefully or accidentally) it turns on me and makes threatening gestures and sounds but stands in place and does nothing else.
    When I shoot at it again, it attacks or does the same "threatening dance" and advances at me little-by-little. It swats at me when I get close.
    When a Nali gets frightened by another monster, it threatens the Nali.
I tried all kinds of tricks with little understanding of uscript or coding.

Does anyone know how to make it unconditionally friendly? Also, can someone please tell me what the code for a function or state that smooths things out with the nalis would look like? I would like the MercBlasta to comfort the frightened nali, almost like with the MakeNaliFriendly actor. The poor thing needs reassurance of MercBlasta's unwavering friendship rather than getting threatening repeatedly. :cry: Getting on its bad side is no fun. Trust me.

I put the script in a *.txt file for you all because I haven't gotten rid of all of the files that it depends on yet.
Attachments
MercBlasta Code.txt
(28.19 KiB) Downloaded 7 times
User avatar
EvilGrins
Godlike
Posts: 9731
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA
Contact:

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by EvilGrins »

All your problems seem to come into play, not surprisingly, because you keep shooting it.

Here's an idea... don't shoot it.

I run a thread on this forum called "New Monsters" and what you're describing sounds like a monster in there · viewtopic.php?p=125415#p125415

The Pet Skaarj.
http://unreal-games.livejournal.com/
Image
medor wrote:Replace Skaarj with EvilGrins :mrgreen:
Smilies · viewtopic.php?f=8&t=13758
User avatar
OjitroC
Godlike
Posts: 3637
Joined: Sat Sep 12, 2015 8:46 pm

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by OjitroC »

I'm not an expert on this - your code alters certain functions, etc in the ScriptedPawn code but all the other, unaltered functions etc of that Class will be implemented.

There is a function

Code: Select all

function damageAttitudeTo(pawn Other)
which sets out what the pawn's Attitude should be when damaged by another Pawn - have a look at the code for that in ScriptedPawn and you will see why your Pawn threatens you.

Here is the code of a friendly, helpful pawn (which attacks those pawns that attack the Player but otherwise ignores the Player)
DDFParker.txt
(59.27 KiB) Downloaded 1 time
you could try using some of the code from that - in particular trying setting your MercBlasta's Attitude to Ignore rather than Friendly.
User avatar
Barbie
Godlike
Posts: 2807
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by Barbie »

This is not an answer to your question. But I saw your code and I assume that it is a complete copy of the Mercenary code? Don't do this but instead consider using the existing code of Mercenary by subclassing Mercenary: class MercBlasta expands Mercenary;
Then you can override the functions that you want to change. The advantage is that it is obvious what has changed.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by Peamole »

I think I learn best from reading code and observing.
EvilGrins wrote: Sat Apr 01, 2023 8:09 am All your problems seem to come into play, not surprisingly, because you keep shooting it.

Here's an idea... don't shoot it.

I run a thread on this forum called "New Monsters" and what you're describing sounds like a monster in there · viewtopic.php?p=125415#p125415

The Pet Skaarj.
Y'know it's kinds funny how that happened... I was blasting out some fancy windows in an abandoned/skaarj-runned nali church in that Bluff Eversmoking map when my precious MercBlastas were struck by a ~wisp of air~ from my eightball nade's splash damage(I was just reading a thread about that map). They were a bit angry but didn't quite attack yet. I'll check that thread out.
OjitroC wrote: Sat Apr 01, 2023 9:20 am I'm not an expert on this - your code alters certain functions, etc in the ScriptedPawn code but all the other, unaltered functions etc of that Class will be implemented.

There is a function

Code: Select all

function damageAttitudeTo(pawn Other)
which sets out what the pawn's Attitude should be when damaged by another Pawn - have a look at the code for that in ScriptedPawn and you will see why your Pawn threatens you.

Here is the code of a friendly, helpful pawn (which attacks those pawns that attack the Player but otherwise ignores the Player) DDFParker.txt
you could try using some of the code from that - in particular trying setting your MercBlasta's Attitude to Ignore rather than Friendly.
Yeah, I see those functions and states. Most of them seem to be concerning methods of attacking pawn Other. Is it not coming from the ones where MercBlasta figures out who hit it (instigatedBy) and how it should attack back? Is there no way to make it think who it's attacking or who its "enemy" is before attacking?
Barbie wrote: Sat Apr 01, 2023 9:24 am This is not an answer to your question. But I saw your code and I assume that it is a complete copy of the Mercenary code? Don't do this but instead consider using the existing code of Mercenary by subclassing Mercenary: class MercBlasta expands Mercenary;
Then you can override the functions that you want to change. The advantage is that it is obvious what has changed.
Yup, it's a copy/paste/edit of the Mercenary. This is way out of my scope for now. How do you override functions? I'm still confusingly dragging myself through "UnrealScript Language Reference" By: Tim Sweeney. All of the over-simplified "function ThisIsAFunction ()" talk is making my eyes roll back into my skull. :help:
User avatar
OjitroC
Godlike
Posts: 3637
Joined: Sat Sep 12, 2015 8:46 pm

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by OjitroC »

Peamole wrote: Sat Apr 01, 2023 3:05 pm Yeah, I see those functions and states. Most of them seem to be concerning methods of attacking pawn Other. Is it not coming from the ones where MercBlasta figures out who hit it (instigatedBy) and how it should attack back? Is there no way to make it think who it's attacking or who its "enemy" is before attacking?
Probably but that involves understanding all of the ScriptedPawn code (and possibly native code) and how it all interacts. Until you have gained that understanding, it's probably easier just to change how the MercBlasta reacts to taking 'damage' from the Player (damage may include being bumped? I don't know). I speak, of course, as someone who has very little understanding of that code - I just concentrate on small changes where I am fairly confident of the effect of those changes.

Have a look at the code for Parker and for the PetSkaarj (which totally ignores most things) and see if you can use some of that.
Peamole wrote: Sat Apr 01, 2023 3:05 pm How do you override functions?
Your functions in MercBlasta override the same functions in the ScriptedPawn class where the functions in MercBlasta are different. Barbie's suggestion is to ensure that there is much less code in MercBlasta so it is easier to see where the differences are.
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by Peamole »

Thank you, everyone. OjitroC, I looked at Nali's script and added the fallowing code before the "function eAttitude AttitudeToCreature(Pawn Other)" section. It works!
function damageAttitudeTo(pawn Other)
{
if ( (Other == Self) || (Other == None) || (FlockPawn(Other) != None) || (Other.IsA('DinoFriend')) || (Other.IsA('Nali')) || (Other.IsA('Cow')) )
return;
if ( Other.bIsPlayer ) //change attitude to player
AttitudeToPlayer = ATTITUDE_Ignore;
else if ( ScriptedPawn(Other) == None )
Hated = Other;
SetEnemy(Other);
}

It's kind of lame how it completely ignores me though... I wish I could make it threaten me once with a nodding or chest pounding, then ignore or be friendly to me. I guess, in the heat of battle, there's no time for MercBlasta to say, "Watch it!" while it's fighting other creatures and super monsters.

I already made a sick skin for it. I'll polish its code up some more, give it a different custom ranged projectile, etc. and post it for y'all. Then there's DinoFriend which is almost done too. That's coming up next.
User avatar
OjitroC
Godlike
Posts: 3637
Joined: Sat Sep 12, 2015 8:46 pm

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by OjitroC »

Good to hear it now works.

Purely as a matter of interest, do you look at the log each time you run a game with these pawns and/or each time you make a change to the script, just to monitor any ScriptWarnings, etc?
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by Peamole »

No, OjitroC. Very rarely do I look at the log for that. I only really look at the log if I find a serious glitch or "missing file for package" or "failed to spawn" problems(if I'm not too lazy...). I figured that if it compiles fine on the first try, and it does, at least in-the-ballpark of what it's supposed to do—then, well, it's fine?... No? :noidea
That reminds me. I'm thinking of adding something that displays a kill message to the log when MercBlasta kills so I know what just went down in Unreal Gold. By any chance, does anybody know where I may find such a code? Does it involve the %k and %o and does it have function fprint() or something like that?

BTW: It was a map or two before Bluff Eversmoking in UnrealI's mission.
User avatar
OjitroC
Godlike
Posts: 3637
Joined: Sat Sep 12, 2015 8:46 pm

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by OjitroC »

Peamole wrote: Mon Apr 03, 2023 12:40 am No, OjitroC. Very rarely do I look at the log for that. I only really look at the log if I find a serious glitch or "missing file for package" or "failed to spawn" problems(if I'm not too lazy...). I figured that if it compiles fine on the first try, and it does, at least in-the-ballpark of what it's supposed to do—then, well, it's fine?... No? :noidea
It may be fine or it may not - that's determined, in part, by checking the log. Code may compile OK but particular 'things' may not work properly in specific circumstances in-game for example.

I've got into the habit of always checking the log after each game with a new ScriptedPawn just to look for errors (animations, weapons, etc) which I may (or may not) be able to eliminate. It's up to you obviously but I would suggest it is good practice.
Peamole wrote: Mon Apr 03, 2023 12:40 am That reminds me. I'm thinking of adding something that displays a kill message to the log when MercBlasta kills so I know what just went down in Unreal Gold. By any chance, does anybody know where I may find such a code? Does it involve the %k and %o and does it have function fprint() or something like that?
Check out the UTDM Pawns that EG uses in his map edits - the UTDMT, SkaarjBerserker, Warlord - these all print messages to the log about 'their' kills. Bear in mind though that these pawns are assigned to a team and that the code is buggy, spamming the log with messages.
User avatar
Barbie
Godlike
Posts: 2807
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by Barbie »

Peamole wrote: Mon Apr 03, 2023 12:40 am Does it involve the %k and %o and does it have function fprint() or something like that?
Writing to log can be done with Object's functions

Code: Select all

native(231) final static function Log( coerce string S, optional name Tag );
native(232) final static function Warn( coerce string S );
Peamole wrote: Mon Apr 03, 2023 12:40 am I'm thinking of adding something that displays a kill message to the log when MercBlasta kills so I know what just went down in Unreal Gold. By any chance, does anybody know where I may find such a code?
Every Pawn has the event Killed that is raised when any Pawn is killed. So you can expand that to log your message:

Code: Select all

function Killed(pawn Killer, pawn Other, name damageType) {
	// let the parent code do its work:
	super.Killed(Killer, Other, damageType);
	// now our message:
	if (Killer == self)
		log(Killer @ "has killed" @ Other);
}
will create
UnrealTournament.log wrote:ScriptLog: Autoplay.MyMercenary0 has killed Autoplay.TFemale0
You can use Pawn.GetHumanName() to retrieve the "normal" Pawn's name.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
EvilGrins
Godlike
Posts: 9731
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA
Contact:

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by EvilGrins »

Hmmmm.

Description on the video is "Not all enemies in Unreal believe in initiating violence. This guy won't attack unless you touch him, shoot him or step on his turf (the pit with the armor and crucified nali)."
http://unreal-games.livejournal.com/
Image
medor wrote:Replace Skaarj with EvilGrins :mrgreen:
Smilies · viewtopic.php?f=8&t=13758
User avatar
OjitroC
Godlike
Posts: 3637
Joined: Sat Sep 12, 2015 8:46 pm

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by OjitroC »

EvilGrins wrote: Mon Apr 03, 2023 4:02 pm
Description on the video is "Not all enemies in Unreal believe in initiating violence. This guy won't attack unless you touch him, shoot him or step on his turf (the pit with the armor and crucified nali)."
Yeah, I don't think that's used enough in MonsterHunt or even in SinglePlayer - probably not what most people want in MonsterHunt of course.

Curiously having compiled the MercBlasta with the original code and summoned it in to some DM maps, all it does is follow the Player around - doesn't threaten or attack when damaged by the Player.
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by Peamole »

OjitroC wrote: Mon Apr 03, 2023 7:57 pm
EvilGrins wrote: Mon Apr 03, 2023 4:02 pm
Description on the video is "Not all enemies in Unreal believe in initiating violence. This guy won't attack unless you touch him, shoot him or step on his turf (the pit with the armor and crucified nali)."
Yeah, I don't think that's used enough in MonsterHunt or even in SinglePlayer - probably not what most people want in MonsterHunt of course.

Curiously having compiled the MercBlasta with the original code and summoned it in to some DM maps, all it does is follow the Player around - doesn't threaten or attack when damaged by the Player.
When I play any Unreal, all the monsters attack me first, because they KNOW I'm a threat to their evil undertakings, and I let them! 8) Come at me, bro! lol
Did you know that If you attack a nali or insanenali, MercBlasta'll turn on you. This I don't mind.... I'm still haven't tried to crack the code of how to get MercBlasta to ignore it mostly because I kinda like him that way. :lol2: He teaches Nali killers a lesson in the Unreal Mission Pack. That game I play in Godlike mode with a special musket. (to be revealed later).
User avatar
EvilGrins
Godlike
Posts: 9731
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA
Contact:

Re: "Friendly" ScriptedPawn Keeps Attacking Me

Post by EvilGrins »

Peamole wrote: Wed Apr 05, 2023 11:35 pmthey KNOW I'm a threat to their evil undertakings
They're not evil, they're misunderstood!
Image
http://unreal-games.livejournal.com/
Image
medor wrote:Replace Skaarj with EvilGrins :mrgreen:
Smilies · viewtopic.php?f=8&t=13758
Post Reply