open.mp forum
[Pawn] I need help with Assembly (#emit or __emit) - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] I need help with Assembly (#emit or __emit) (/showthread.php?tid=2433)



I need help with Assembly (#emit or __emit) - Otakeiro - 2023-07-26

I want to make a simple hook through the #emit
PHP Code:
native CallLocalFunction(const funcname[], const format[], {Float,_}:...);
native printf(const output[], {Float,_}:...);

stock __CallLocalFunction(const funcname[], const format[], {Float,_}:...) {
    static retval;
    if(funcidx(funcname) == -1) {
        retval 0;
        printf("Function not defined: %s.\n"funcname);
    } else {
        if(numargs() == 2) {
            retval CallLocalFunction(funcnameformat);
        } else {
            // "emit" code to call function with args and return value to "retval"
        }
    }
    return retval;

I've tried using codes like SendClientMessageEx or EasyDialog, but I need it to return the value
If possible comment the code so I can study it


RE: I need help with Assembly (#emit or __emit) - N0FeaR - 2024-03-04

Try this

PHP Code:
native CallLocalFunction(const funcname[], const format[], {Float,_}:...);
native printf(const output[], {Float,_}:...);


stock __CallLocalFunction(const funcname[], const format[], {Float,_}:...) {
    static retval;


    if (funcidx(funcname) == -1) {

        retval 0;
        printf("Function not defined: %s.\n"funcname);
    } else {

        if (numargs() == 2) {

            retval CallLocalFunction(funcnameformat);
        } else {

            new arguments[128];
            formatex(argumentssizeof(arguments), format);


            #emit __emit_function_call funcname arguments
        }
    }


    return retval;
}


public 
__emit_function_call(const funcname[], arguments[]) {
    new Function:func funcidx(funcname);
    new result;

    switch (numargs(arguments)) {
        case 0result CallLocalFunction(funcname); break;
        case 1result CallLocalFunction(funcnamearguments[0]); break;
        case 2result CallLocalFunction(funcnamearguments[0], arguments[1]); break;

    }

    // Store the result
    retval result;