|
||
|
|||||||
| FAQ Forum A place to find answers to the most frequently asked questions, and a place to post said answers. Do NOT use this forum to ask questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Join Date: Oct 2004
Location: São Paulo - Brazil
Age: 27
Posts: 4
|
Intro
Sometimes you want to add a custom flag to the players, so you can control something, for example if they did or not a quest and if they will be able to do it again or not. Of course you don´t want to delete players and restart the shard etc. Description Go to \Scripts\Mobiles and open PlayerMobile.cs Now, look for private int m_Profession; just below it, place your flag/variable, as example:private bool m_test; Now, to keep this organized, lets add just below this declaration Code:
//test flag for quest of the tutorial
[CommandProperty( AccessLevel.GameMaster )]
public bool test
{
get{ return m_test; }
set{ m_test = value; }
}
Code:
switch ( version )
{
case 19:
{
m_test = reader.ReadBool();
goto case 18;
}
case 18:
{
m_SolenFriendship = (SolenFriendship)...
Code:
writer.Write( (int) 18 ); // version And finally, add below this last line, Code:
writer.Write( m_test ); Conclusion Adding custom flags can be a powerfull tool when designing a quest, and as this tutorial shows, its easy to implement, and can be easily accessed from other classes. Also note, the method above can use others variables too, with few changes. This tutorial was based in FSGov script by Ronin. Last edited by ygor; 04-16-2006 at 04:44 PM. |
|
|
|
|
|
#2 (permalink) | ||
|
Join Date: Oct 2004
Location: São Paulo - Brazil
Age: 27
Posts: 4
|
Intro
Although the method above is functional, it can begin to take some space and make code confusing! I got a reply from A_Li_N, and this part of the tutorial I will base on it! Description Quote:
Booleans have a good feature, as in example: (Atention! Binary!) Quest 1 -> 1=b00000001 Quest 2 -> 2=b00000010 Quest 3 -> 4=b00000100 Quest 4 -> 8=b00001000 Notice that you can have a unique number as the control of quests. For example, 7=4+2+1(b00111) ; 5=4+1(b00101); 12=8+4(b01100), etc! To convert a binary to hex, without the use of a calculator(the windows one does the trick) b010101010011 -> b 0101 0101 0011 0000=0 0001=1 0010=2 0011=3 0100=4 0101=5 0110=6 0111=7 1000=8 1001=9 1010=A 1011=B 1100=C 1101=D 1110=E 1111=F b010101010011 -> b 0101 0101 0011 -> h 5 5 3 -> 0x553 alright?! if you still completely lost, try this So, let´s code! by A_Li_N Code:
[Flags]
public enum CustomFlag
{
None = 0x00000000,
Quest1 = 0x00000001, //hex for binary 000001
Quest2 = 0x00000002, //hex for binary 000010
Quest3 = 0x00000004, //hex for binary 000100
Quest4 = 0x00000008, //hex for binary 001000
Quest5 = 0x00000010, //hex for binary 010000
Quest6 = 0x00000020 //hex for binary 100000
}
...
private CustomFlag m_CustomFlags;
...
public CustomFlag CustomFlags
{
get{ return m_CustomFlags; }
set{ m_CustomFlags = value; }
}
...
public bool GetFlag( CustomFlag flag )
{
return ( (m_CustomFlags & flag) != 0 );
}
public void SetFlag( CustomFlag flag, bool value )
{
if( value )
m_CustomFlags |= flag;
else
m_CustomFlags &= ~flag;
}
...
Deserialize(...)
{
...
m_CustomFlags = (CustomFlag)reader.ReadInt();
...
}
...
Serialize(...)
{
...
writer.Write( (int)m_CustomFlags );
...
}
Quote:
Its more compact, its more complex! The first method is fast and simple, but can eat some res from your server if the number increases. This part of tutorial cover a more professional approach, hope you enjoy! A special thanks to A_Li_N for the support! Last edited by ygor; 04-16-2006 at 02:44 PM. |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|