While using e2, you might find that some servers have plugins, like propcore, and others do not. Unfortunately, if you script your e2 to take advantage of a plugin, then it will error on servers that do not have the plugin.
However, one may use the functionality of #ifdef to avoid that.
#ifdef allows the e2 to check if a function exists. Not what it returns, but if the function is defined at all. However, it checks IF A FUNCTION IS DEFINED (Hi, jason!), NOT THE VARIABLE IT RETURNS!
Usage is like so-
Code:
#ifdef argument:aFunction( argument )
#else
#endif
The main part is the bit after ifdef. When using ifdef, the script has to know what arguments to check. If it doesn't know, then it will check for the wrong function. One mistake that may be made is as such
Code:
#ifdef applyForce()
print( "Applyforce is defined." )
#else
print( "Applyforce isn't defined." )
#endif
However, this will never be true. applyForce requires a vector, and thus when it checks for applyForce without the vector, it doesn't find a function, and so goes to the else.
You have to provide the proper types of arguments. If the function takes a vector, you would write
Code:
#ifdef applyForce( vector )
This would return true, unlike our earlier check. The same goes for array, number, string, etc.
You may be thinking at this point, "What use would this have to me?"
Well, it would, as mentioned above, allow you to check if the server has a plugin. For example,
Code:
#ifdef entity:setPos( vector )
#else
#endif
This would allow you to check if you could teleport your entities, as opposed to applyForcing them into place, for example
Code:
#ifdef entity:setPos( vector )
Prop:setPos( AVariablePosition )
#else
Prop:applyForce( ( AVariablePosition - Prop:pos() - Prop:vel() / 2 ) * Prop:mass() )
#endif
Additionally, its possible to forsake the #else, but it would be kind of pointless. You could at least print a warning and selfDestruct, or something.
Code:
#ifdef notAFunction()
print( "Wow." )
#endif
Well, I really can't think of anything else, so if you can think of anything, let me know. I think there was a guide before, but I searched and couldn't find one.
Bookmarks