Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 07-08-2008, 05:51 AM   #1 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default Custom Properties

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
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 05:58 AM   #2 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

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; }
}
Soteric is offline   Reply With Quote
Old 07-08-2008, 07:03 AM   #3 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 07:15 AM   #4 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

I doubt anyone except you know where to use your new property It depends on your idea, on algorithm of your level system and etc.
Soteric is offline   Reply With Quote
Old 07-08-2008, 07:21 AM   #5 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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;
but I dont know what public method to put that under ? or how to create my own
__________________
legendsofkaine.page.tl
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 07:41 AM   #6 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

"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)
}
There is also another variant and I think better than making new property. You can just place a new method in PlayerMobile class. Let's say GetLevel(). Every time you need to calculate player's level you can call this method. For example:
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;
}
Hope it helps you to understand how methods and properties work
Soteric is offline   Reply With Quote
Old 07-08-2008, 07:46 AM   #7 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 08:06 AM   #8 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 08:15 AM   #9 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

You need "set" only if you plan to change Level value anywhere in scripts. But since you calculate this value using other properties "set" isn't needed
Soteric is offline   Reply With Quote
Old 07-08-2008, 08:24 AM   #10 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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;
			}
		}
why am I getting this error at the red line (which is "get"):

Errors:
+ Mobiles/PlayerMobile.cs:
CS1002: Line 2791: ; expected

any suggestions ?

ta
__________________
legendsofkaine.page.tl
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 08:37 AM   #11 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

You can't pass references to properties. This is a wrong code:
Code:
public int Level (Mobile m)
But in your case you doesn't need to do it. You are already in PlayerMobile class, that means "SkillsTotal < 500" should work without "m."
Soteric is offline   Reply With Quote
Old 07-08-2008, 09:14 AM   #12 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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));
that gave these errors:

Quote:
Errors:
+ Mobiles/PlayerMobile.cs:
CS1502: Line 2823: The best overloaded method match for 'int.ToString(string
)' has some invalid arguments
CS1503: Line 2823: Argument '1': cannot convert from 'Server.Mobiles.PlayerM
obile' to 'string'
what do I do to add it as a description ?
__________________
legendsofkaine.page.tl
typhoonbot is offline   Reply With Quote
Old 07-08-2008, 11:57 AM   #13 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

Nevermind, figured it out

for those that are interested, this is what I did:

list.Add("Level: " + this.Level.ToString());
__________________
legendsofkaine.page.tl
typhoonbot is offline   Reply With Quote
Old 07-10-2008, 05:22 AM   #14 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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; }
		}
It works, but I'm sure I need to serialize / deserialize it somewhere, becuase all cases of it (every player) is set back to 0 when the server restarts.

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
typhoonbot is offline   Reply With Quote
Old 07-10-2008, 06:02 AM   #15 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

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
}
Now deserializing:
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
	}
}
Don't mess the variables you serialize and deserialize. If you serialized Profession and then Level (just an example), then you first deserialize ONLY Profession and then Level. Server doesn't know what variables he serializes and deserializes, it's just reading bytes from file
Soteric is offline   Reply With Quote
Old 07-10-2008, 09:47 AM   #16 (permalink)
Forum Novice
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 480
Default

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
typhoonbot is offline   Reply With Quote
Reply

Bookmarks

Tags
custom, property


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5