Skip to content

Commit 1573857

Browse files
committed
Merge branch 'colshape-type' of https://github.com/CrosRoad95/mtasa-blue into CrosRoad95-colshape-type
2 parents ce48bec + 8366fcd commit 1573857

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void CLuaColShapeDefs::LoadFunctions(void)
1919
CLuaCFunctions::AddFunction("createColRectangle", CreateColRectangle);
2020
CLuaCFunctions::AddFunction("createColPolygon", CreateColPolygon);
2121
CLuaCFunctions::AddFunction("createColTube", CreateColTube);
22+
CLuaCFunctions::AddFunction("getColShapeType", GetColShapeType);
2223
}
2324

2425
void CLuaColShapeDefs::AddClass(lua_State* luaVM)
@@ -34,10 +35,60 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
3435

3536
lua_classfunction(luaVM, "getElementsWithin", "getElementsWithinColShape");
3637
lua_classvariable(luaVM, "elementsWithin", NULL, "getElementsWithinColShape");
38+
39+
lua_classvariable(luaVM, "elementsWithin", NULL, "getElementsWithinColShape");
40+
lua_classvariable(luaVM, "shapeType", NULL, "getColShapeType");
3741

3842
lua_registerclass(luaVM, "ColShape", "Element");
3943
}
4044

45+
int CLuaColShapeDefs::GetColShapeType ( lua_State* luaVM )
46+
{
47+
// Verify the arguments
48+
CClientColShape* pColShape = nullptr;
49+
CScriptArgReader argStream ( luaVM );
50+
argStream.ReadUserData ( pColShape );
51+
52+
if ( !argStream.HasErrors ( ) )
53+
{
54+
// Grab our VM
55+
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
56+
if (pLuaMain)
57+
{
58+
switch ( pColShape->GetShapeType( ) )
59+
{
60+
case 0:
61+
lua_pushstring(luaVM, "Circle");
62+
break;
63+
case 1:
64+
lua_pushstring(luaVM, "Cuboid");
65+
break;
66+
case 2:
67+
lua_pushstring(luaVM, "Sphere");
68+
break;
69+
case 3:
70+
lua_pushstring(luaVM, "Rectangle");
71+
break;
72+
case 4:
73+
lua_pushstring(luaVM, "Polygon");
74+
break;
75+
case 5:
76+
lua_pushstring(luaVM, "Tube");
77+
break;
78+
default:
79+
lua_pushboolean(luaVM, false);
80+
}
81+
return 1;
82+
}
83+
}
84+
else
85+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) );
86+
87+
// Failed
88+
lua_pushboolean ( luaVM, false );
89+
return 1;
90+
}
91+
4192
int CLuaColShapeDefs::CreateColCircle(lua_State* luaVM)
4293
{
4394
CVector2D vecPosition;

Client/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ class CLuaColShapeDefs : public CLuaDefs
2424
LUA_DECLARE(CreateColRectangle);
2525
LUA_DECLARE(CreateColPolygon);
2626
LUA_DECLARE(CreateColTube);
27+
28+
LUA_DECLARE(GetColShapeType);
2729
};

Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CLuaElementDefs : public CLuaDefs
3838
LUA_DECLARE(IsElementWithinColShape);
3939
LUA_DECLARE(IsElementWithinMarker);
4040
LUA_DECLARE(GetElementsWithinColShape);
41+
LUA_DECLARE(GetColShapeType);
4142
LUA_DECLARE(GetElementDimension);
4243
LUA_DECLARE(GetElementZoneName);
4344
LUA_DECLARE(GetElementBoundingBox);

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
void CLuaColShapeDefs::LoadFunctions()
1515
{
1616
// Shape create funcs
17+
1718
CLuaCFunctions::AddFunction("createColCircle", CreateColCircle);
1819
CLuaCFunctions::AddFunction("createColCuboid", CreateColCuboid);
1920
CLuaCFunctions::AddFunction("createColSphere", CreateColSphere);
2021
CLuaCFunctions::AddFunction("createColRectangle", CreateColRectangle);
2122
CLuaCFunctions::AddFunction("createColPolygon", CreateColPolygon);
2223
CLuaCFunctions::AddFunction("createColTube", CreateColTube);
24+
CLuaCFunctions::AddFunction("getColShapeType", GetColShapeType);
2325
}
2426

2527
void CLuaColShapeDefs::AddClass(lua_State* luaVM)
@@ -32,11 +34,38 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
3234
lua_classfunction(luaVM, "Sphere", "createColSphere");
3335
lua_classfunction(luaVM, "Tube", "createColTube");
3436
lua_classfunction(luaVM, "Polygon", "createColPolygon");
35-
3637
lua_classfunction(luaVM, "getElementsWithin", "getElementsWithinColShape");
38+
lua_classfunction(luaVM, "getShapeType", "getColShapeType");
39+
40+
lua_classvariable(luaVM, "shapeType", nullptr, "getColShapeType");
3741
lua_registerclass(luaVM, "ColShape", "Element");
3842
}
3943

44+
int CLuaColShapeDefs::GetColShapeType ( lua_State* luaVM )
45+
{
46+
// Verify the arguments
47+
CColShape* pColShape = nullptr;
48+
CScriptArgReader argStream ( luaVM );
49+
argStream.ReadUserData( pColShape );
50+
51+
if ( !argStream.HasErrors( ) )
52+
{
53+
// Grab our VM
54+
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
55+
if (pLuaMain)
56+
{
57+
lua_pushnumber ( luaVM, pColShape->GetShapeType ( ) + 1); // start from 1 not 0
58+
return 1;
59+
}
60+
}
61+
else
62+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) );
63+
64+
// Failed
65+
lua_pushboolean ( luaVM, false );
66+
return 1;
67+
}
68+
4069
int CLuaColShapeDefs::CreateColCircle(lua_State* luaVM)
4170
{
4271
CVector2D vecPosition;

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ class CLuaColShapeDefs : public CLuaDefs
2525
LUA_DECLARE(CreateColRectangle);
2626
LUA_DECLARE(CreateColPolygon);
2727
LUA_DECLARE(CreateColTube);
28+
LUA_DECLARE(GetColShapeType);
2829
};

0 commit comments

Comments
 (0)