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!

Switch & Levers interface

alambik

Sorceror
Switch & Levers interface

Here are two files for your switch and levers. By implementing them, you can make an action on anything (Item, Addon, Multi, Mobile...).

First file is a switch. You can easily transform it into a lever for example.
The other file is an interface allowing to define the actions on the target when switching on or off.

Here how to implement new actions:

- Add a the "switchable" intervace to the targeted object class

Example: a lift built as an addon.
Code:
	public class Lift : BaseAddon , Switchable
	{

- Implement the 2 following methods corresponding to the actions to do:
Code:
bool On(Mobile from)
...

bool Off(Mobile from)
...

- Add the switch ingame
Code:
[add switch

- Add the created target object
Example:
Code:
[add lift

- In the properties of the switch, make the "Target" field pointing on the created target object you just added

Some example of implementation:
A lift that go up/down
A light that switch on/off
A remote bomb
A trap activator/deactivator

Advantages:
- You can see the switch.
- You can activate something even if it's very very far away.
 

LordHogFred

Knight
Wow this looks great :).
I'll have to get this on my shard when I get home, something like this could be invaluable to making customs dungeons, houses and decoration.
 

alambik

Sorceror
TechnoLift

As an example, that comes from a SF/MedFan cross-over shard, here is a "TechnoLift".

How to make it work:

1) Add the TechnoLift:
[add technolift

2) Modify the properties
[props on the technolift
Choose: --> "AddOn" --> "ViewProperties"
Modify the following fields:
UpPosition : Up state position
DownPosition : Down state position
UpMap : Up state map
DownMap : Down state map

3) Add a switch and link it to the TechnoLift addon:
[add Switch
[props on the switch
Modify the field:
Target : select the TechnoLift

4) Optional:
If you want the switch to move with the lift:
[props on the TechnoLift
Choose: --> "AddOn" --> "ViewProperties"
Modify the field:
TheSwitch: target the switch you created


Some UO cyber-shards are currently developped.
I hope they will offer a new original sight to uo :)
Enjoy!
 

tink

Wanderer
Anyone else get this to work? I followed the instructions, changed all the props as indicated but its not moving. Anyone else?
 

alambik

Sorceror
I removed the in game state propety access from the script.
(for information of internal functionality: state values significatons are 1 for moving up , -1 for moving down, 0 for waiting switch to be switched: this prevent the switch to be used many time while going up or down)
Seems it confused some people.
Please don't PM me, just answer here.

I've retested the "TechnoLift" example as described, I encountered no pb.

The important thing is that you wan reuse Switchable for anything.
"TechnoLift" is just here as an exemple of "Switchable" interface.

(by the way, I've seen RunUO team are naming inteface with a "I" at the beginning, so if you want to be consistent, should be named "ISwitchable")
 

Viago

Knight
LordHogFred said:
Wow this looks great :).
I'll have to get this on my shard when I get home, something like this could be invaluable to making customs dungeons, houses and decoration.

my thoughts exactly.
 

Jarrod

Sorceror
Sorry for the PM yesterday, I normally do not PM anyone, but I thought you had perhaps overlooked something.

the lift is created with state 0 by default

On returns Off

Off says "if state is NOT equal 0 then begin"

As the state is 0 by default, the lift does not, and will not move.

If you set the state to 1 manually after creating the lift, when you activate it, it will move up or down twice in a row.

i.e. it is at 0, and should be moved up to 25 z
you click the switch
the lift moves up to 25 z
the lift reappears at 0 z and moves back up to 25 z again

the same applies for moving down.

unless of course you have modified your switch.cs ;)

Ill mess around with the lift a bit and post the results.
 

Jarrod

Sorceror
with this version all you do is set the UP Z and DOWN Z. link the switch to it, and the rest takes care of itself.

Code:
using System;
using Server;
using Server.Network;

namespace Server.Items
{
	public class Lift : BaseAddon , Switchable
	{

		private Item m_Switch;
		[CommandProperty( AccessLevel.GameMaster )]
		public Item TheSwitch
		{ get{ return m_Switch; } set{ m_Switch = value; } }

		private Point3D m_UpPosition;
		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D UpPosition
		{ get{ return m_UpPosition; } set{ m_UpPosition = value; } }

		private Point3D m_DownPosition;
		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D DownPosition
		{ get{ return m_DownPosition; } set{ m_DownPosition = value; } }

		private int m_Sound;
		[CommandProperty( AccessLevel.GameMaster )]
		public int Sound
		{ get{ return m_Sound; } set{ m_Sound = value; } }

		private int m_State;
		[CommandProperty( AccessLevel.GameMaster )]
		public int State
		{ get{ return m_State; } set{ m_State = value; } }

		[Constructable]
		public Lift()
		{
			AddComponent( new AddonComponent( 1997 ), 0, 0, 0 );
			Name="a lever";
			m_Sound=1301;
			m_State=1;
			m_UpPosition=Location;
			m_DownPosition=Location;
		}

		public bool On( Mobile from )
		{
			if (m_State != 1)
			{
				m_State=1;
				new InternalTimer(this,m_State,from,((from.Z-1 == Z) && (from.X == X) && (from.Y == Y))).Start();
				
				return true;
			}
			return false;
		}

		public bool Off( Mobile from )
		{
			if (m_State != 2)
			{
				m_State=2;
				new InternalTimer(this,m_State,from,((from.Z-1 == Z) && (from.X == X) && (from.Y == Y))).Start();
				
				return true;
			}
			return false;		
		}

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

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

			writer.Write( (int) 0 ); // version
			writer.Write( m_UpPosition );
			writer.Write( m_DownPosition );
			writer.Write( m_Sound );
			writer.Write( m_State );
			writer.Write( m_Switch );
		}

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

			int version = reader.ReadInt();
			m_UpPosition = reader.ReadPoint3D();
			m_DownPosition = reader.ReadPoint3D();
			m_Sound = reader.ReadInt();
			m_State = reader.ReadInt();
			m_Switch = reader.ReadItem();
		}

		private class InternalTimer : Timer
		{
			private Lift m_Lift;
			private int m_Counter;
			private int m_Offset;
			private Mobile m_Target;
			private bool m_MoveMobile;

			public InternalTimer( Lift Lift, int offset, Mobile target, bool moveMobile ) : base( TimeSpan.FromSeconds( 0 ), TimeSpan.FromSeconds( 0.1 ) )
			{
				m_Lift = Lift;
				m_Target = target;
				m_Offset = offset;
				m_Counter = 0;
				m_MoveMobile = moveMobile;
				Effects.PlaySound( m_Lift.Location, m_Lift.Map, m_Lift.Sound );
			}

			protected override void OnTick()
			{
				if (m_Offset == 1) // its down, now moving up
				{
					if (m_Lift.Z < m_Lift.UpPosition.Z) m_Lift.Z = m_Lift.Z + 1;
					if ( m_MoveMobile )
						m_Target.MoveToWorld( new Point3D(m_Lift.X, m_Lift.Y, m_Lift.Z+1), m_Lift.Map=m_Lift.Map);
					if (m_Lift.Z >= m_Lift.UpPosition.Z)
						Stop();
					 
				}
				if (m_Offset == 2) // its up, now moving down
				{
					if (m_Lift.Z > m_Lift.DownPosition.Z) m_Lift.Z = m_Lift.Z - 1;
					if ( m_MoveMobile )
						m_Target.MoveToWorld( new Point3D(m_Lift.X, m_Lift.Y, m_Lift.Z+1), m_Lift.Map=m_Lift.Map);
					if (m_Lift.Z <= m_Lift.DownPosition.Z)
						Stop();
					 
				}
		
			}
		}

	}
}
 

