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!

Any help :?: (real newb at c# scripting)

Staunch

Wanderer
Any help :?: (real newb at c# scripting)

ok, I was trying to modify the gambling stone to make the options on it changable and it was a disaster :p so I was wondering if anyone could look at my modified version and tell me what I'm doing wrong.

[code:1]
// Gambling Stone
// By zero
using System;
using Server.Items;

namespace Server.Scripts.Items
{
public class GamblingStone : Item
{
private int m_GamblePot = 2500;
private int m_GambleAmount = 250;
private int m_GambleJackpotChance = 1;
private int m_GambleRegbagChance = 20;
private int m_GambleBigCheckChance = 40;
private int m_GambleSmallCheckChance = 100;
private int m_GambleRegBagAmount = 50;
private int m_GambleJackpotStart = m_GamblePot;

[CommandProperty( AccessLevel.GameMaster )]
public int GamblePot
{
get
{
return m_GamblePot;
}
set
{
m_GamblePot = value;
}
}
public int GambleJackpotChance
{
get
{
return m_GambleJackpotChance;
}
set
{
m_GambleJackpotChance = value;
}
}
public int RegbagChance
{
get
{
return m_RegbagChance;
}
set
{
m_RegbagChance = value;
}
}
public int GambleBigCheckChance
{
get
{
return m_GambleBigCheckChance;
}
set
{
m_GambleBigCheckChance = value;
}
}
public int GambleSmallCheckChance
{
get
{
return m_GambleSmallCheckChance;
}
set
{
m_GambleSmallCheckChance = value;
}
}
public int GambleRegBagAmount
{
get
{
return m_GambleRegBagAmount;
}
set
{
m_GambleRegBagAmount = value;
}
}
public int GambleJackpotStart
{
get
{
return m_GambleJackpotStart;
}
set
{
m_GambleJackpotStart = value;
}
}

[Constructable]
public GamblingStone() : base( 0xED4 )
{
Movable = false;
Hue = 0x56;
Name = "a gambling stone";
}

public override void OnSingleClick( Mobile from )
{
base.OnSingleClick( from );
base.LabelTo( from, "Jackpot: {0}gp", m_GamblePot );
}

public override void OnDoubleClick( Mobile from )
{
Container pack = from.Backpack;

if ( pack != null && pack.ConsumeTotal( typeof( Gold ), m_GambleAmount ) )
{
m_GamblePot += 150;

int roll = Utility.Random( 999 );

if ( roll == ( m_GambleJackpotChance - 1 ) ) // Jackpot
{
from.SendMessage( 0x35, "You win the {0}gp jackpot!", m_GamblePot );
from.AddToBackpack( new BankCheck( m_GamblePot ) );

m_GamblePot = m_GambleJackpotStart;
}
else if ( roll <= ( m_GambleRegbagChance - 1 ) ) // Chance for a regbag
{
from.SendMessage( 0x35, "You win a bag of reagents!" );
from.AddToBackpack( new BagOfReagents( m_RegBagAmount ) );
}
else if ( roll <= ( m_GambleBigCheckChance - 1 ) ) // Chance for gold
{
from.SendMessage( 0x35, "You win 1500gp!" );
from.AddToBackpack( new BankCheck( 1500 ) );
}
else if ( roll <= ( m_GamblSmallCheckChance -1 ) ) // Another chance for gold
{
from.SendMessage( 0x35, "You win 1000gp!" );
from.AddToBackpack( new BankCheck( 1000 ) );
}
else // Loser!
{
from.SendMessage( 0x22, "You lose!" );
}
}
else
{
from.SendMessage( 0x22, "You need at least (0)gp in your backpack to use this.", m_GambleAmount );
}
}

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

public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );

writer.Write( (int) 0 ); // version

writer.Write( (int) m_GamblePot );
writer.Write( (int) m_GambleJackpotChance );
writer.Write( (int) m_GambleRegbagChance );
writer.Write( (int) m_GambleBigCheckChance );
writer.Write( (int) m_GambleSmallCheckChance );
writer.Write( (int) m_GambleRegBagAmount );
writer.Write( (int) m_GambleJackpotStart );
}

public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );

int version = reader.ReadInt();

switch ( version )
{
case 0:
{
m_GamblePot = reader.ReadInt();
m_GambleJackpotChance = reader.ReadInt();
m_GambleRegbagChance = reader.ReadInt();
m_GambleBigCheckChance = reader.ReadInt();
m_GambleSmallCheckChance = reader.ReadInt();
m_GambleRegBagAmount = reader.ReadInt();
m_GambleJackpotStart = reader.ReadInt();

break;
}
}
}
}
}
[/code:1]

*prepares to be flamed on everything he is doing wrong*
 

Staunch

Wanderer
oh, and btw, this is the error that occurs

Scripts: Compiling...done (6 errors, 0 warnings)
- Error: Scripts\Items\GamblingStone.cs: CS0103: (line 46, column 12) The name
'm_RegbagChance' does not exist in the class or namespace 'Server.Scripts.Items.
GamblingStone'
- Error: Scripts\Items\GamblingStone.cs: CS0103: (line 50, column 5) The name '
m_RegbagChance' does not exist in the class or namespace 'Server.Scripts.Items.G
amblingStone'
- Error: Scripts\Items\GamblingStone.cs: CS0236: (line 17, column 38) A field i
nitializer cannot reference the nonstatic field, method, or property 'Server.Scr
ipts.Items.GamblingStone.m_GamblePot'
- Error: Scripts\Items\GamblingStone.cs: CS0103: (line 132, column 45) The name
'm_RegBagAmount' does not exist in the class or namespace 'Server.Scripts.Items
.GamblingStone'
- Error: Scripts\Items\GamblingStone.cs: CS0103: (line 139, column 25) The name
'm_GamblSmallCheckChance' does not exist in the class or namespace 'Server.Scri
pts.Items.GamblingStone'
- Error: Scripts\Items\GamblingStone.cs: CS0236: (line 17, column 38) A field i
nitializer cannot reference the nonstatic field, method, or property 'Server.Scr
ipts.Items.GamblingStone.m_GamblePot'
Scripts: One or more scripts failed to compile
- Press return to exit
 
