Hey all,

Need a hand on my first real script.
I'm trying to build some kind of bow, It already has the ammo but I need it to check for some item when you shoot the bow.
Code:
public override Type AmmoType {get { return typeof(Bolt); }}
public override Item Ammo {get { return new Bolt();}}
I found this but it seems like changing it to OnAttack won't work.
Code:
public override void OnDoubleClick( Mobile m )

the part I got (not working)
Code:
// starting of required item "theflame" to be able to shoot
 public override void Onattack( Mobile m )
 {
 Item a = m.Backpack.FindItemByType( typeof(theflame) );
 if ( a != null )
 {
 m.SendMessage( "You light up your bolts and are ready to fire..." ); 
 }
 else
 {
 m.SendMessage( "You don't got The Flame. My advise it to RUN" );
 }
 }
 // end of requiered item "theflame"
 
That needs to go in OnFired method

public override bool OnFired( Mobile attacker, Mobile defender )
{

don't forget to call base first so you can probably do like
bool fired = base.OnFired(attacker,defender);
if(fired)
{
insert your code

}
return fired;
}


Edit:

Having read your messages you give to player, I think you might as well do this upon equipping the bow. Not entirely sure as to how the bow works.
 
Last edited:
tnx for the help.
This is what I came up with already
But giving me an error
Not all code paths return a value.

Code:
using System;
using Server.Network;
using Server.Items;
namespace Server.Items
{
  [FlipableAttribute(0xF50, 0xF4F)]
  public class Flame : BaseRanged
  {
  [Constructable]
  public Flame()
  : base(0xF50)
  {
  this.Weight = 7.0;
 this.Name = "Flames";
 this.Hue = 1644;
  }
  public Flame(Serial serial)
  : base(serial)
  {
  }
  public override Type AmmoType {get { return typeof(Bolt); }}
  public override Item Ammo {get { return new Bolt();}}
 public override int EffectID{ get{ return 0x36D4; } }
  public override WeaponAbility PrimaryAbility { get{ return WeaponAbility.ConcussionBlow;}}
  public override WeaponAbility SecondaryAbility { get{ return WeaponAbility.MortalStrike; }}
  public override int AosStrengthReq { get {return 100;}}
  public override int AosMinDamage { get{ return 60; } }
  public override int AosMaxDamage { get{ return Core.ML ? 80 : 80; }}
  public override int AosSpeed {get{ return 5; } }
  public override float MlSpeed { get{ return 0.35f; }}
  public override int OldStrengthReq {get { return 100; }}
  public override int OldMinDamage { get { return 60; }}
  public override int OldMaxDamage {get { return 80; }}
  public override int OldSpeed {get{ return 5; }}
  public override int DefMaxRange { get{return 12;}}
  public override int InitMinHits { get { return 100;}}
  public override int InitMaxHits {get{ return 150; }}
  
 
 // starting of required item "theflame" to be able to shoot
 
 public override bool OnEquip(Mobile from)
 {
 Item a = from.Backpack.FindItemByType( typeof(theflame) );
 if ( a != null)
 { 
 from.SendMessage( "You light up your bolts and are ready to fire..." );
 } 
 else
 {
 from.SendMessage( "You don't got The Flame." );
 }
 }
 //end of reqquired item "theflame"
 public override void Serialize( GenericWriter writer )
 {
 base.Serialize( writer );
 writer.Write( (int) 1 ); // version
 }
 
 public override void Deserialize(GenericReader reader)
 {
 base.Deserialize( reader );
 int version = reader.ReadInt();
 }
 
  }
}
 
This
public override bool OnEquip(Mobile from)

just do
public override bool OnEquip(Mobile from)
{
Item a = from.Backpack.FindItemByType( typeof(theflame) );
if ( a != null)
{
from.SendMessage( "You light up your bolts and are ready to fire..." );
}
else
{
from.SendMessage( "You don't got The Flame." );
}

return base.OnEquip(from);

}
 
Actually that won't work as you want it to though ... can you explain how you want the bow to work? I mean you've named your bow as the flame so that makes me slightly confused as to what your goal is.

For instance, if you want to use your flame to light up the bolts. You might as well have that flame checked for double click in your backpack ( again I have no clue how you intend this to work ).
Check if the FlamableBow is equipped for instance, that would have a field LightBolts or something you can set that to true. Obviously upon removal of item you set it to false. Or other way is check if you have flame in your backpack as you shoot the arrows.

There are many ways to approach whatever it is you want but I am not entirely sure as to how you want this to work.

