altmp / altv-issues

Issues and roadmap for alt:V project
93 stars 16 forks source link

[Bug] Requesting scaleforms don't work in key press events #228

Closed Unnvaldr closed 5 years ago

Unnvaldr commented 5 years ago

Expected Behavior

requestScaleformMovie should return proper scaleform handled, when loaded in keydown or keyup event

Current Behavior

requestScaleformMovie always return 0, when it is in keydown or keyup event

Possible Solution

N/A

Steps to Reproduce

You have to only execute this code (add some logging for scaleformHandle variable to see it's value) and press F12:

let localPlayer = alt.Player.local;
alt.on('keydown', (key) => {
    if(key == 0x7B) { //F12
        var scaleformHandle = null;
        var boardHandle = null;
        var renderTargetHandle = null;
        var renderTargetModel = game.getHashKey('prop_police_id_text');
        var renderTargetID = -1;
        var boardHandle = game.createObject(game.getHashKey('prop_police_id_board'), localPlayer.pos.x, localPlayer.pos.y, localPlayer.pos.z + 1, false, false, false);
        var boardRenderTargetHandle = game.createObject(renderTargetModel, localPlayer.pos.x, localPlayer.pos.y, localPlayer.pos.z + 1, false, false, false);
        scaleformHandle = game.requestScaleformMovie('mugshot_board_01');
        game.registerNamedRendertarget('id_text');
        game.linkNamedRendertarget(renderTargetModel);
        renderTargetID = game.getNamedRendertargetRenderId('id_text');
        new Promise((resolve, reject) => {
            let interval = alt.setInterval(() => {
                if(game.hasScaleformMovieLoaded(scaleformHandle) && renderTargetID !== -1) {
                    alt.clearInterval(interval);
                    return resolve(true);
                }
            }, 0);
        }).then(() => {
            game.beginScaleformMovieMethod(scaleformHandle, 'SET_BOARD');
            game.addScaleformMovieMethodParameterString('Everybody');
            game.addScaleformMovieMethodParameterString('Gordon Freeman');
            game.addScaleformMovieMethodParameterString('~ Black Mesa');
            game.addScaleformMovieMethodParameterString('loves');
            game.addScaleformMovieMethodParameterInt(0);
            game.addScaleformMovieMethodParameterInt(30);
            game.endScaleformMovieMethod();
            alt.on('update', () => {
                game.setTextRenderId(renderTargetID);
                game.drawScaleformMovie(scaleformHandle, 0.405, 0.37, 0.81, 0.74, 255, 255, 255, 255);
                game.setTextRenderId(game.getDefaultScriptRendertargetRenderId());
            });
        });
    }
});

Context (Environment)

N/A

Detailed Description

N/A

Possible Implementation

N/A

vadzz-dev commented 5 years ago

Most likely related to some gta scripting stuff, as a temp workaround you could wrap it in alt.nextTick

vadzz-dev commented 5 years ago

Moved to #231