RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

{NOX} {Point System}

S

Seven

Guest
{NOX} {Point System}

Hey everyone,
Currently having a problem. When my players "die" from a monster or themselves they loose a point. Is there a way to fix this?
Thanks.

Your friend,
Seven
 

Spooky

Wanderer
This is pseudo code but its the hint you are after.

[code:1]if ( !from.LastKiller is typeof( playermobile ) || from.LastKiller = from )
{
//do nothing
}
else
{
//do calcs here
}[/code:1]
 
S

Seven

Guest
Hey,
Where do i place this? Also what does "//do nothing //do calcs here" do?
Im a bit confused on that one.
Thanks.

your friend,
Seven
 
S

Seven

Guest
Ok. Thanks.
Im still sortra new to c# langauge and currently trying to teach my self step by step.
So like i would put :

[code:1]
if ( !from.LastKiller is typeof( playermobile ) || from.LastKiller = from )
{
get point //or something like that takes away a point
}
else
{
return false
}[/code:1]
Am i correct?
 

Spooky

Wanderer
Wrong way around because you dont want anything to happen to their points when its a monstor kill or self kill it needs to be in the else clause.
(unless of course you reverse the logic of the if statement)
 
S

Seven

Guest
Ohh...I know where to put it now...
just dont know what to put in the // //
[code:1]
if ( !from.LastKiller is typeof( playermobile ) || from.LastKiller = from )
{
return false
}
else //i thinK?
{
get point
}[/code:1]
 

Clarke76

Wanderer
[code:1]
using System;
using System.Collections;
using Server;
using Server.Mobiles;
using Server.Network;


namespace Server.Mobiles
{

public class PointSystem
{

public static void Initialize()
{
EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_PlayerDeath);
Server.Commands.Register("ViewScore", AccessLevel.Player, new CommandEventHandler(ViewScore_OnCommand));
}

//this is the initializer for your [viewscore command which will display points overhead

public static void ViewScore_OnCommand(CommandEventArgs args)
{
Mobile m = args.Mobile;
PlayerMobile from = m as PlayerMobile;

if(from != null)
{
string message = "" + from.GetPoints();
from.PublicOverheadMessage( MessageType.Regular, 0x5A7, false, message);
}
}

//this is the code that runs on the [viewscore command

//and this part may seem a little confusing, but the code to determine who has killed who was pretty much ripped straight from the corpse.cs code. Many many thanks to Zippy and everyone else for helping me out with this.

public static void EventSink_PlayerDeath(PlayerDeathEventArgs e)
{
PlayerMobile owner = e.Mobile as PlayerMobile;
PlayerMobile m_Killer = owner;
TimeSpan lastTime = TimeSpan.MaxValue;

for ( int i = 0; i < owner.Aggressors.Count; ++i )
{
AggressorInfo info = (AggressorInfo)owner.Aggressors;

if ( info.Attacker.Player && (DateTime.Now - info.LastCombatTime) < lastTime )
{
m_Killer = info.Attacker as PlayerMobile;
lastTime = (DateTime.Now - info.LastCombatTime);
}
}
for ( int i = 0; i < owner.Aggressed.Count; ++i )
{
AggressorInfo info = (AggressorInfo)owner.Aggressed;
if ( info.Attacker.Player && (DateTime.Now - info.LastCombatTime) < lastTime )
{
m_Killer = info.Defender as PlayerMobile;
lastTime = (DateTime.Now - info.LastCombatTime);
}
}

//so now you should have who killed stored in m_Killer and who died in owner. Now we decide what needs to be done from there.

if(m_Killer is PlayerMobile)
{

//this part shouldn't really have to be added since m_Killer is of type PlayerMobile, but we had some bugs where guards and monsters were trying to get points from killing players and it was crashing the server... so.. this was a quick fix.

if( m_Killer.Guild != owner.Guild || m_Killer.Guild == null || owner.Guild == null)
{
if( !owner.KillerIsTimed(m_Killer))
{
m_Killer.AddPoint();
m_Killer.SendMessage( 0x5A7, "You have earned 1 point for killing {0}", owner.Name);
KillTimer timerx = new KillTimer ( TimeSpan.FromHours( 4 ), m_Killer, owner);
timerx.Start();

owner.SubPoint();
SimpleTimer timer = new SimpleTimer( TimeSpan.FromSeconds( 4 ), m_Killer, owner );
timer.Start();
}
}
}
}
}

//So, we checked to make sure that the players were not in the same guild (because they should be able to fight themselves whenever they want). And we started a few timers. The timer for owner is set because if you try to display a message to him while he's dieing it won't show up. So you have to delay it a few seconds until after the death animation. You should also notice that this is where the killer gets his 4 hour time limit set.

//and now on to the timers. basically what happens is when the timer is initialized, the killer and owner are passed in, and OnTick is when the timer expires, so that's when you want the message to be displayed to the one who died, and in the killtimer thats where you want the killer to be taken off the list.

public class SimpleTimer : Timer
{
PlayerMobile m_Killer;
PlayerMobile m_Owner;

public SimpleTimer( TimeSpan delay, PlayerMobile killer, PlayerMobile owner ) : base( delay )
{
Priority = TimerPriority.OneSecond;
m_Killer = killer;
m_Owner = owner;
}

protected override void OnTick()
{
if(m_Owner.HasMoreThanMin(1))
{
if( m_Killer != m_Owner)
{
m_Owner.SendMessage( 0x5A7, "You have lost 1 point to {0}", m_Killer.Name);
}
else
{
m_Owner.SendMessage( 0x5A7, "You have lost 1 point for killing yourself...");
}
}
else
{
m_Owner.SendMessage( 0x5A7, "You suck so bad you can't even loose a point...");
}

Stop();
}
}

public class KillTimer : Timer
{
PlayerMobile m_Killer;
PlayerMobile m_Owner;

public KillTimer( TimeSpan delay, PlayerMobile killer, PlayerMobile owner) : base (delay)
{
Priority = TimerPriority.OneSecond;
m_Killer = killer;
m_Owner = owner;
m_Owner.AddKiller(m_Killer);
}

protected override void OnTick()
{
m_Owner.RemoveKiller(m_Killer);
Stop();
}
}
}
[/code:1]
 
S

Seven

Guest
Ike,
Thanks for posting that it can now be a reference :)
Thanks Ike.
Seven.
 
Top