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!

Some functions for a weapon

Thynro

Wanderer
Hey guys... 12 year sphere scripter here who decided to finally make the plundge to runuo. I am in the proccess of converting a 14 year old sphere server to runuo and I am pretty new to C# but I was hoping I could get a little help with this one....

I am trying to convert this section of sphere code here...

Code:
[ITEMDEF Paladin_Sword]
//Paladin's Weapon
ID=i_sword_broad
TYPE=t_weapon_sword
DAM={19 35}
SPEED=55 //edited by Thynro
SKILL=Swordsmanship
REQSTR=25
WEIGHT=3
SKILLMAKE= BLACKSMITHING 100.0, ARMSLORE 100.0, MAGERY 50.0
RESOURCES=10 i_ingot_frost
 
ON=@Create
    NAME=Sword of Truth
    ATTR=attr_magic|attr_newbie
    HITPOINTS=paladin_sword_hits
    color=0482
    MOREP=0 800 0
 
CATEGORY=TFL Additions
SUBSECTION=Paladin
DESCRIPTION=Sword of Truth
 
ON=@EQUIP
    f_paladin_equip
 
ON=@DAMAGE
//Karma -9000 or higher in the negative field, or hitting an undead npc activate
IF (<SRC.NPC>==BRAIN_UNDEAD) || (<SRC.KARMA> < -9000))
  SRC.DAMAGE={10 18}
  SRC.EFFECT=3,037b9,6,15,1
  SRC.SOUND=snd_SPELL_POISON
  RETURN 0
ENDIF

Now, I seem to have the basic of the item down (that took me a good while for my first day trying to learn C#) but I can't seem to figure out how I would call the karma and undead triggers like I was able to on sphere.

Here is what I have thus far....

Code:
using System;
using Server;

namespace Server.Items
{
    public class SwordofTruth : Broadsword
    {

        [Constructable]
        public SwordofTruth()
        {
            Name = "Sword of Truth";
            Weight = 3.0;
            Hue = 0x0482;
            LootType = LootType.Blessed;
            Attributes.WeaponDamage = 35;
            Attributes.WeaponSpeed = 55;
        }

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

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            }
    }
}

Again, i'm not even sure if i'm doing it right. I wanna try my best to convert all of my scripts but when I have a basic understanding of the triggers I need I will be in alot better shape.
 

Thynro

Wanderer
what I wanna do is have this weapon have a special affect when the player using the sword is attacking either an undead creature or a player with negative karma.
 

m309

Squire
You can make it an Undead Slayer (do more damage to undead), you can make it raise the players karma, lower the defenders karma, have spell effects on hit, etc etc - all sorts of stuff. What sort of "special effect" do you mean?
 

Thynro

Wanderer
I apologize, I have been trying to learn C# most of the night and I didn't explain myself clearly. The affect I want for it to have is an animation (a glowing white animation on the target) followed by a sound affect. (The poison sound effect if memory serves correct) If activated I also want it to do a little extra damage to the target.
 

m309

Squire
For the effect, see this:

Code:
public void FixedParticles(int itemID, int speed, int duration, int effect, EffectLayer layer)
        {
            Effects.SendTargetParticles(this, itemID, speed, duration, 0, 0, effect, layer, 0);
        }

If you look in ArmorIgnore.cs, you can find an example of the above.

And for the sound, something like:

Code:
from.PlaySound( 0x241 );

You may have to change the "from", and change the "0x241" to whatever sound you'd like. You can get the Sound ID's as well as listen to them all with Fiddler.
 

Thynro

Wanderer
What I truly seem to not be able to grasp is the conversions for the @ statements on sphere. such as on=@damage (target being attacked, trigger these things). Is there some sort of reference for these I can read?
 

Dian

Sorceror
Right. You should be able to do an override Onhit in your weapon script to give your damage mod

C#:
public override void OnHit(Mobile attacker, Mobile defender, double damageBonus)
{
    // Add your checks and modifiers
 
    base.OnHit(attacker, defender, damageBonus);
}
 

Thynro

Wanderer
Instead of double damage could I randomize a damage number. between 10 and 18? I dont want the sword too powerful lol
 

Thynro

Wanderer
I thought this code was trying to do double damage unless I was reading it incorrectly...

Code:
public override void OnHit(Mobile attacker, Mobile defender, double damageBonus)
{
    // Add your checks and modifiers
 
    base.OnHit(attacker, defender, damageBonus);
}
 

pooka01

Sorceror
Basically, the override keyword of the public override void OnHit, justs overrides the baseweapon's method only for that weapon, so you can do a chain if you wish.
you can do:
Code:
public override void OnHit(Mobile attacker, Mobile defender, double damageBonus)
{
     Console.WriteLine("i've hit");
     base.OnHit(attacker, defender, damageBonus);
}

and this will show that message, but still deliver the basic OnHit of baseweapon, as you did base.OnHit(..);
 

Dian

Sorceror
The word double that you are refering to is not in the sense of double damage, it is double integer, as the damageBonus isin itself, a double (rather than an int)

To randomize a number you can use Utility.Random(2, 10) and would be a number between 2 and 10, for example.

Hope that makes sense.
 

Thynro

Wanderer
Well so far I think i'm doing pretty decent considering im still learning... what I have is this. I am getting the effects desired except the damage to the target. I can't seem to get that working... and once I finally get all the modifiers working I need to base it all off of karma so only targets with -9000 karma is affected. Heres what I got.

Code:
}
        public override void OnHit(Mobile attacker, Mobile defender, double damageBonus) //On hit trigger
        { 
            attacker.PlaySound( 517 ); //Play Poison Sound for attacker
            defender.FixedEffect( 0x037B9, 35, 15 ); //Give glowing orb effect
            //defender.damage( 10 ) ; //Hurt target for 10 extra points
            base.OnHit(attacker, defender, damageBonus);
        }
    }
}
 

pooka01

Sorceror
Code:
if (defender.Karma <= -9000)
defender.Damage( 10, attacker );
should do it.

The second argument for damage is for from who he damage comes from, i guess, if you want a modifier, just do:
damageBonus *= 1.1; like that it will do 10% more damage.
 

ThatDudeJBob

Sorceror
With the Snippet blow i was able to get it to do what you were asking.

The weapon i used did 42-49ish damage to a mob with -8999 karma up to the positives. When i set the mobs Karma to -9000 to max negative karma it did from 80-90sih damage

PHP:
        public override void OnHit(Mobile attacker, Mobile defender, double damageBonus) //On hit trigger
        {
            if (defender.Karma <= -9000)//Checks if the defender's Karma -9000 to maxNegativeKarma
            {
                attacker.PlaySound( 517 ); //Play Poison Sound for attacker
                defender.FixedEffect( 0x037B9, 35, 15 ); //Give glowing orb effect
                damageBonus = 2;//Adds double damageBonus ( 1=Normal Damage 2=Double Damage 3 = Triple Damage .... )
            }
            base.OnHit(attacker, defender, damageBonus);//Hits the defender no matter what
        }

Hope its what you were looking for.

------------------------EDIT------------------------
After re-reading some of the post I saw this
Instead of double damage could I randomize a damage number. between 10 and 18? I dont want the sword too powerful lol

On this line
PHP:
                damageBonus = 2;//Adds double damageBonus ( 1=Normal Damage 2=Double Damage 3 = Triple Damage .... )
You can also set it to
PHP:
                damageBonus = 1.25;
When I did this it added about 10 damage instead of double.
 

Thynro

Wanderer
You guys are awesome. I really appreciate the help. The funny thing is I had the karma damage code pretty much how you did only I must have had a space where it wasn't needed.
 
Top