Judging by the message "and you are ready to fire". You can also do a backpack check if there's a flame in your backpack that has been lit. If there isn't you can alert the player or something... yeah just figure out how you want it to work first.
 
Last edited:
Actually that won't work as you want it to though ... can you explain how you want the bow to work? I mean you've named your bow as the flame so that makes me slightly confused as to what your goal is.

I know, I changed the way it works a bit.
the onfire seemed silly when I thought about it a bit more.

For the moment what I'm trying to create is a bow that needs bolts and a special item to be able to shoot.
the Flame is just a wannabe flamethrower.
To be able to shoot it you need to have "The Flame" in your bags so you are able to put the bolts on fire.
the animation is the one from a fireball.

I hope it makes sense.

I'll try your solution.
 
ok it doesn't do what it needs to be doing :)
but the script loads now so tnx for that.
now to start looking for the correct way to deny it to be equipped if the required item isn't in the bags.

update: ok that was an easy fix. the required item seems to work.

hmmz I think I need to put the onfire part in it aswell. Now it checks only when you equip the bow. but it still keeps working when I take out the item after it's equipped.
 
Last edited:
Yeah try adding these two, as for Equip yeah make sure they can't equip without the torch.

public bool CanFire(Mobile m)
{
return m!= null && m.Alive && m.Backpack != null && m.Backpack.FindItemByType(typeof(Torch)) != null;
}
// starting of required item "theflame" to be able to shoot

public override bool OnFired(Mobile attacker, Mobile defender)
{
if (CanFire(attacker))
return base.OnFired(attacker, defender);
else
return false;
}

Replace Torch by whatever it is you have
 
@Boldunum tnx a lot.
It seems to be ok now.
this is the code so far (note that theflame is another script file)
Code:
using System;
using Server.Network;
using Server.Items;
namespace Server.Items
{
  [FlipableAttribute(0xF50, 0xF4F)]
  public class Flame : BaseRanged
  {
  [Constructable]
  public Flame()
  : base(0xF50)
  {
  this.Weight = 7.0;
 this.Name = "Flames";
 this.Hue = 1644;
  }
  public Flame(Serial serial)
  : base(serial)
  {
  }
  public override Type AmmoType {get { return typeof(Bolt); }}
  public override Item Ammo {get { return new Bolt();}}
 public override int EffectID{ get{ return 0x36D4; } }
  public override WeaponAbility PrimaryAbility { get{ return WeaponAbility.ConcussionBlow;}}
  public override WeaponAbility SecondaryAbility { get{ return WeaponAbility.MortalStrike; }}
  public override int AosStrengthReq { get {return 100;}}
  public override int AosMinDamage { get{ return 60; } }
  public override int AosMaxDamage { get{ return Core.ML ? 80 : 80; }}
  public override int AosSpeed {get{ return 5; } }
  public override float MlSpeed { get{ return 0.35f; }}
  public override int OldStrengthReq {get { return 100; }}
  public override int OldMinDamage { get { return 60; }}
  public override int OldMaxDamage {get { return 80; }}
  public override int OldSpeed {get{ return 5; }}
  public override int DefMaxRange { get{return 12;}}
  public override int InitMinHits { get { return 100;}}
  public override int InitMaxHits {get{ return 150; }}
  
 
 // Checking if the needed items are there to equip The Flame
 
 public override bool OnEquip(Mobile from)
 {
 Item a = from.Backpack.FindItemByType( typeof(theflame) );
 if ( a != null)
 { 
 from.SendMessage( "You light up your bolts and are ready to fire..." );
 } 
 else
 {
 from.SendMessage( "You don't got The Flame." );
 return false;
 }
 return base.OnEquip(from);
 }
 //end of equip check
 
 //check on attack if the required items are still there.
 public bool CanFire(Mobile m)
 {
 return m!= null && m.Alive && m.Backpack != null && m.Backpack.FindItemByType(typeof(theflame)) != null;
 }
 public override bool OnFired(Mobile attacker, Mobile defender)
 {
 if (CanFire(attacker))
 return base.OnFired(attacker, defender);
 
 else
 attacker.SendMessage("Are we cheating? No flame no fire");
 return false;
 }
 // end of attack check
 
 public override void Serialize( GenericWriter writer )
 {
 base.Serialize( writer );
 writer.Write( (int) 1 ); // version
 }
 
 public override void Deserialize(GenericReader reader)
 {
 base.Deserialize( reader );
 int version = reader.ReadInt();
 }
 
  }
}
 
Back