ServUO Version
Publish 57
Ultima Expansion
Endless Journey
if(Combatant != null)
{
switch(Utility.RandomMinMax( 1, 5 ))
{
case 1: Say(""); break;
case 2: Say(""); break;
case 3: Say(""); break;
case 4: Say(""); break;
case 5: Say(""); break;
default: break;
}
I only want the message to pop up when the player attacks in the script above. The same message appears when another monster attacks by npc. I want to know what command to put in to fix the attack message only when the player attacks.
using System;
using System.Collections;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
public class Human : BaseRanger
{


[Constructable]
public Human() : base( AIType.AI_Melee, FightMode.None, 15, 5, 0.1, 0.2 )
{

Body = 401;




SetStr( 50, 50 );
SetDex( 50, 50 );
SetInt( 21, 30 );
SetHits ( 800, 800 );

SetSkill( SkillName.Anatomy, 10.0, 10.0 );
SetSkill( SkillName.Archery, 10.0, 10.0 );
SetSkill( SkillName.Tactics, 10.0, 10.0 );
SetSkill( SkillName.MagicResist, 10.0, 10.0 );
SetSkill( SkillName.Wrestling, 10.0, 10.0 );
SetSkill(SkillName.Healing, 10.0, 10.0);







Utility.AssignRandomHair( this );
}

public virtual bool CanHealOwner { get { return true; } }

private DateTime _nextCallHelp;

[CommandProperty(AccessLevel.Counselor, AccessLevel.Administrator)]
public TimeSpan NextCallout
{
get
{
TimeSpan time = _nextCallHelp - DateTime.Now;

if (time < TimeSpan.Zero)
time = TimeSpan.Zero;

return time;
}
set
{
try { _nextCallHelp = DateTime.Now + value; }
catch { }
}
}

public override int GetHurtSound() { return 0x319; }
public override int GetDeathSound() { return 0x316; }

public override void OnThink()
{
base.OnThink();



if (NextCallout == TimeSpan.Zero)
{
int toRescue = 0;


if(Hits < (HitsMax * 0.10) && Combatant != null)
{
switch(Utility.RandomMinMax( 1, 5 ))
{
case 1: Say(""); break;
case 2: Say(""); break;
case 3: Say("!"); break;
case 4: Say(""); break;
case 5: Say("!"); break;
default: break;
}
NextCallout = TimeSpan.FromSeconds(6);
}
if(Hits > (HitsMax * 0.10) && Combatant != null)
{
switch(Utility.RandomMinMax( 1, 5 ))
{

case 1: Say(""); break;
case 2: Say(""); break;
case 3: Say(""); break;
case 4: Say(""); break;
case 5: Say(""); break;
default: break;
}
NextCallout = TimeSpan.FromSeconds(6);
}
}

}



public Human( Serial serial ) : base( serial )
{
}

public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );

writer.Write( (int) 0 ); // version
}

public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );

int version = reader.ReadInt();
}
}
}
This is the full version of the script above.
 
The Mobile class exposes a "Player" bool property that you can check.

Assuming you want to check if the Combatant is a player, you can use;
Code:
if (Combatant is Mobile mob && mob.Player)

The alternative is a more expensive test, but will have the same result;
Code:
if (Combatant is PlayerMobile)
Note that you don't need a null check when using 'is' in this context.
 
The Mobile class exposes a "Player" bool property that you can check.

Assuming you want to check if the Combatant is a player, you can use;
Code:
if (Combatant is Mobile mob && mob.Player)

The alternative is a more expensive test, but will have the same result;
Code:
if (Combatant is PlayerMobile)
Note that you don't need a null check when using 'is' in this context.
Thank you very much. This answer is very helpful to me. I'm so happy.
 
Last edited:
Back