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!

First Kill System? How-To?

Toriad

Sorceror
What would be the most optimized way to do a First Kill system for monsters and players? I ask because I plan on rewarding extra experience when a player kills a monster for the first time.

Toriad: -Kills a Troll-
- Toriad gets 200 bonus experience for his first troll kill -
Toriad: - Kills a Troll -
- Toriad gets 0 Bonus experience
Toriad: - Kills a Ogre -
- Toriad gets 500 Bonus Experience for his first ogre kill -

How would someone accomplish something like that the most efficient way?

Getting back into scripting is fun!
 

tass23

Page
I think you're going to have to add a tag for every new character for every mob you have on the server, killed or notkilled for example. if killed, then, basically do nothing, it notkilled, then, give 500 experience points.
 

Pure Insanity

Sorceror
Just add to a list of types (creature.GetType()) when a person kills a creature, simply prevent it from adding the same type more than once. Only edit needed for a mob would be to detect when it dies and add it to the player's list.
 

Toriad

Sorceror
My First Code Snippet since returning, yay?

This is what I got so far, haven't tested it yet as I'm at work (yeah I'm a bad person).

My Changes to PlayerMobile

Code:
public class PlayerMobile : Mobile, IHonorTarget
{
  /* First-Kill System */
 
  private List<string> m_first_kills;

PlayerMobile Deserialize

Code:
case 29:
{
  int first_kill_count = reader.ReadInt();
 
  if (first_kill_count > 0)
  {
      m_first_kills = new List<string>();
 
    for (int i = 0; i < first_kill_count; i++)
    {
      int r = reader.ReadString();
      m_first_kills.Add(r);
    }
  }
 
  goto case 28;
}

PlayerMobile Seralization

Code:
writer.Write( (int) 29 ); // version
 
if (m_first_kills == null)
{
  writer.Write((int)0);
} else {
  writer.Write((int) m_first_kills.Count);
 
  for (int i = 0; i > m_first_kills.Count; i++)
  {
    writer.Write((string) m_first_kills[i]);
  }
}

PlayerMobile AddFirstKill Function

Code:
public bool AddFirstKill(string creature_type)
{
  if (m_first_kills == null)
  {
    m_first_kills = new List<string>();
  }
 
  if (m_first_kills.Contains(creature_type))
  {
    return false;
  } else {
    m_first_kills.Add(creature_type);
    return true;
  }
 
  return false;
}

Finally BaseCreature OnDeath

Code:
if (pm != null && pm.AddFirstKill((string)this.getType()) == true)
{
  //add extra rewards here
}

Does that look right? and optimized?
 

Pure Insanity

Sorceror
Yes that should do it. Can even take the reward an extra step and base the reward on a formula for how powerful the creature was, teamed with it being a rare first kill.
 
A thought, instead of building up a list that eventually will become cumbersome and capped, give each new player a memory item that is a list of all creatures to be killed. Delete the creature from the list once it has been killed, and delete the list from the player after it's empty. Upon killing a creature, check the player for the memory item, if it doesn't exist, that code is all done. After characters have depleted the list, there will be less data being stored / saved, and less code being processed each time a player kills something.
 

LordHogFred

Knight
I would suggest looking into using Xml Attachments to do something like this.
You could have a single Attachment that would have a bool for each mob to be killed, or as above it could have a list associated that slowly deleted mobs as they were killed and then deleted itself once the list was empty. Using an attachment would mean you wouldn't need to use the ugly approach of having a "tracking item" on the player.
 

Pure Insanity

Sorceror
You could just build it into the player, using attributes like he did above. That is if you aren't scared of working with your Mobile class like most of the forum is, just know what you're doing before trying it.

As Daemon said above. I believe this is a horrible idea, as you would first have to compile a long list of all the creatures on your shard and then keep this list maintained.

If you do like was mentioned above. You would only be adding to a list when a player kills something new, meaning no wasted memory for a creature that a player may never see in the world.

Saving a list of types does add a bit more to memory, but that's not a huge issue even for large shards. It's easy to upgrade a server to 16gb of memory these days, and you'd never ever need that much for RunUO.

Although if you do the way Daemon mentioned, you'd start off with max memory and work your way down. A complete list for every character, including shit that they may never ever see on the game. This sounds more like a waste of time to compile a list, and space/memory for starting with a full list.

Either way...you can do this a bunch of different ways, so it's up to you. Just the thread starter asked for the most optimized way, and imo...making a list as he kills something new would be more optimized.
 

Tresdni

Squire
Save it as an array, that's my suggestion.

Kill the monster, if this type not in array, add it, then reward. Else, continue on.
 
Top