Quote:
Originally Posted by EthicalHacker007
I had a doubt, since pcvars are faster than cvars and efficient too. Can you please explain me what's the difference between pcvars and cvars? I've understood this.
|
This code will show you the general difference between the two:
PHP Code:
get_cvar_num(name[]) {
for (new i = 0; i < g_cvar_count; ++i) {
if (equal(name, g_cvar_list[i]))
return g_cvar_values[i];
}
return 0;
}
get_pcvar_num(pointer) {
return g_cvar_values[pointer];
}
Of course there is some extra safety internally, but this is the idea behind pcvars. They directly access the cvar while the old get_cvar natives have to search through a list of potentially thousands of cvars.
Quote:
Originally Posted by EthicalHacker007
PHP Code:
native ExecuteHamB(Ham:function, this, any:...);
So I did not get this. What does "Ham:function" "this" "any" means?
Also same with default include files
Thanks.
|
Quote:
Originally Posted by EthicalHacker007
And where is the predefined list? (noob questions)
|
Ham: refers to the Ham enum in ham_const.inc. If you remove all the documentation in ham_const.inc it looks like this:
PHP Code:
enum Ham {
Ham_Spawn = 0,
Ham_Precache,
Ham_Keyvalue,
// ...
}
It is there to ensure you actually pass in one of the Ham_* constants instead of a normal integer. This allows the compiler to give you a "tag mismatch" error if you don't do that.
any: is not a tag like all the others. any: is a
magic tag that tells the compiler to ignore the tag of the variable or constant you pass into the function. I'll explain it using one of the cellaray.inc natives:
If ArrayPushCell was defined without the any: tag the compiler would expect an integer to be passed as the second argument. It would issue a "tag mismatch" warning although it is clearly okay to store floats in an array. But we can't use Float:input either because then a tag mismatch would happen when we use an integer. any: gets rid of this and simply allows any tag. Here are three examples that show the different scenarios.
PHP Code:
native ArrayPushCell(Array:which, input);
function() {
ArrayPushCell(g_array, 1); // okay
ArrayPushCell(g_array, 1.0); // tag mismatch
}
PHP Code:
native ArrayPushCell(Array:which, Float:input);
function() {
ArrayPushCell(g_array, 1); // tag mismatch
ArrayPushCell(g_array, 1.0); // okay
}
PHP Code:
native ArrayPushCell(Array:which, any:input);
function() {
ArrayPushCell(g_array, 1); // okay
ArrayPushCell(g_array, 1.0); // okay
}
Quote:
Originally Posted by EthicalHacker007
Did not understood this, NVM. Will keep on learning.
|
Tags in AMXX are introduced by enums. When the plugin is compiled they only matter for some light type checking that will result in tag mismatch errors. Other than that they are standard integers and will be treated as such.
The Float: tag is another kind of magic tag in AMXX. Unlike a language like C for example Pawn has no real types. Everything in AMXX is a 32bit integer, called a
cell. Without the special Float: tag we wouldn't be able to work with floating point math in AMXX. All this magic happens in float.inc, where you will find things like this:
PHP Code:
native Float:operator+(Float:oper1, Float:oper2) = floatadd;
stock Float:operator+(Float:oper1, oper2)
return floatadd(oper1, float(oper2));
This is a light version of
operator overloading which can be found in C++ for example. This code means that this transformation will take place:
PHP Code:
// This code ...
new Float:fraction, Float:fraction2, number;
fraction = fraction + fraction2;
fraction = fraction2 + number;
PHP Code:
// ... will become this
new Float:float, Float:float2, int;
fraction = floatadd(fraction, fraction2);
fraction = floatadd(fraction, float(number));
The natives like floatadd, floatsub and the like are actually responsible for treating the numbers as floating point. Without this transformation anything would behave like an integer. Only the AMXX core actually knows what floats are!
Quote:
Originally Posted by EthicalHacker007
I don't understand what's this forward params and execute params. Can you please explain this in short, basic language? Thanks.
|
Consider Ham_Spawn:
PHP Code:
/**
* Description: This is typically called whenever an entity is created.
* It is the virtual equivilent of spawn from the engine.
* Some mods call this on player spawns too.
* Forward params: function(this)
* Return type: None.
* Execute params: ExecuteHam(Ham_Spawn, this);
*/
Ham_Spawn = 0,
Description tells you what this function is and when it is usually called. To find precise information for your mod you should search this forum or do some testing on your own.
Forward params tells you how your function will be called if you use RegisterHam. For example:
PHP Code:
RegisterHam(Ham_Spawn, "player", "ham_spawn");
// ...
public ham_spawn(this) {
// This is your forward function. It will only receive one parameter.
// In this case, "this" will actually refer to a "player" entity, as defined in RegisterHam's second parameter.
}
Return type tells you what the function returns when it runs. You need this information when you want to use the SetHamReturn* natives inside a Hamsandwich forward.
Execute params tells you how you should execute the function using ExecuteHam. This equivalent to the forward params of course.
this is simply the entity that the function has or should run on. So when you use RegisterHam with the
player entity class the
this parameter will refer to a
player entity, which is usually a client. The naming comes from the
this pointer in C++ as Hamsandwich deals with virtual functions of the various C++ classes that represent the entities inside of the engine. This is a technical detail you don't really need to understand (yet).
__________________