Humberd
Żal Adzi
- Joined
- Nov 7, 2009
- Messages
- 10
- Reaction score
- 9
I always wanted to start writing my own OTS, but what repelled me for years was a dynamic nature of lua and a very poor IDE support.
For the last few days I've been working on bringing static typing and full IDE support to the forgotten server.
Now, I can write scripts in Typescript, which then are transpiled to lua scripts.
Here is an example of a script that instantly kills a target creature.
Here is how it looks transpiled
Here is how it looks in my IDE, all the types are visible.
I get compilation errors and IDE highlights whenever I make some typing mistake.
In this screenshot I forgot to check if a target is null
I have a very nice autocomplete for enum types
I can also easily explore what each object has inside
What do you think?
For the last few days I've been working on bringing static typing and full IDE support to the forgotten server.
Now, I can write scripts in Typescript, which then are transpiled to lua scripts.
Here is an example of a script that instantly kills a target creature.
JavaScript:
const talkAction = new TalkAction(
'!kill_target',
'/kill_target',
'!kt',
'/kt',
);
talkAction.onSay((player, words, param) => {
const target = player.getTarget();
if (!target || !target.isCreature()) {
player.sendTextMessage(
MessageClasses.MESSAGE_STATUS_WARNING,
'You must target a creature to use this command.',
);
return false;
}
target.addHealth(-target.getHealth());
target.getPosition().sendMagicEffect(MagicEffectClasses.CONST_ME_MORTAREA);
player.sendTextMessage(MessageClasses.MESSAGE_STATUS_CONSOLE_BLUE, `Killed ${target.getName()}`);
return false;
});
talkAction.access(true);
talkAction.accountType(AccountType.ACCOUNT_TYPE_GOD);
talkAction.register();
export {};
Here is how it looks transpiled
Lua:
local ____exports = {}
local talkAction = TalkAction("!kill_target", "/kill_target", "!kt", "/kt")
talkAction:onSay(function(player, words, param)
local target = player:getTarget()
if not target or not target:isCreature() then
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You must target a creature to use this command.")
return false
end
target:addHealth(-target:getHealth())
target:getPosition():sendMagicEffect(CONST_ME_MORTAREA)
player:sendTextMessage(
MESSAGE_STATUS_CONSOLE_BLUE,
"Killed " .. target:getName()
)
return false
end)
talkAction:access(true)
talkAction:accountType(ACCOUNT_TYPE_GOD)
talkAction:register()
return ____exports
Here is how it looks in my IDE, all the types are visible.
I get compilation errors and IDE highlights whenever I make some typing mistake.
In this screenshot I forgot to check if a target is null
I have a very nice autocomplete for enum types
I can also easily explore what each object has inside
What do you think?