Closed TheCaJlaT closed 1 year ago
Labels (or offsets within compiled script) simply don't exist in JS. It will never work, no matter what you put in sa.json.
To provide this functionality in JavaScript one should convert those commands into CLEO Redux using its own SDK. You can look here for the first step https://re.cleo.li/docs/en/events.html#creating-your-own-events
In short, registerChatCommand
should use CLEO Redux SDK, and when the command 'test' is called in the game it should call TriggerEvent
with some predefined name, e.g. "OnChatCommand"
.
cleo_redux_sdk::trigger_event("OnChatCommand", '{"chatCommand": "test"}';
On JS side, a script should subscribe to such event using built-in addEventListener
function:
addEventListener("OnChatCommand", (event) => {
const chatCommand= event.data.chatCommand;
log(`Command ${chatCommand} is called`); // logs "Command test is called"
})
Faced with the problem of registering commands in SA:MP, by calling the SAMPFUNCS opcode, you need to pass a label to it, but there are no labels in JS, as in cleo. I tried to pass the function there, but I got an error:
[ERROR] Unknown argument type function in command sampRegisterChatCommand
Please tell me what needs to be passed to the opcode so that everything works? Opcode: https://wiki.blast.hk/gta-sa/opcodes/0B34 My code:Opcode in sa.json: Opcode in ./includes/Samp.js: