|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
Hey everyone
![]() I want to add a custom property to my player, and this property can take on an integer value anywhere between 0 and 20. how would I go about doing this ? regards
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#2 (permalink) |
|
Forum Novice
|
Make it like any other non-custom property:
Code:
private int m_YourNewProperty; // Adding new field
[CommandProperty( AccessLevel.GameMaster )] // Add this line if you want to modify it with the [props command in game
public int YourNewProperty // Adding property to access the field from another classes
{
get { return m_YourNewProperty; }
set { m_YourNewProperty = value; }
}
|
|
|
|
|
|
#3 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
BTW, the property is "Level". making a small little level system of my own.
Okay, that worked - players now have the property in [props list. now, what method do I use to assign the property a value, if a certain condition = true. so like: if (blah blah blah) { m.Level = ValurHere; } under which method would I do that ? and also, how do I get it to display the level under the characters name as a description ? ta for help so far regards
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#5 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
hahah ok,
well it needs to go into playermobile.cs. ok, the player level depends on the mobiles total skill value. when they reach a certain total skill value. they will be level 1. the next required total skill value = level 2 etc. SO, it will be something like this: Code:
if (m.SkillsTotal < 500)
m.Level = 0;
if (m.SkillsTotal >= 500 && m.SkillsTotal < 750)
m.Level = 1;
if (m.SkillsTotal >= 750 && m.SkillsTotal < 1000)
m.Level = 2;
if (m.SkillsTotal >= 1000 && m.SkillsTotal < 1450)
m.Level = 3;
if (m.SkillsTotal >= 1450 && m.SkillsTotal < 2000)
m.Level = 4;
if (m.SkillsTotal >= 2000 && m.SkillsTotal < 2500)
m.Level = 5;
if (m.SkillsTotal >= 2500 && m.SkillsTotal < 2900)
m.Level = 6;
if (m.SkillsTotal >= 2900 && m.SkillsTotal < 3500)
m.Level = 7;
if (m.SkillsTotal >= 3500 && m.SkillsTotal < 4050)
m.Level = 8;
if (m.SkillsTotal >= 4050 && m.SkillsTotal < 5100)
m.Level = 9;
if (m.SkillsTotal >= 5100 && m.SkillsTotal < 6200)
m.Level = 10;
if (m.SkillsTotal >= 6200 && m.SkillsTotal < 7050)
m.Level = 11;
if (m.SkillsTotal >= 7050 && m.SkillsTotal < 8050)
m.Level = 12;
if (m.SkillsTotal >= 8050 && m.SkillsTotal < 8900)
m.Level = 13;
if (m.SkillsTotal >= 8900 && m.SkillsTotal < 9900)
m.Level = 14;
if (m.SkillsTotal >= 9900 && m.SkillsTotal < 10800)
m.Level = 15;
if (m.SkillsTotal >= 10800 && m.SkillsTotal < 11750)
m.Level = 16;
if (m.SkillsTotal >= 11750 && m.SkillsTotal < 12000)
m.Level = 17;
if (m.SkillsTotal >= 12000 && m.SkillsTotal < 12750)
m.Level = 18;
if (m.SkillsTotal >= 12750 && m.SkillsTotal < 13500)
m.Level = 19;
if (m.SkillsTotal >= 13500)
m.Level = 20;
![]()
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#6 (permalink) |
|
Forum Novice
|
"Get" method of your Level property should be fine for those calculations. This method calls every time you try to check m_Level value. So:
Code:
private int m_Level; // Hm... Do we need it at all?..
[CommandProperty( AccessLevel.GameMaster )]
public int Level
{
get // This method return us the value of player's level
{
if ( Skills.Total < 500 ) return 0;
else if ( Skills.Total < 750 ) return 1;
else if ( Skills.Total < 1000 ) return 2;
... // So on till the last else statement
else return 20;
}
// set method doesn't need here as we never assign m_Level value, it always depends on other property (Skills.Total in your case)
}
Code:
public int GetLevel()
{
if ( Skills.Total < 500 ) return 0;
else if ( Skills.Total < 750 ) return 1;
else if ( Skills.Total < 1000 ) return 2;
... // So on till the last else statement
else return 20;
}
...
// and anywhere in code you want to know what is the player level. For example in OnEquip method of your UberSword
public override bool OnEquip( Mobile from )
{
if ( from is PlayerMobile && (PlayerMobile)from.GetLevel() < 3 )
{
from.SendMessage("Your level is too low to equip this Uber Sword");
return false;
}
else if ( !base.OnEquip(from)) return false;
return true;
}
|
|
|
|
|
|
#7 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
Haha yeh, I was using "GetLeve" before I asked for property, but I didnt know how to use it in other code, like you showed in that ubersword example. So now that I know, I can go back to the way I was using it, and will know how to refer to it in other scripts. thank you
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#8 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
Ok, decided just to use the property, as its more efficient for me in other scripts. however If I need to refer to the "level" property in other scripts like for example, and ubersword, the level property will need the"set" value in playemobile.cs wont ?
cause we removed it earlier
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#10 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
This is what ive done:
Code:
private int m_Level;
[CommandProperty( AccessLevel.GameMaster )]
public int Level (Mobile m)
{
get
{
if (m.SkillsTotal < 500) return 0;
else if (m.SkillsTotal >= 500 && m.SkillsTotal < 750) return 1;
else if (m.SkillsTotal >= 750 && m.SkillsTotal < 1000) return 2;
else if (m.SkillsTotal >= 1000 && m.SkillsTotal < 1450) return 3;
else if (m.SkillsTotal >= 1450 && m.SkillsTotal < 2000) return 4;
else if (m.SkillsTotal >= 2000 && m.SkillsTotal < 2500) return 5;
else if (m.SkillsTotal >= 2500 && m.SkillsTotal < 2900) return 6;
else if (m.SkillsTotal >= 2900 && m.SkillsTotal < 3500) return 7;
else if (m.SkillsTotal >= 3500 && m.SkillsTotal < 4050) return 8;
else if (m.SkillsTotal >= 4050 && m.SkillsTotal < 5100) return 9;
else if (m.SkillsTotal >= 5100 && m.SkillsTotal < 6200) return 10;
else if (m.SkillsTotal >= 6200 && m.SkillsTotal < 7050) return 11;
else if (m.SkillsTotal >= 7050 && m.SkillsTotal < 8050) return 12;
else if (m.SkillsTotal >= 8050 && m.SkillsTotal < 8900) return 13;
else if (m.SkillsTotal >= 8900 && m.SkillsTotal < 9900) return 14;
else if (m.SkillsTotal >= 9900 && m.SkillsTotal < 10800) return 15;
else if (m.SkillsTotal >= 10800 && m.SkillsTotal < 11750) return 16;
else if (m.SkillsTotal >= 11750 && m.SkillsTotal < 12000) return 17;
else if (m.SkillsTotal >= 12000 && m.SkillsTotal < 12750) return 18;
else if (m.SkillsTotal >= 12750 && m.SkillsTotal < 13500) return 19;
else if (m.SkillsTotal >= 13500) return 20;
else return 0;
}
}
Errors: + Mobiles/PlayerMobile.cs: CS1002: Line 2791: ; expected any suggestions ? ![]() ta
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#12 (permalink) | |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
Okay, awesome - its working very nicely now.
now, I need to add the level as a description under the players name, this is what I did: Code:
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );
list.Add(Level.ToString(this));
Quote:
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
|
#14 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
I'm having another small issue. I created a custom property in my playermobile.cs to refer to the players profession in other scripts (the profession gate sets each player profession number depending on the profession they select).
what I did looks like this: Code:
private int m_ProfessionNumber;
[CommandProperty( AccessLevel.GameMaster )]
public int ProfessionNumber
{
get { return m_ProfessionNumber; }
set { m_ProfessionNumber = value; }
}
I read the Serialize forum, and it only really goes into serialization of items. How do I serialize / deserialize a property ? thanks
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#15 (permalink) |
|
Forum Novice
|
All new properties should be serialized just after the version and version should be increased by 1. Usually version commented so you can easily find it:
Code:
public override void Serialize( GenericWriter writer )
{
... // Some code
writer.Write( (int) 26 ); // version // The old version was 25 (in my case), so I increased it by 1
// Here your new property should be serialized
writer.Write( m_ProfessionNumber ); // Serializing it
... // The rest code
}
Code:
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt(); // Here we read the version to know where to start deserializing
switch ( version ) // Checking the version
{
case 26: // It is 26, so we start player's loading from this point
{
m_ProfessionNumber = reader.ReadInt(); // The second serialized variable was our m_ProfessionNumber (the first was version), so we read it here
goto case 25; // And continue loading other properties
}
case 25:
... // The rest code
}
}
|
|
|
|
|
|
#16 (permalink) |
|
Forum Novice
Join Date: Dec 2006
Posts: 480
|
Thanks so much man, that worked perfectly, and I learnt a ton of new stuff - I like the way you explain everything you do, to help the person you're helping better understand it..
regards
__________________
legendsofkaine.page.tl
|
|
|
|
![]() |
| Bookmarks |
| Tags |
| custom, property |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|