Raised This Month: $32 Target: $400
 8% 

Only include if specific game


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-11-2020 , 20:36   Only include if specific game
Reply With Quote #1

Is it possible to include example #include "test.sp" only if the game is TF2? curious question
__________________
Teamkiller324 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-11-2020 , 21:44   Re: Only include if specific game
Reply With Quote #2

#include happens at compile time, I don't think the compiler knows what game it's compiling for, only when the plugin is running can you determine which game. Write the code in such a way that the checks happen while the plugin is active even if some include is for other games.

You can use #tryinclude <> so it will attempt to include but still compile if the file is missing. If you're using any natives from an optional include you should detect if the include loaded (e.g. using #if !defined _SomePlugin_included - a defined variable from the include file, most properly written includes will have this) to define the missing native and avoid using it. You also have to use MarkNativeAsOptional on any optional natives or the plugin will fail when they're missing. You can see my Prototype Grenades plugin as an example using this method.
__________________

Last edited by Silvers; 07-11-2020 at 21:45.
Silvers is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-11-2020 , 22:27   Re: Only include if specific game
Reply With Quote #3

Quote:
Originally Posted by Silvers View Post
#include happens at compile time, I don't think the compiler knows what game it's compiling for, only when the plugin is running can you determine which game. Write the code in such a way that the checks happen while the plugin is active even if some include is for other games.

You can use #tryinclude <> so it will attempt to include but still compile if the file is missing. If you're using any natives from an optional include you should detect if the include loaded (e.g. using #if !defined _SomePlugin_included - a defined variable from the include file, most properly written includes will have this) to define the missing native and avoid using it. You also have to use MarkNativeAsOptional on any optional natives or the plugin will fail when they're missing. You can see my Prototype Grenades plugin as an example using this method.
Thanks for the information

Have some bacon
__________________
Teamkiller324 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode