[Question] How to share the same function?
#1

There are 2 files included:

test1.inc
PHP Code:
/*
// imitation lack of function
#if !defined  debug_1
stock debug_1() {
    print("debug file 1");
}
#endif*/ 
test2.inc
PHP Code:
#if !defined  debug_1
stock debug_1() {
    print(
"debug file 2");
}
#endif 
gamemode:
PHP Code:
#include <a_samp>
#include <test1> 
#include <test2>
main()
{
    print(
"\n----------------------------------");
    print(
" Blank Gamemode by your name here");
    print(
"----------------------------------\n");
    
    print(
"sta");
    
debug_1();
    print(
"eof");

One function debug_1();

Question: What are the methods of using directives? Condition: You can not delete function physically. One of the functions can be commented out and must operate the other

My method for some reason, causes an error:
HTML Code:
[12:35:10] sta
[12:35:10] Script[gamemodes/new.amx]: Run time error 6: "Invalid instruction"
Add: Method found. Decided:

test1.inc > If not available
PHP Code:
#if !defined  debug_1
#define debug_1 new_debug_1
stock debug_1() {
    print(
"debug file 1");
}
#endif 
test2.inc < used functions
PHP Code:
#if !defined  debug_1
#define debug_1 new_debug_1
stock debug_1() {
    print(
"debug file 2");
}
#endif 
gamemode:
PHP Code:
#include <a_samp>
#include <test1> //faworite functions
#include <test2> //alternative functions
main()
{
    print(
"\n----------------------------------");
    print(
" Blank Gamemode by your name here");
    print(
"----------------------------------\n");
    
    print(
"sta");
    
debug_1();
    print(
"eof");

Print if all included:
Code:
sta
debug file 1
eof
Print if one #include <test2> included:
Code:
sta
debug file 2
eof
Reply
#2

You can use states: https://sampforum.blast.hk/showthread.php?tid=570939
Reply
#3

The use of new and alternative functions. Method found. Decided

test1.inc > If not available
PHP Code:
#if !defined  debug_1
#define debug_1 new_debug_1
stock debug_1() {
    print(
"debug file 1");
}
#endif 
test2.inc < used functions
PHP Code:
#if !defined  debug_1
#define debug_1 new_debug_1
stock debug_1() {
    print(
"debug file 2");
}
#endif 
gamemode:
PHP Code:
#include <a_samp>
#include <test1> //faworite functions
#include <test2> //alternative functions
main()
{
    print(
"\n----------------------------------");
    print(
" Blank Gamemode by your name here");
    print(
"----------------------------------\n");
    
    print(
"sta");
    
debug_1();
    print(
"eof");

Print if all included:
Code:
sta
debug file 1
eof
Print if one #include <test2> included:
Code:
sta
debug file 2
eof
Reply
#4

Use y_hooks included in the YSI 4 library (documentation). This only works for native callbacks, if you want to do it with custom callbacks use an alternative method, such as naming them differently or ALS hooking.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)