Log in

View Full Version : New C++ script interface



foxtacles
05-20-2012, 05:41 PM
The next snapshot will come with the revised scripting interface. You can now write scripts in C, C++ and PAWN. C++ scripts are fully binary compatible, so you should be able to use any C++11 compiler to write scripts for vaultmp.

The C++ part now includes game object class wrappers to enable scripting in an object-oriented manner (with little to no overhead, though). For example, the rewritten example OnSpawn:


Void VAULTSCRIPT OnSpawn(ID object) noexcept
{
Player player(object);

if (player)
{
player.UIMessage("Hello, " + player.GetName() + "!");

Base pipboy = static_cast<Base>(0x00015038);

if (player.GetContainerItemCount(pipboy) == 0)
{
player.AddItem(pipboy);
player.EquipItem(pipboy);
}
}
}


In addition to that, C++ functions are now much more typesafe. Consider CreateTimer (CreateTimerEx, now overloaded):


Result example(const char* var1, UCount var2, ID var3) noexcept
{
return static_cast<Result>(0);
}

Void VAULTSCRIPT exec() noexcept
{
CreateTimer<const char*, UCount, ID>(example, static_cast<Interval>(500), "Example text", 123, static_cast<ID>(123123123123));
}


Template metaprogramming auto-generates the type specifier string for you. No chance to make an error anymore.

Oufz0r
05-21-2012, 11:20 AM
Is the next snapshot come with database ? :)

Aeronix
05-21-2012, 11:39 AM
Awesome, I'm going to try to train my C++ skills by making scripts in it :p.
I'm getting a little tired of PAWN's syntax therefore it is necessary.


Is the next snapshot come with database ?
I'm sure someone is going to create a simple file system with PAWN or C++.

I'm curious as to whether we can use includes such as Vectors, and Strings in the STD.

foxtacles
05-21-2012, 12:54 PM
I'm curious as to whether we can use includes such as Vectors, and Strings in the STD.

You can use everything from the C++11 standard library, basically every C++ extension / code you want. The only restriction is that you must not throw exceptions in your code (at least, you must not allow exceptions to leave the scope of your script)

Tomo
05-21-2012, 05:50 PM
Neat. Looking forward to trying this out properly.