P

prettz

Guest
hrmmm

Well I looked over it a bit, and just found a few spelling errors... and some variables that didn't exist. However the compiler still seems to have a problem with:

[code:1]
private int m_GambleJackpotStart = m_GamblePot;
[/code:1]

It simpy does not like that ^^, the resulting error is:

Scripts: Compiling...done (2 errors, 0 warnings)
- Error: Scripts\Items\GamblingStone.cs: CS0236: (line 17, column 42) A field i
nitializer cannot reference the nonstatic field, method, or property 'Server.Scr
ipts.Items.GamblingStone.m_GamblePot'

anyway.. here's the revised code that seems to work.. you'll just have to replace the m_GamblePot to something else

[code:1]
// By zero
using System;
using Server.Items;

namespace Server.Scripts.Items
{
public class GamblingStone : Item
{
private int m_GamblePot = 2500;
private int m_GambleAmount = 250;
private int m_GambleJackpotChance = 1;
private int m_GambleRegbagChance = 20;
private int m_GambleBigCheckChance = 40;
private int m_GambleSmallCheckChance = 100;
private int m_GambleRegBagAmount = 50;
private int m_GambleJackpotStart = m_GamblePot;

[CommandProperty( AccessLevel.GameMaster )]
public int GamblePot
{
get
{
return m_GamblePot;
}
set
{
m_GamblePot = value;
}
}
public int GambleJackpotChance
{
get
{
return m_GambleJackpotChance;
}
set
{
m_GambleJackpotChance = value;
}
}
public int RegbagChance
{
get
{
return m_GambleRegbagChance;
}
set
{
m_GambleRegbagChance = value;
}
}
public int GambleBigCheckChance
{
get
{
return m_GambleBigCheckChance;
}
set
{
m_GambleBigCheckChance = value;
}
}
public int GambleSmallCheckChance
{
get
{
return m_GambleSmallCheckChance;
}
set
{
m_GambleSmallCheckChance = value;
}
}
public int GambleRegBagAmount
{
get
{
return m_GambleRegBagAmount;
}
set
{
m_GambleRegBagAmount = value;
}
}
public int GambleJackpotStart
{
get
{
return m_GambleJackpotStart;
}
set
{
m_GambleJackpotStart = value;
}
}

[Constructable]
public GamblingStone() : base( 0xED4 )
{
Movable = false;
Hue = 0x56;
Name = "a gambling stone";
}

public override void OnSingleClick( Mobile from )
{
base.OnSingleClick( from );
base.LabelTo( from, "Jackpot: {0}gp", m_GamblePot );
}

public override void OnDoubleClick( Mobile from )
{
Container pack = from.Backpack;

if ( pack != null && pack.ConsumeTotal( typeof( Gold ), m_GambleAmount ) )
{
m_GamblePot += 150;

int roll = Utility.Random( 999 );

if ( roll == ( m_GambleJackpotChance - 1 ) ) // Jackpot
{
from.SendMessage( 0x35, "You win the {0}gp jackpot!", m_GamblePot );
from.AddToBackpack( new BankCheck( m_GamblePot ) );

m_GamblePot = m_GambleJackpotStart;
}
else if ( roll <= ( m_GambleRegbagChance - 1 ) ) // Chance for a regbag
{
from.SendMessage( 0x35, "You win a bag of reagents!" );
from.AddToBackpack( new BagOfReagents( m_GambleRegBagAmount ) );
}
else if ( roll <= ( m_GambleBigCheckChance - 1 ) ) // Chance for gold
{
from.SendMessage( 0x35, "You win 1500gp!" );
from.AddToBackpack( new BankCheck( 1500 ) );
}
else if ( roll <= ( m_GambleSmallCheckChance -1 ) ) // Another chance for gold
{
from.SendMessage( 0x35, "You win 1000gp!" );
from.AddToBackpack( new BankCheck( 1000 ) );
}
else // Loser!
{
from.SendMessage( 0x22, "You lose!" );
}
}
else
{
from.SendMessage( 0x22, "You need at least {0}gp in your backpack to use this.", m_GambleAmount );
}
}

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

public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );

writer.Write( (int) 0 ); // version

writer.Write( (int) m_GamblePot );
writer.Write( (int) m_GambleJackpotChance );
writer.Write( (int) m_GambleRegbagChance );
writer.Write( (int) m_GambleBigCheckChance );
writer.Write( (int) m_GambleSmallCheckChance );
writer.Write( (int) m_GambleRegBagAmount );
writer.Write( (int) m_GambleJackpotStart );
}

public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );

int version = reader.ReadInt();

switch ( version )
{
case 0:
{
m_GamblePot = reader.ReadInt();
m_GambleJackpotChance = reader.ReadInt();
m_GambleRegbagChance = reader.ReadInt();
m_GambleBigCheckChance = reader.ReadInt();
m_GambleSmallCheckChance = reader.ReadInt();
m_GambleRegBagAmount = reader.ReadInt();
m_GambleJackpotStart = reader.ReadInt();

break;
}
}
}
}
}
[/code:1]

I'm extremely new to C# so I couldn't really solve to problem, sorry :(

Ryousuke
 
Top