alambik

Sorceror
About "state", you were right.
To "fix", just initialize the attribute to "-1" for example.
(script has been updated).

About the use, it was not intended to work as you said.

The aim was to create a lift that you take for example to go in an underground...

Up, the lift is somewhere, at the earth level.
Down, you arrive in a donjon (somewhere in another place, and, why not, another map).

The effect of this is that you really feel you go progressivly underground using this lift (not like an "instant" teleporter). So it is important to define Up location & map, and Down location & map.

But your script is good for the lifts that does not "teleport" elsewhere. Good work.

;-) Thanks
 

Ali G

Wanderer
im trying to make a door be switchable and im not sure what to add with the

HTML:
bool On( Mobile from ) ;
          bool Off( Mobile from ) ;
	}
I dont know what the corresponding to the actions to do are.

im getting errors like this

HTML:
RunUO - [www.runuo.com] Version 1.0.0, Build 36918
Scripts: Compiling C# scripts...failed (2 errors, 0 warnings)
 - Error: Scripts\Customs\TheDoor.cs: CS0535: (line 3, column 15) 'Server.Items.
TheDoor' does not implement interface member 'Server.Items.Switchable.On(Server.
Mobile)'
 - Error: Scripts\Customs\TheDoor.cs: CS0535: (line 3, column 15) 'Server.Items.
TheDoor' does not implement interface member 'Server.Items.Switchable.Off(Server
.Mobile)'
Scripts: One or more scripts failed to compile or no script files were found.
 - Press return to exit, or R to try again.
 
Top