Skip to content

Instantly share code, notes, and snippets.

@qaisjp
Created November 22, 2014 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qaisjp/ff3cdd6a5ae16af550cd to your computer and use it in GitHub Desktop.
Save qaisjp/ff3cdd6a5ae16af550cd to your computer and use it in GitHub Desktop.
mtasa-blue patch for oop velocities
Index: MTA10/mods/shared_logic/lua/CLuaMain.cpp
===================================================================
--- MTA10/mods/shared_logic/lua/CLuaMain.cpp (revision 6938)
+++ MTA10/mods/shared_logic/lua/CLuaMain.cpp (working copy)
@@ -163,7 +163,7 @@
lua_classfunction ( luaVM, "getPosition", CLuaOOPDefs::GetElementPosition );
lua_classfunction ( luaVM, "getRotation", CLuaOOPDefs::GetElementRotation );
lua_classfunction ( luaVM, "getMatrix", CLuaOOPDefs::GetElementMatrix );
- lua_classfunction ( luaVM, "getVelocity", "getElementVelocity" );
+ lua_classfunction ( luaVM, "getVelocity", CLuaOOPDefs::GetElementVelocity );
lua_classfunction ( luaVM, "getByType", "getElementsByType" );
lua_classfunction ( luaVM, "getDistanceFromCentreOfMassToBaseOfModel", "getElementDistanceFromCentreOfMassToBaseOfModel" );
lua_classfunction ( luaVM, "getType", "getElementType" );
@@ -226,7 +226,7 @@
lua_classvariable ( luaVM, "position", CLuaFunctionDefs::SetElementPosition, CLuaOOPDefs::GetElementPosition );
lua_classvariable ( luaVM, "rotation", CLuaOOPDefs::SetElementRotation, CLuaOOPDefs::GetElementRotation );
lua_classvariable ( luaVM, "matrix", CLuaFunctionDefs::SetElementMatrix, CLuaOOPDefs::GetElementMatrix );
- lua_classvariable ( luaVM, "velocity", "setElementVelocity", "getElementVelocit" );
+ lua_classvariable ( luaVM, "velocity", CLuaFunctionDefs::SetElementVelocity, CLuaOOPDefs::GetElementVelocity );
lua_classvariable ( luaVM, "data", NULL, "getAllElementData" ); // TODO: .data["age"] = 1337;
lua_registerclass ( luaVM, "Element" );
Index: MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPDefs.h
===================================================================
--- MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPDefs.h (revision 6938)
+++ MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPDefs.h (working copy)
@@ -30,6 +30,7 @@
LUA_DECLARE ( GetElementPosition );
LUA_DECLARE ( GetElementRotation );
LUA_DECLARE ( SetElementRotation );
+ LUA_DECLARE ( GetElementVelocity );
LUA_DECLARE ( GetCameraMatrix );
LUA_DECLARE ( GetCameraPosition );
Index: MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp
===================================================================
--- MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp (revision 6938)
+++ MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp (working copy)
@@ -42,10 +42,10 @@
if ( !argStream.HasErrors () )
{
- CVector vector;
- pEntity->GetPosition ( vector );
+ CVector vecPosition;
+ pEntity->GetPosition ( vecPosition );
- lua_pushvector ( luaVM, vector );
+ lua_pushvector ( luaVM, vecPosition );
return 1;
}
else
@@ -55,6 +55,28 @@
return 1;
}
+int CLuaOOPDefs::GetElementVelocity( lua_State* luaVM )
+{
+ CClientEntity* pEntity = NULL;
+
+ CScriptArgReader argStream( luaVM );
+ argStream.ReadUserData( pEntity );
+
+ if ( !argStream.HasErrors() )
+ {
+ CVector vecVelocity;
+ CStaticFunctionDefinitions::GetElementVelocity( *pEntity, vecVelocity );
+
+ lua_pushvector( luaVM, vecVelocity );
+ return 1;
+ }
+ else
+ m_pScriptDebugging->LogCustom( luaVM, argStream.GetFullErrorMessage() );
+
+ lua_pushboolean( luaVM, false );
+ return 1;
+}
+
int CLuaOOPDefs::GetElementRotation ( lua_State* luaVM )
{
CClientEntity* pEntity = NULL;
Index: MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp
===================================================================
--- MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp (revision 6938)
+++ MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp (working copy)
@@ -375,7 +375,7 @@
lua_classfunction ( luaVM, "getParent", "getElementParent" );
lua_classfunction ( luaVM, "getAttachedElements", "getAttachedElements" );
lua_classfunction ( luaVM, "getAttachedTo", "getAttachedTo" );
- lua_classfunction ( luaVM, "getVelocity", "getElementVelocity" );
+ lua_classfunction ( luaVM, "getVelocity", "getElementVelocity", CLuaOOPDefs::GetElementVelocity );
lua_classfunction ( luaVM, "getID", "getElementID" );
lua_classfunction ( luaVM, "getZoneName", "getElementZoneName" );
lua_classfunction ( luaVM, "getAlpha", "getElementAlpha" );
@@ -429,7 +429,7 @@
lua_classvariable ( luaVM, "position", "setElementPosition", "getElementPosition", CLuaElementDefs::setElementPosition, CLuaOOPDefs::GetElementPosition );
lua_classvariable ( luaVM, "rotation", "setElementRotation", "getElementRotation", CLuaOOPDefs::SetElementRotation, CLuaOOPDefs::GetElementRotation );
lua_classvariable ( luaVM, "matrix", "setElementMatrix", "getElementMatrix", CLuaElementDefs::setElementMatrix, CLuaOOPDefs::GetElementMatrix );
- lua_classvariable ( luaVM, "velocity", "setElementVelocity", "getElementVelocity" );
+ lua_classvariable ( luaVM, "velocity", "setElementVelocity", "getElementVelocity", CLuaElementDefs::setElementVelocity, CLuaOOPDefs::GetElementVelocity );
//lua_classvariable ( luaVM, "data", "setElementData", "getElementData", CLuaOOPDefs::SetElementData, CLuaOOPDefs::GetElementData );
//lua_classvariable ( luaVM, "visibility", "setElementVisibleTo", "isElementVisibleTo", CLuaOOPDefs::SetElementVisibleTo, CLuaOOPDefs::IsElementVisibleTo ); // .visibility[john]=false
@@ -838,7 +838,7 @@
lua_classfunction ( luaVM, "hasPermissionTo", "hasObjectPermissionTo" );
lua_classfunction ( luaVM, "logOut", "logOut" );
lua_classfunction ( luaVM, "toggleControl", "toggleControl" );
- lua_classfunction ( luaVM, "triggerEvent", "triggerClientEvent" );
+ lua_classfunction ( luaVM, "triggerEvent", "triggerClientEvent" );
lua_classfunction ( luaVM, "outputChat", "outputChatBox", CLuaOOPDefs::OutputChat );
//lua_classfunction ( luaVM, "observeDisplay", "textDisplayAddObserver" ); // swap args
Index: MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h
===================================================================
--- MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h (revision 6938)
+++ MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h (working copy)
@@ -35,7 +35,9 @@
LUA_DECLARE ( GetElementPosition );
LUA_DECLARE ( GetElementRotation );
LUA_DECLARE ( SetElementRotation );
+ LUA_DECLARE ( GetElementVelocity );
+
// Camera
LUA_DECLARE ( GetCameraMatrix );
Index: MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp
===================================================================
--- MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp (revision 6938)
+++ MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp (working copy)
@@ -54,6 +54,28 @@
return 1;
}
+int CLuaOOPDefs::GetElementVelocity( lua_State* luaVM )
+{
+ CElement* pElement = NULL;
+
+ CScriptArgReader argStream( luaVM );
+ argStream.ReadUserData( pElement );
+
+ if ( !argStream.HasErrors() )
+ {
+ CVector vecVelocity;
+ CStaticFunctionDefinitions::GetElementVelocity( pElement, vecVelocity );
+
+ lua_pushvector( luaVM, vecVelocity );
+ return 1;
+ }
+ else
+ m_pScriptDebugging->LogCustom( luaVM, argStream.GetFullErrorMessage() );
+
+ lua_pushboolean( luaVM, false );
+ return 1;
+}
+
int CLuaOOPDefs::GetElementRotation ( lua_State* luaVM )
{
CElement* pElement = NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment