gold wın lıke tokens
ı was tryıng to make my bag to earn extra gold when player kılls monster ıt was goıng to be lıke tokens but ı couldnt made ıt complıes but ıts not gıvıng golds when ı kıll a monster any ıdeas???
ı was tryıng to make my bag to earn extra gold when player kılls monster ıt was goıng to be lıke tokens but ı couldnt made ıt complıes but ıts not gıvıng golds when ı kıll a monster any ıdeas???
Code:
using System;
using Server;
using Server.Targeting;
using Server.Mobiles;
using Server.Gumps;
using Server.Network;
using System.Net;
using Server.Accounting;
using Server.Targets;
using Server.Scripts.Gumps;
using System.Collections;
using Server.Items;
using Server.ContextMenus;
using Server.Misc;
namespace Server.Items
{
public class GoldBag : Item
{
private int i_Owner, i_Gold;
[CommandProperty(AccessLevel.Administrator)]
public int Owner { get { return i_Owner; } set { i_Owner = value; InvalidateProperties(); } }
[CommandProperty(AccessLevel.Administrator)]
public int Gold { get { return i_Gold; } set { i_Gold = value; InvalidateProperties(); } }
[Constructable]
public GoldBag() : base( 3702 )
{
Stackable = false;
Name = "An Empty Gold Bag";
Hue = 1161;
Weight = 1.0;
LootType = LootType.Blessed;
}
public override void OnDoubleClick(Mobile from)
{
if ( this.IsChildOf( from.Backpack ) )
{
if (i_Owner == 0)
{
i_Owner = from.Serial;
Name = from.Name + "'s Gold Bag";
i_Gold = 0;
from.SendGump( new GoldsGump( from, this ) );
}
else if (from.Serial == i_Owner)
{
from.SendGump( new GoldsGump( from, this ) );
}
else if (from.AccessLevel >= AccessLevel.GameMaster)
{
from.SendMessage(1153, "Select a new owner for this Gold Bag.");
BeginSetOwner( from );
}
else
{
from.PlaySound(1074); //play no!! sound
from.SendMessage(1153, "This book is not yours and you cannot seem to write your name in it!");
}
}
else
from.SendMessage(1153, "The Gold Bag must be in your backpack to be used.");
}
public override bool OnDragDrop( Mobile from, Item item )
{
if ( item is Gold)
{
this.Gold = (this.Gold + item.Amount);
from.SendMessage(1281, "You added {0} gold to your bag.", item.Amount);
return true;
}
else
{
from.SendMessage ("You can only place gold in this bag.");
return false;
}
}
public void BeginSetOwner( Mobile from )
{
from.Target = new SetOwnerTarget( this );
}
public class SetOwnerTarget : Target
{
private GoldBag m_TL;
public SetOwnerTarget( GoldBag tl ) : base( 18, false, TargetFlags.None )
{
m_TL = tl;
}
protected override void OnTarget( Mobile from, object targeted )
{
if ( m_TL.Deleted )
return;
m_TL.EndSetOwner( from, targeted );
}
}
public void EndSetOwner( Mobile from, object obj )
{
if ( obj is PlayerMobile )
{
PlayerMobile m = obj as PlayerMobile;
if ( m.Alive )
{
if (!(this.Deleted))
{
if (m.Name != null)
{
this.Owner = m.Serial;
this.Name = m.Name + "'s Gold Bag";
from.SendMessage(1153, "You set the new owner as: {0}", m.Name);
m.SendMessage(1153, "You became the owner of a new Gold Bag.");
}
else
from.SendMessage(1153, "Your target doesn't have a name.");
}
else
from.SendMessage(1153, "The Bag was deleted before you selected your target.");
}
else
from.SendMessage(1153, "Your target is dead, please choose a target that is alive.");
}
else
from.SendMessage(1153, "Only players can be the owners of Gold Bag.");
}
public void BeginAddGolds( Mobile from )
{
from.Target = new AddGoldsTarget( this );
}
public class AddGoldsTarget : Target
{
private GoldBag m_TL;
public AddGoldsTarget( GoldBag tl ) : base( 18, false, TargetFlags.None )
{
m_TL = tl;
}
protected override void OnTarget( Mobile from, object targeted )
{
if ( m_TL.Deleted )
return;
m_TL.EndAddGolds( from, targeted );
}
}
public void EndAddGolds( Mobile from, object obj )
{
from.CloseGump( typeof( GoldsGump ) );
if ( obj is Item )
{
Item oldGold = obj as Item;
if ( oldGold.IsChildOf( from.Backpack ) )
{
if ( oldGold is Gold )
{
if (!(this.Deleted) && !(oldGold.Deleted))
{
this.Gold = (this.Gold + oldGold.Amount);
from.SendMessage(1281, "You added {0} gold to your bag.", oldGold.Amount);
oldGold.Delete();
}
}
else if ( oldGold is BankCheck )
{
if (!(this.Deleted) && !(oldGold.Deleted))
{
this.Gold = (this.Gold + ((BankCheck)oldGold).Worth);
from.SendMessage(1281, "You added check to your bag.", oldGold.Amount);
oldGold.Delete();
}
}
else
{
from.PlaySound(1069); //play Hey!! sound
from.SendMessage(1281, "Hey, don't try to rob the bank!!!");
}
}
else
from.SendMessage(1153, "This isn't in your backpack.");
}
else
from.SendMessage(1153, "This is not an item.");
from.SendGump( new GoldsGump( from, this ) );
}
public GoldBag( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( i_Gold );
writer.Write( i_Owner );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch (version)
{
case 0:
{
i_Gold = reader.ReadInt();
i_Owner = reader.ReadInt();
break;
}
}
}
}
public class GoldsGump : Gump
{
private Mobile m_From;
private GoldBag m_TL;
public GoldsGump( Mobile from, Item item ) : base( 50, 50 )
{
from.CloseGump( typeof( GoldsGump ) );
m_From = from;
if (!(item is GoldBag))
return;
GoldBag tl = item as GoldBag;
m_TL = tl;
AddPage(0);
AddBackground(40, 40, 360, 325, 5170);
AddImageTiled( 70, 75, 300, 250, 0xA40 );
AddAlphaRegion( 70, 75, 300, 250 );
AddLabel(165, 75, 1160, item.Name);
AddLabel(75, 100, 1153, "You have " + ((GoldBag)tl).Gold + " Golds.");
AddLabel(75, 150, 1160, @"How much Golds you want to take out?");
AddLabel(75, 125, 31, @"Add Golds to your Bag manually:");
AddButton(307, 130, 2460, 2461, 1, GumpButtonType.Reply, 0); //add Golds
AddBackground(125, 200, 195, 41, 9270); //text entry backgrounf
if (((GoldBag)tl).Gold >= 100000)
AddTextEntry(145, 211, 155, 21, 1160, 3, "100000"); //default text entry (where we write how much Golds)
else
AddTextEntry(145, 211, 155, 21, 1160, 3, "" + ((GoldBag)tl).Gold + "");
//Gold check
AddLabel(75, 180, 31, @"Write a check:");
AddImage(70, 200, 92);
AddButton(79, 207, 2474, 0, 2, GumpButtonType.Reply, 0);
//Gold item
AddLabel(280, 180, 31, @"Extract Golds:");
AddImage(325, 200, 92);
AddButton(334, 207, 2474, 0, 4, GumpButtonType.Reply, 0);
AddImage(70, 255, 7012);
AddImage(300, 255, 7012);
AddLabel(270, 322, 1160, "Made By Sidious");
AddLabel(70, 322, 1160, "Version 1.0.1");
}
public override void OnResponse( NetState state, RelayInfo info )
{
if ( m_TL.Deleted )
return;
else if ( info.ButtonID == 1 )
{
if (((GoldBag)m_TL).Gold <= 2000000000)
m_TL.BeginAddGolds( m_From );
else
m_From.SendMessage(1153, "This Gold Bag is full");
m_From.SendGump( new GoldsGump( m_From, m_TL ) );
}
else if ( info.ButtonID == 2 || info.ButtonID == 4 )
{
TextRelay tr_GoldAmount = info.GetTextEntry( 3 );
if(tr_GoldAmount != null)
{
int i_MaxAmount = 0;
try
{
i_MaxAmount = Convert.ToInt32(tr_GoldAmount.Text,10);
}
catch
{
m_From.SendMessage(1153, "Please make sure you write only numbers.");
}
if(i_MaxAmount > 0)
{
if (i_MaxAmount <= ((GoldBag)m_TL).Gold)
{
if (info.ButtonID == 4 )
{
if (i_MaxAmount <= 100000)
{
m_From.AddToBackpack(new Gold(i_MaxAmount));
m_From.SendMessage(1281, "You extracted {0} Golds from your Bag.", i_MaxAmount);
((GoldBag)m_TL).Gold = (((GoldBag)m_TL).Gold - i_MaxAmount);
}
else
m_From.SendMessage(1153, "You can't extract more then 100,000 Golds at 1 time.");
}
else if (i_MaxAmount >= 1000)
{
m_From.AddToBackpack(new BankCheck(i_MaxAmount));
m_From.SendMessage(1281, "You wrote a bank check in the value of {0} Golds.", i_MaxAmount);
((GoldBag)m_TL).Gold = (((GoldBag)m_TL).Gold - i_MaxAmount);
}
else
m_From.SendMessage(1153, "You can't write checks for less then 1,000 Golds.");
}
else
m_From.SendMessage(1153, "You don't have that many Golds in your Bag.");
}
m_From.SendGump( new GoldsGump( m_From, m_TL ) );
}
}
}
}
public class GiveGold
{
public static void CalculateGold(Mobile m, BaseCreature creature)
{
if (creature.IsBonded)
return;
double d_Resists = ((creature.PhysicalResistance + creature.FireResistance + creature.ColdResistance + creature.PoisonResistance + creature.EnergyResistance)/50);
if (d_Resists < 1.0)
d_Resists = 1.0;
int i_Hits = (creature.HitsMax/10);
double d_TempGolReward = (i_Hits + ((i_Hits * d_Resists)/10) );
int i_FameKarma = creature.Fame;
if (creature.Karma < 0)
i_FameKarma -= creature.Karma;
else
i_FameKarma += creature.Karma;
i_FameKarma = (i_FameKarma/250);
if (i_FameKarma < 0)
i_FameKarma = 0;
d_TempGolReward += i_FameKarma;
if (creature.AI == AIType.AI_Mage)
{
double d_Mage = ((creature.Skills[SkillName.Meditation].Value + creature.Skills[SkillName.Magery].Value + creature.Skills[SkillName.EvalInt].Value)/8);
d_TempGolReward += d_Mage;
}
if (creature.HasBreath)
{
double d_FireBreath = (creature.HitsMax/25);
d_TempGolReward += d_FireBreath;
}
int i_GolReward = ((int)d_TempGolReward);
i_GolReward = Utility.RandomMinMax((int)(i_GolReward*0.4), (int)(i_GolReward*0.5));
if (i_GolReward < 1)
i_GolReward = 1;
RewardGold(m, i_GolReward);
}
public static void RewardGold(Mobile m, int amount)
{
if (amount < 1)
return;
Item[] items = m.Backpack.FindItemsByType( typeof( GoldBag ) );
foreach( GoldBag tl in items )
{
if (tl.Owner == m.Serial && tl.Gold <= 2000000000)
{
tl.Gold = (tl.Gold + amount);
m.SendMessage(1281, "You recieved {0} Golds.",amount);
break;
}
}
}
}
}