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.
![1705876334500.png 1705876334500.png](https://static3.otland.net/d/attachments/73/73147-8518605008d069b8b1394db679e7e8c7.jpg?hash=hRhgUAjQab)
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
![1705876449646.png 1705876449646.png](https://static3.otland.net/d/attachments/73/73148-ff670c299afb2f22263329e827da18f7.jpg?hash=_2cMKZr7Ly)
I have a very nice autocomplete for enum types
![1705876497889.png 1705876497889.png](https://static3.otland.net/d/attachments/73/73149-2f00b51c98b73a7739c64f5588e3edc9.jpg?hash=LwC1HJi3On)
I can also easily explore what each object has inside
![1705876568880.png 1705876568880.png](https://static3.otland.net/d/attachments/73/73150-cc35cebecde39234b422c0703fd899b0.jpg?hash=zDXOvs3jkj)
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.
![1705876334500.png 1705876334500.png](https://static3.otland.net/d/attachments/73/73147-8518605008d069b8b1394db679e7e8c7.jpg?hash=hRhgUAjQab)
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
![1705876449646.png 1705876449646.png](https://static3.otland.net/d/attachments/73/73148-ff670c299afb2f22263329e827da18f7.jpg?hash=_2cMKZr7Ly)
I have a very nice autocomplete for enum types
![1705876497889.png 1705876497889.png](https://static3.otland.net/d/attachments/73/73149-2f00b51c98b73a7739c64f5588e3edc9.jpg?hash=LwC1HJi3On)
I can also easily explore what each object has inside
![1705876568880.png 1705876568880.png](https://static3.otland.net/d/attachments/73/73150-cc35cebecde39234b422c0703fd899b0.jpg?hash=zDXOvs3jkj)
What do you think?