19.02.2014, 13:11
(
Последний раз редактировалось a3om; 20.02.2014 в 15:08.
)
System-oriented approach
Short description:This approach allows you to divide your gamemode into parts.
The structure of SOA:
- Including main libraries
- Including the core
- Including classes (file "classes.pwn" in "gamemode" directory is a list of systems and them params)
- Including some constants (colors or something else)
- Including config (you can store some data here, mysql configuration for example)
- Including global ("global" is global functions with no class, macros or variables maybe)
- - Including variables of systems (classes) required it.
- Including macros of systems (classes) required it.
- Including functions of systems (classes) required it.
- Including events of systems (classes) requires it.
The structure of some system (some class). Each system may include vars, macros, functions and events and have respectively four or fewer files. Further, the system if it's required may have objects. For example, if you have created a system "players", the object of this system would be an "player".
How to create the system?
1. Discribe the class in this way (file classes.pwn):
PHP код:
#define players. a_ // Allocate symbol for the system
#define a_@ "players" // Set the name of the system
#define a_@@ 0 // Set the number of the system
...
#define gamemode. b_
#define b_@ "gamemode"
#define b_@@ 1
#define vehicles. c_
#define c_@ "vehicles"
#define c_@@ 2
...
Variables (file "system.variables.pwn")
If you want to create objects of system, you have to write this:
PHP код:
/*!
- Objects Static
*/
#define Objects. Objects_
#define Object. Object_
#define CLASS_NAME Objects
#define CLASS_DATA Object
en(Data)
{
i.SomeIntVar;
f.SomeFloatVar;
i.SomeArrayOfVars[TheSizeOfTheArray];
}
nw[CountOfObjects]{Data};
#undef Objects
#undef Object
#define Objects[%0]. Objects[%0][Object_@
#define Object Objects[object]
#undef CLASS_NAME
#undef CLASS_DATA
PHP код:
new this.VarName, this.VarName2;
Then again if you want to create objects of system, you have to create some necessary macros:
PHP код:
#define object objectid
#define objectid.%0(%1) objects.%0(_:object,%1)
You also can add your own macros for any aims.
Functions (file "system.functions.pwn")
Functions may be created by simple way.
Normal functions of system:
PHP код:
is.Name()
{
// stock and integer function
}
ip.Name1(param0, param1, ...)
{
// public and integer function
}
in.Name2(param0, param1, ...)
{
// normal integer function
}
fs.Name3(param0, param1, ...)
{
// stock and float
}
bs.Name4()
{
// stock and bool
}
s - stock, n - normal, p - forward + public
Functions with objects (or methods):
PHP код:
is.SomeMethod(object)
{
// some actions over the object
}
PHP код:
// class "players"
is.Teleport(player, float:x, float:y, float:z)
{
Player.Pos.X = x; // Player.Pos.X ~ Player.Pos[0] ~ Players[player].Pos[0] ~ Players[player][Player_Pos][0]
Player.Pos.Y = y; // Player.Pos.Y ~ Player.Pos[1] ~ Players[player].Pos[1] ~ Players[player][Player_Pos][1]
Player.Pos.Z = z; // Player.Pos.Z ~ Player.Pos[2] ~ Players[player].Pos[2] ~ Players[player][Player_Pos][2]
player.SetPos(); // <- is the method set position to player
}
is.SetPos(player)
{
SetPlayerPos(player, Player.Pos.X, Player.Pos.Y, Player.Pos.Z);
}
is.GetPos(player)
{
GetPlayerPos(player, Player.Pos.X, Player.Pos.Y, Player.Pos.Z);
}
PHP код:
// class "players"
is.Connect(player) // it's event
{
// to call some method use:
player.SomeMethod(params); // player is the object
// to call normal function use:
players.NormalFunctions(params); // players is the system
// you also can write shortly
this.NormalFunctions(params); // If you locate in "players" system
thi.SomeMethod(params); // If you locate in "players" system and "player" is an object of this system.
one.SomeMethod(params); // the same
}
Events are divided into two types: for system, for object.
Examples:
PHP код:
// class "players"
cl.Connect(player) // is the same as "OnPlayerConnect"
{
// cl - callback (public function without forward)
// callback to the object
}
// class "gamemode"
cl.Init()
{
// callback to the system
}
// you also can make your own event
is.SomeEvent()
{
// do something
}
PHP код:
is.MoveToXYZ(player, float:x, float:y, float:z) // simple method
{
player.@Move();
// or
players.@Move(player);
// "Move" is the function, "@Move" is the event!
}
Example:
PHP код:
is.MoveToPlayer(player, player1)
{
players.GetPos(player1);
Player.Pos.X = Players[player1].Pos.X;
Player.Pos.Y = Players[player1].Pos.Y;
Player.Pos.Z = Players[player1].Pos.Z;
player.SetPos(player);
}
// or
is.MoveToPlayer(player, player1)
{
players.GetPos(player1);
for(i -> 3) Player.Pos[i] = Players[player1].Pos[i];
player.SetPos(player);
}
If you have any questions, post them here! I try to answer each of them.
I'm probably very poorly explained...