Skip to content

Commit 5cda43d

Browse files
Add native VScript_CreateInstance
1 parent 5414b2f commit 5cda43d

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

scripting/include/vscript.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ native HSCRIPT VScript_CreateScope(const char[] name, HSCRIPT parent = HSCRIPT_R
466466
*/
467467
native HSCRIPT VScript_CreateTable();
468468

469+
/**
470+
* Creates a new HSCRIPT instance, this is only to be used on non-entity script class that needs it's script instance created
471+
* @note You may need to manually set property to an instance to point where the newly created hscript are at
472+
*
473+
* @param class Script class an instance uses
474+
* @param instance Instance pointer address to use
475+
*
476+
* @return HSCRIPT of an instance, null if could not create one.
477+
*/
478+
native HSCRIPT VScript_CreateInstance(VScriptClass class, Address instance);
479+
469480
/**
470481
* Get all the classes used for vscript
471482
*
@@ -695,6 +706,7 @@ public void __pl_vscript_SetNTVOptional()
695706
MarkNativeAsOptional("VScript_CompileScriptFile");
696707
MarkNativeAsOptional("VScript_CreateScope");
697708
MarkNativeAsOptional("VScript_CreateTable");
709+
MarkNativeAsOptional("VScript_CreateInstance");
698710
MarkNativeAsOptional("VScript_GetAllClasses");
699711
MarkNativeAsOptional("VScript_GetClass");
700712
MarkNativeAsOptional("VScript_CreateClass");

scripting/vscript.sp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "include/vscript.inc"
44

5-
#define PLUGIN_VERSION "1.9.2"
5+
#define PLUGIN_VERSION "1.10.0"
66
#define PLUGIN_VERSION_REVISION "manual"
77

88
char g_sOperatingSystem[16];
@@ -126,6 +126,7 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iLen
126126
CreateNative("VScript_CompileScriptFile", Native_CompileScriptFile);
127127
CreateNative("VScript_CreateScope", Native_CreateScope);
128128
CreateNative("VScript_CreateTable", Native_CreateTable);
129+
CreateNative("VScript_CreateInstance", Native_CreateInstance);
129130
CreateNative("VScript_GetAllClasses", Native_GetAllClasses);
130131
CreateNative("VScript_GetClass", Native_GetClass);
131132
CreateNative("VScript_CreateClass", Native_CreateClass);
@@ -858,6 +859,11 @@ public any Native_CreateTable(Handle hPlugin, int iNumParams)
858859
return HScript_CreateTable();
859860
}
860861

862+
public any Native_CreateInstance(Handle hPlugin, int iNumParams)
863+
{
864+
return HScript_CreateInstance(GetNativeCell(1), GetNativeCell(2));
865+
}
866+
861867
public any Native_GetAllClasses(Handle hPlugin, int iNumParams)
862868
{
863869
ArrayList aList = List_GetAllClasses().Clone();

scripting/vscript/hscript.sp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ static Handle g_hSDKCallGetValue;
55
static Handle g_hSDKCallSetValue;
66
static Handle g_hSDKCallReleaseValue;
77
static Handle g_hSDKCallClearValue;
8+
static Handle g_hSDKCallRegisterInstance;
89
static Handle g_hSDKCallGetInstanceValue;
910
static Handle g_hSDKCallReleaseScope;
1011
static Handle g_hSDKCallReleaseScript;
@@ -18,6 +19,7 @@ void HScript_LoadGamedata(GameData hGameData)
1819
g_hSDKCallSetValue = CreateSDKCall(hGameData, "IScriptVM", "SetValue", SDKType_Bool, SDKType_PlainOldData, SDKType_String, SDKType_PlainOldData);
1920
g_hSDKCallReleaseValue = CreateSDKCall(hGameData, "IScriptVM", "ReleaseValue", _, SDKType_PlainOldData);
2021
g_hSDKCallClearValue = CreateSDKCall(hGameData, "IScriptVM", "ClearValue", SDKType_Bool, SDKType_PlainOldData, SDKType_String);
22+
g_hSDKCallRegisterInstance = CreateSDKCall(hGameData, "IScriptVM", "RegisterInstance", SDKType_PlainOldData, SDKType_PlainOldData, SDKType_PlainOldData);
2123
g_hSDKCallGetInstanceValue = CreateSDKCall(hGameData, "IScriptVM", "GetInstanceValue", SDKType_PlainOldData, SDKType_PlainOldData, SDKType_PlainOldData);
2224
g_hSDKCallReleaseScope = CreateSDKCall(hGameData, "IScriptVM", "ReleaseScope", _, SDKType_PlainOldData);
2325
g_hSDKCallReleaseScript = CreateSDKCall(hGameData, "IScriptVM", "ReleaseScript", _, SDKType_PlainOldData);
@@ -38,6 +40,11 @@ HSCRIPT HScript_CreateTable()
3840
return pHScript;
3941
}
4042

43+
HSCRIPT HScript_CreateInstance(VScriptClass pClass, Address pInstance)
44+
{
45+
return SDKCall(g_hSDKCallRegisterInstance, GetScriptVM(), pClass, pInstance);
46+
}
47+
4148
int HScript_GetKeyValue(HSCRIPT pHScript, int iIterator, ScriptVariant_t pKey, ScriptVariant_t pValue)
4249
{
4350
return SDKCall(g_hSDKCallGetKeyValue, GetScriptVM(), pHScript, iIterator, pKey.Address, pValue.Address);

0 commit comments

Comments
 (0)