For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

function MutatorTakeDamage. help

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

function MutatorTakeDamage. help

Post by Sergey »

Dear coders!Please look at my mutator code. it dont work. Timer is dont work. Why? Sorry  but i m beginner in c[ch1086]ding...

Code: Select all

class InstaSniperMutator extends Mutator;

var bool Initialized;


function PostBeginPlay()
{

       if (Initialized)
            return;
      Initialized = True;

        Super.PostBeginPlay();
           
        SetTimer(0.05, true);
}

function Timer()
{
         local Pawn Victim;
         local Pawn Killer;
         local Pawn P;

         for ( P=Level.PawnList; P!=None; P=P.NextPawn )
         {
            if (Victim.IsA('PlayerPawn'))
           {
                  if (Victim.health < 100)
                          Victim.health = 0;
                          Victim.died(Killer, 'shot', Location);
           }
     
        }       
} 
The player needs to die after not a big damage, but it's not happening.
Last edited by Sergey on Sun Dec 25, 2016 2:21 pm, edited 1 time in total.
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: My Code dont want to work. help.

Post by Masterkent »

Why?
The variable Victim does not refer to any pawn. You're trying to check if "nothing" is a PlayerPawn and then kill it.
Last edited by Masterkent on Sun Dec 18, 2016 12:59 pm, edited 1 time in total.
User avatar
yrex .
OldUnreal Member
Posts: 291
Joined: Wed May 06, 2015 6:46 am

Re: My Code dont want to work. help.

Post by yrex . »

Firstly, you don't set Victim and Killer to anything after declaring them. For this to work at all you should get rid of these variables and just use P there.

Secondly, you forgot the {}'s after if(Victim.health < 100), which will cause all players to die constantly.

Thirdly, the current way has some problems. Taking any damage (eg. falling) will cause death. Also, there's no information about who was the killer, so this will probably get registered as players commiting suicide. A better way is to use GameRules (a 227 feature) where you can intercept ModifyDamage.
My work | contact: ampoyrex at wp dot pl
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

Re: My Code dont want to work. help.

Post by Sergey »

Firstly, you don't set Victim and Killer to anything after declaring them.
i didnt understand what you mean.
if (Victim.IsA('PlayerPawn')) ??? victim = playerpawn, right? i set victim!
please write this a little code for me. I've been working on it for two days without result.
Last edited by Sergey on Sun Dec 18, 2016 1:13 pm, edited 1 time in total.
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

Re: My Code dont want to work. help.

Post by Sergey »

Why?
The variable Victim does not refer to any pawn. You're trying to check if "nothing" is a PlayerPawn and then kill it.
local Pawn Victim;

i set Victim. Victim is Pawn!

Code: Select all

f (Victim.IsA('PlayerPawn'))
I set PlayerPawn as Victim.

Please write what you mean!
Last edited by Sergey on Sun Dec 18, 2016 1:31 pm, edited 1 time in total.
User avatar
yrex .
OldUnreal Member
Posts: 291
Joined: Wed May 06, 2015 6:46 am

Re: My Code dont want to work. help.

Post by yrex . »

This:

Code: Select all

local Pawn Victim;
just means "create a variable that can refer to Pawn actors (or subclasses)". It doesn't set it to anything. In particular, the compiler doesn't care whether you name it "Victim" or "Killer" or "jf74ibcg478bngc". It's only for your convenience.

This:

Code: Select all

if (Victim.IsA('PlayerPawn'))
translates to: "if Victim is set to some actor and that actor is a PlayerPawn, then...".

So, the simplest way to make it work is:

Code: Select all

function Timer()
{
      local Pawn P;

      for ( P=Level.PawnList; P!=None; P=P.NextPawn )
      {
            if (P.IsA('PlayerPawn'))
            {
                  if (P.health < 100)
                  {
                        P.health = 0;
                        P.died(P, 'shot', Location);
                  }
            }
      }      
}
Obviously, it's far from perfect, but at least it should do something.
My work | contact: ampoyrex at wp dot pl
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

Re: My Code dont want to work. help.

Post by Sergey »

yrex
Test this code on sniper arena. Bots can kill with one shot! But the bots now are not getting frags! And the player loses a frag.. its not suicide! :'(

Please try somebody to fix it. i  realy want to make a mutator with new damage system based on the timer.
Nobody made another similar code.
Last edited by Sergey on Sun Dec 18, 2016 3:03 pm, edited 1 time in total.
User avatar
yrex .
OldUnreal Member
Posts: 291
Joined: Wed May 06, 2015 6:46 am

Re: My Code dont want to work. help.

Post by yrex . »

Wait, is this on Unreal Tournament?

Then try this:

Code: Select all

function MutatorTakeDamage( out int ActualDamage, Pawn Victim, Pawn InstigatedBy, out Vector HitLocation, 
                                    out Vector Momentum, name DamageType)
{
      if(DamageType == 'shot')
      {
            Victim.Died(InstigatedBy, 'shot', HitLocation);
            return;
      }
      
      if ( NextDamageMutator != None )
            NextDamageMutator.MutatorTakeDamage( Damage, Victim, InstigatedBy, HitLocation, Momentum, DamageType );
}
My work | contact: ampoyrex at wp dot pl
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

Re: My Code dont want to work. help.

Post by Sergey »

how to write in one line:

if (P.health > 30)
and
if (P.health
Last edited by Sergey on Sun Dec 18, 2016 9:52 pm, edited 1 time in total.
User avatar
gopostal
OldUnreal Member
Posts: 1007
Joined: Thu Jul 31, 2008 9:29 pm

Re: My Code dont want to work. help.

Post by gopostal »

if ( (P.health != none) && (P.health > 30) && (P.health
I don't want to give the end away
but we're all going to die one day
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

Re: My Code dont want to work. help.

Post by Sergey »

if ( (P.health != none) && (P.health > 30) && (P.health 30) && (P.health
User avatar
gopostal
OldUnreal Member
Posts: 1007
Joined: Thu Jul 31, 2008 9:29 pm

Re: My Code dont want to work. help.

Post by gopostal »

I know better than that. Sorry my friend, my brains are ever so slowly going to mush.

Change it all up to this:

Code: Select all

if( P.IsA('PlayerPawn') )
{
       if (P != none)
       {
              if ( (P.health > 30) && (P.health
I don't want to give the end away
but we're all going to die one day
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: My Code dont want to work. help.

Post by Masterkent »

Code: Select all

if( P.IsA('PlayerPawn') )
{
       if (P != none)
} 
If P is none, then P.IsA('PlayerPawn') is an erroneous function call on none (that evaluates to false), hence that check for P != none is useless (it would always be passed and it would never prevent the warnings about accessing none).

If P is expected to be none, then it makes sense to use

Code: Select all

if (PlayerPawn(P) != none)
instead of the IsA thing.

In case of a loop like

Code: Select all

for ( P=Level.PawnList; P!=None; P=P.NextPawn )
P cannot be none inside the loop body, unless you explicitly set it to none there.
Last edited by Masterkent on Mon Dec 19, 2016 9:03 am, edited 1 time in total.
User avatar
Rocky
OldUnreal Member
Posts: 99
Joined: Mon Nov 18, 2013 9:21 am

Re: My Code dont want to work. help.

Post by Rocky »

Off Topic: I have one dumb question.
If I want to iterate through all the pawns in the level, which one is fastest??

This:
for ( P=Level.PawnList; P!=None; P=P.NextPawn )

or this:
foreach AllActors(Class'Pawn', P)
User avatar
gopostal
OldUnreal Member
Posts: 1007
Joined: Thu Jul 31, 2008 9:29 pm

Re: My Code dont want to work. help.

Post by gopostal »

There was a thread at UT99.org where Nelsona logged an output to measure the speed with which different loops operated in a real world server. IIRC the difference was very small. It's overall much more important to just not do looping through lists unless it's necessary.

I've used multiple loops done different way over the years and tried them in ways that I thought would stress the server. Only in extreme cases did I ever get enough impact that I could tell when playing. Even liberal usage had no negative effects that I could feel.
I don't want to give the end away
but we're all going to die one day
User avatar
Sergey
OldUnreal Member
Posts: 71
Joined: Wed Nov 25, 2015 5:16 am

Re: function MutatorTakeDamage. help

Post by Sergey »

Dear coders!Please look at my mutator code.

Code: Select all

function MutatorTakeDamage( out int ActualDamage, Pawn Victim, Pawn InstigatedBy, out Vector HitLocation, out Vector Momentum, name DamageType)
{
         if ( DamageType == 'Impact' && Victim != Killer ) 
         { 
                   ActualDamage = 50; 
                
         } 

      if ( NextDamageMutator != None )
            NextDamageMutator.MutatorTakeDamage( ActualDamage, Victim, InstigatedBy, HitLocation, Momentum, DamageType );
}
I would like to have bots at all levels of complexity  and Players were applied to each other are always equal damage. I wrote correctly?
Last edited by Sergey on Sun Dec 25, 2016 2:37 pm, edited 1 time in total.

Return to “UScript Board”