need script:Headshot=2Frags

Discussions about Coding and Scripting
DarKobalt
Novice
Posts: 6
Joined: Sun Jan 09, 2011 12:18 pm
Personal rank: PGM 8)

need script:Headshot=2Frags

Post by DarKobalt »

Hi, I need your help in UnrealScript:

I tried to create a mutator which, when you do a headshot, gives you 2 frags (not 1), and says a message (in the top left), like " %k just sniped for 2 frags". But I didn't find how to do this...so can you help me? :help:
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: need script:Headshot=2Frags

Post by Feralidragon »

Well, in the mutator, use the function PreventDeath to detect a "death", and use the arguments of that function to identify the Killer, the Killed and the damageType.

The damageType will say if it's an headshot or not (damageType=='Decapitated'), then you just have to increment the score of the Killer (the KillCount and I think there's another you must increment or function to call, at least in Team games).

I did that a long time ago within my Venom, but I don't remember the exact code, but it should be very easy.
As for the message, you can use the BroadCastMessage function (I think this the one), however the original message will still appear as well (there might be a way to prevent this, but I don't dominate that coding area, so someone who did the code already might help you better).
DarKobalt
Novice
Posts: 6
Joined: Sun Jan 09, 2011 12:18 pm
Personal rank: PGM 8)

Re: need script:Headshot=2Frags

Post by DarKobalt »

I already tried with the preventdeath, and if damagetype='Decapitated', increase Killer.KillCount, but after i tested and it didn't work...but i will retry ;)
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: need script:Headshot=2Frags

Post by Feralidragon »

Just checked my code at the Venom, there's another value you must increment:
Killer.PlayerReplicationInfo.Score

So just make
Killer.PlayerReplicationInfo.Score += 1;

But don't remove the KillCount increment, let both of them stay.
DarKobalt
Novice
Posts: 6
Joined: Sun Jan 09, 2011 12:18 pm
Personal rank: PGM 8)

Re: need script:Headshot=2Frags

Post by DarKobalt »

Thanks, I will testing ;)
DarKobalt
Novice
Posts: 6
Joined: Sun Jan 09, 2011 12:18 pm
Personal rank: PGM 8)

Re: need script:Headshot=2Frags

Post by DarKobalt »

This is my script (it doesn't work):

Code: Select all

class HardSniper_MUT expands Mutator;

function bool PreventDeath(Pawn Killed, Pawn Killer, name damageType, vector HitLocation)
{
	local bool bMessage;
	local string HeadShot;
	HeadShot="HeadShot!!";
	if ( NextMutator != None )
		return NextMutator.PreventDeath(Killed,Killer, damageType,HitLocation);
	if ( damageType == 'Decapitated' )
	{
		Killer.KillCount += 1;
		Killer.PlayerReplicationInfo.Score += 1;
		bMessage = MutatorBroadcastMessage( None, None, HeadShot, true);
		
	}
	return false;
}

function bool MutatorBroadcastMessage( Actor Sender, Pawn Receiver, out coerce string Msg, optional bool bBeep, out optional name Type )
{
	if ( NextMessageMutator != None )
		return NextMessageMutator.MutatorBroadcastMessage( Sender, Receiver, Msg, bBeep, Type );
	else
		return true;
}

Why it doesn't work? :?
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: need script:Headshot=2Frags

Post by Feralidragon »

This:

Code: Select all

if ( NextMutator != None )
      return NextMutator.PreventDeath(Killed,Killer, damageType,HitLocation);
is in the wrong place.

Place it right before "return false", like this:

Code: Select all

function bool PreventDeath(Pawn Killed, Pawn Killer, name damageType, vector HitLocation)
{
   local bool bMessage;
   local string HeadShot;
   HeadShot="HeadShot!!";

   if ( damageType == 'Decapitated' )
   {
      Killer.KillCount += 1;
      Killer.PlayerReplicationInfo.Score += 1;
      bMessage = MutatorBroadcastMessage( None, None, HeadShot, true);
      
   }

   if ( NextMutator != None )
      return NextMutator.PreventDeath(Killed,Killer, damageType,HitLocation);
   return false;
}
Basically, where it was, just took NextMutator != None to the function "return" and not run the rest of it, thus not running your code afterwards at all.
DarKobalt
Novice
Posts: 6
Joined: Sun Jan 09, 2011 12:18 pm
Personal rank: PGM 8)

Re: need script:Headshot=2Frags

Post by DarKobalt »

I totally forgot this, sorry :loool:

I rebuild all of this and test ;)

EDIT: Now the game count 2 frags per headshot, but it doesn't print the BroadCast message...But :gj: for the code ;)
DarKobalt
Novice
Posts: 6
Joined: Sun Jan 09, 2011 12:18 pm
Personal rank: PGM 8)

Re: need script:Headshot=2Frags

Post by DarKobalt »

A little up!!
Anyone knows who must be the receiver and the sender when i call the broadcast message function?
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: need script:Headshot=2Frags

Post by The_Cowboy »

Code: Select all

function bool PreventDeath(Pawn Killed, Pawn Killer, name damageType, vector HitLocation)
{
    if ( damageType == 'Decapitated' )
   {
      Killer.KillCount += 1;
      Killer.PlayerReplicationInfo.Score += 1;
      BroadcastMessage(Killer.PlayerReplicationInfo.PlayerName&" took off  "Killed.PlayerReplicationInfo.PlayerName$"'s head");
     
   }

   if ( NextMutator != None )
      return NextMutator.PreventDeath(Killed,Killer, damageType,HitLocation);
   return false;
}
Try this :idea:
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: need script:Headshot=2Frags

Post by The_Cowboy »

DarKobalt wrote:A little up!!
Anyone knows who must be the receiver and the sender when i call the broadcast message function?
I am not sure but I think receivers are all the pawns( player classes ) and sender could be anyone, from mutator to gametype you are playing(CTFGame etc ).Basically it should be an Actor.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: need script:Headshot=2Frags

Post by JackGriffin »

Cowboy is right. The easiest way is to use broadcast message. If you want to send a message to a specific person (like the killer) you'd use:
Killer.ReceiveLocalizedMessage(class'MH2HeadShotMessage5');
and then script your own specific message.

There are a couple of caveats though you need to be aware of. There is not a way to change the First Blood and Head Shot announcement through mutator. You have to access those two in gametype (thank you Epic for that). Being able to change the announcer for First Blood was surprisingly difficult and took me several evenings to get.
So long, and thanks for all the fish
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: need script:Headshot=2Frags

Post by Rakiayn »

I did something simular, but I used killer.playerrplicationinfo.score += 1;
why is the killer.killcount += 1; needed?

@DarKobalt
you can alse use: killer.clientmessage(message);
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: need script:Headshot=2Frags

Post by The_Cowboy »

Rakiayn wrote: why is the killer.killcount += 1; needed?
DarKobalt wrote: need script:Headshot=2Frags
Headshotgives one frag.1 frag is manually added to make it count 2 frags for each headshot
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: need script:Headshot=2Frags

Post by Rakiayn »

The_Cowboy wrote:
Rakiayn wrote: why is the killer.killcount += 1; needed?
DarKobalt wrote: need script:Headshot=2Frags
Headshotgives one frag.1 frag is manually added to make it count 2 frags for each headshot
killer.playerrplicationinfo.score += 1
already does that
Post Reply