Иконка ресурса

CSDM Menu 1.0.2

Нет прав для скачивания
Сообщения
2,722
Реакции
2,997
Помог
60 раз(а)
Код:
-#define IsPlayer(%1)                     (1 <= %1 <= MAX_PLAYERS)
+#define IsPlayer(%1)                     (1 <= %1 <= MaxClients)
 
Сообщения
108
Реакции
17
Помог
2 раз(а)
Сообщения
974
Реакции
51
Помог
10 раз(а)
mIDnight, I will add
Код:
stock FadeScreen(id) {
    static iScreenFade

    if(!iScreenFade)
        iScreenFade = get_user_msgid("ScreenFade")

    /*message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("ScreenFade"), {0,0,0}, id)*/
    message_begin(MSG_ONE_UNRELIABLE, iScreenFade, {0,0,0}, id)
    write_short(1<<10)
    write_short(1<<9)
    write_short(0x0000)
    write_byte(52)
    write_byte(g_iSettingColorRender[FadeColor][R])
    write_byte(g_iSettingColorRender[FadeColor][G])
    write_byte(g_iSettingColorRender[FadeColor][B])
    message_end()
}
 
Сообщения
108
Реакции
17
Помог
2 раз(а)
Code_0xABC why?

I mean what is the difference if you store it inside stock, its gonna be called every time when ScreenFade is called. Also it's not gonna be changed during runtime so its okey to be hardcoded. But if you really like to store it don't do it as static variable , better store it as normal global new variable inside
plugin_init()
 
Последнее редактирование:
Сообщения
974
Реакции
51
Помог
10 раз(а)
mIDnight, таким образом вы один раз воспльзуетесь get_user_msgid("ScreenFade") и закешируете id, в следующий раз уже будет старое значение
 
Последнее редактирование:
Сообщения
974
Реакции
51
Помог
10 раз(а)
Georg, зачем, если будет практически одно и тоже
3 Дек 2023
Код:
#include <amxmodx>

public plugin_init() {
    register_plugin("a", "b", "c");

    register_clcmd("say test", "test");
}

public test(id) {
    static iScreenFade;

    server_print("*** %i", iScreenFade);

    if(!iScreenFade)
        iScreenFade = get_user_msgid("ScreenFade");

    message_begin(MSG_ONE_UNRELIABLE, iScreenFade, {0,0,0}, id);
    write_short(1<<10);
    write_short(1<<9);
    write_short(0x0000);
    write_byte(52);
    write_byte(255);
    write_byte(100);
    write_byte(120);
    message_end();
}
3 Дек 2023
Code_0xABC, Тогда уж в plugin_init кэш делай
Вообще достаночно const gl_iScreenFade = 98
 
Сообщения
108
Реакции
17
Помог
2 раз(а)
Code_0xABC


C++:
#include <amxmodx>

new iScreenFade;

public plugin_init() {
    register_plugin("a", "b", "c");

    register_clcmd("say test", "test");

    iScreenFade = get_user_msgid("ScreenFade");
}

public test(id) {
//    static iScreenFade;

    server_print("*** %i", iScreenFade);

/*    if(!iScreenFade)
        iScreenFade = get_user_msgid("ScreenFade"); */

    message_begin(MSG_ONE_UNRELIABLE, iScreenFade, {0,0,0}, id);
    write_short(1<<10);
    write_short(1<<9);
    write_short(0x0000);
    write_byte(52);
    write_byte(255);
    write_byte(100);
    write_byte(120);
    message_end();
}

Result:

C++:
*** 98
mIDnight : test
*** 98
mIDnight : test
*** 98
mIDnight : test
*** 98
mIDnight : test
*** 98
mIDnight : test
 
Сообщения
974
Реакции
51
Помог
10 раз(а)
Разница в чем? При первом вызове стока, закешируется id сообщения
 
Сообщения
108
Реакции
17
Помог
2 раз(а)
Based on the test results, using a global variable initialized in plugin_init() is a more reliable and consistent approach. It ensures that the get_user_msgid
is initialized before any function calls that might rely on it.
Using a static variable might introduce timing-related issues, especially if the initialization code depends on certain conditions being met, and those conditions are not guaranteed when the function is first called.
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу