Skip to content

Commit

Permalink
v0.3.0-beta release.
Browse files Browse the repository at this point in the history
Reworked use logic (now more like source engine).
Add 'SJD_IsMapConfigured' native.
Fix bug in 'IsMapConfigured' logic.
Fix bug in 'CheckMapsWithNoDoorsCfg' logic.
Loops cleanup.
  • Loading branch information
Kailo97 committed Jun 12, 2015
1 parent fbe5fce commit 190b1ad
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 19 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
v0.3.0-beta
Reworked use logic (now more like source engine).
Add 'SJD_IsMapConfigured' native.
Fix bug in 'IsMapConfigured' logic.
Fix bug in 'CheckMapsWithNoDoorsCfg' logic.
Loops cleanup.
1 change: 1 addition & 0 deletions ToDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add use sound for buttons.
9 changes: 9 additions & 0 deletions addons/sourcemod/scripting/include/smartjaildoors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ native void SJD_CloseDoors();
*/
native void SJD_ToggleDoors();

/**
* Check if exist doors config for said map.
*
* @param num2 String with map name for check.
* @return
*/
native bool SJD_IsMapConfigured(const char[] mapName);

public SharedPlugin:__pl_smartjaildoors =
{
name = "smartjaildoors",
Expand All @@ -56,5 +64,6 @@ public __pl_smartjaildoors_SetNTVOptional()
MarkNativeAsOptional("SJD_OpenDoors");
MarkNativeAsOptional("SJD_CloseDoors");
MarkNativeAsOptional("SJD_ToggleDoors");
MarkNativeAsOptional("SJD_IsMapConfigured");
}
#endif
113 changes: 94 additions & 19 deletions addons/sourcemod/scripting/smartjaildoors.sp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>

#define PLUGIN_VERSION "0.2.1-beta"
// Changelog:
// Loops cleanup.
#define PLUGIN_VERSION "0.3.0-beta"

#include <sdktools>
#include <topmenus>
Expand All @@ -25,6 +23,7 @@

//Compile defines
#define CONFIRM_MENUS
#define NEW_USE_LOGIC

public Plugin myinfo =
{
Expand All @@ -44,6 +43,11 @@ public Plugin myinfo =
// Distance before button for active
#define BUTTON_USE 64.0

#define BUTTON_HEIGHT 52.2

//Distance from button top as radius sphere where u can use button
#define USE_AREA 15.0

KeyValues g_kv;

typeset DoorHandler
Expand Down Expand Up @@ -93,6 +97,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("SJD_OpenDoors", Native_SJD_OpenDoors);
CreateNative("SJD_CloseDoors", Native_SJD_CloseDoors);
CreateNative("SJD_ToggleDoors", Native_SJD_ToggleDoors);
CreateNative("SJD_IsMapConfigured", Native_SJD_IsMapConfigured);

RegPluginLibrary("smartjaildoors");

Expand Down Expand Up @@ -169,15 +174,14 @@ bool ExecuteDoors(DoorHandler handler, any data = 0)

char name[64], clsname[64];
do {
int result;
g_kv.GetSectionName(name, sizeof(name));
g_kv.GetString("class", clsname, sizeof(clsname));
Call_StartFunction(null, handler);
Call_PushString(name);
Call_PushString(clsname);
if (data != 0)
Call_PushCell(data);
Call_Finish(result);
Call_Finish();
} while (g_kv.GotoNextKey());

g_kv.Rewind();
Expand Down Expand Up @@ -220,6 +224,8 @@ void DeleteDoor(const char[] name)
g_kv.JumpToKey("doors");
g_kv.JumpToKey(name);
g_kv.DeleteThis();
if (!g_kv.GotoFirstSubKey())
g_kv.DeleteThis();
g_kv.Rewind();
g_kv.ExportToFile(DATAFILE);
}
Expand Down Expand Up @@ -329,6 +335,55 @@ public Action OnPlayerRunCmd(int client, int &f_buttons, int &impulse, float vel

if (f_buttons & IN_USE == IN_USE && g_oldButtons[client] & IN_USE != IN_USE)
{
#if defined NEW_USE_LOGIC
if (HaveButtonsInCfg()) {
char mapName[64];
GetCurrentMap(mapName, sizeof(mapName));
if (IsMapConfigured(mapName)) {
g_kv.JumpToKey(mapName);
g_kv.JumpToKey("buttons");
g_kv.GotoFirstSubKey();

int counter;
float buttonPos[2048][3];
do
g_kv.GetVector("pos", buttonPos[counter++]);
while (g_kv.GotoNextKey());

g_kv.Rewind();

for (int i = 0; i < counter; i++)
buttonPos[i][2] += BUTTON_HEIGHT;

float ang[3];
GetClientEyeAngles(client, ang);
float vec[3];
GetAngleVectors(ang, vec, NULL_VECTOR, NULL_VECTOR);
float eyePos[3];
GetClientEyePosition(client, eyePos);

float temp_vec[3], temp_pos[3];
bool used;
for (float i = 0.0; i <= BUTTON_USE; i++) {
temp_vec = vec;
ScaleVector(temp_vec, i);
temp_pos = eyePos;
for (int i2 = 0; i2 < sizeof(eyePos); i2++)
temp_pos[i2] += temp_vec[i2];

for (int i2 = 0; i2 < counter; i2++)
if (DistanceBetweenPoints(buttonPos[i2], temp_pos) <= USE_AREA) {
used = true;
OnPressButton();
break;
}

if (used)
break;
}
}
}
#else
if (HaveButtonsInCfg()) {
int target = GetClientAimTarget(client, false);
if (target != -1) {
Expand Down Expand Up @@ -369,7 +424,7 @@ public Action OnPlayerRunCmd(int client, int &f_buttons, int &impulse, float vel
g_kv.GetVector("pos", buttonpos);
g_kv.Rewind();

buttonpos[2] = buttonpos[2] + 52.2;
buttonpos[2] = buttonpos[2] + BUTTON_HEIGHT;

float origin[3];
GetClientEyePosition(client, origin);
Expand All @@ -382,6 +437,7 @@ public Action OnPlayerRunCmd(int client, int &f_buttons, int &impulse, float vel
}
}
}
#endif
}

g_oldButtons[client] = f_buttons;
Expand Down Expand Up @@ -477,13 +533,12 @@ public int ConfirmMenu(Menu menu, MenuAction action, int param1, int param2)

void ExecuteConfirmMenuHandler(int client, ConfirmMenuHandler handler, bool result, any data = 0)
{
int callresult;
Call_StartFunction(null, handler);
Call_PushCell(client);
Call_PushCell(result);
if (data != 0)
Call_PushCell(data);
Call_Finish(callresult);
Call_Finish();
}
#endif

Expand Down Expand Up @@ -548,7 +603,6 @@ bool ExecuteButtons(ButtonHandler handler, any data = 0)

char buffer[8];
float origin[3];
int result;
do {
g_kv.GetSectionName(buffer, sizeof(buffer));
g_kv.GetVector("pos", origin);
Expand All @@ -557,7 +611,7 @@ bool ExecuteButtons(ButtonHandler handler, any data = 0)
Call_PushArray(origin, 3);
if (data != 0)
Call_PushCell(data);
Call_Finish(result);
Call_Finish();
} while (g_kv.GotoNextKey());

g_kv.Rewind();
Expand Down Expand Up @@ -698,6 +752,20 @@ public void CloseDoor(const char[] name, const char[] clsname, any data)
}
}

bool IsMapConfigured(const char[] mapName)
{
if (!g_kv.JumpToKey(mapName))
return false;

if (!g_kv.JumpToKey("doors")) {
g_kv.Rewind();
return false;
}

g_kv.Rewind();
return true;
}

//** Menu Section **//
public Action Command_SJDMenu(int client, int args)
{
Expand Down Expand Up @@ -1208,6 +1276,20 @@ public int Native_SJD_ToggleDoors(Handle plugin, int numParams)
{
ToggleDoorsOnMap(true);
}

public int Native_SJD_IsMapConfigured(Handle plugin, int numParams)
{
int len;
GetNativeStringLength(1, len);

if (len <= 0)
return view_as<int>(false);

char[] mapName = new char[len + 1];
GetNativeString(1, mapName, len + 1);

return view_as<int>(IsMapConfigured(mapName));
}
//** End Native functions **//

//** Debug section **//
Expand Down Expand Up @@ -1237,23 +1319,16 @@ bool CheckMapsWithNoDoorsCfg(int client)
{
MapList.GetString(i, mapName, sizeof(mapName));

if (!g_kv.JumpToKey(mapName)) {
if (!IsMapConfigured(mapName)) {
mapsWithNoCfg[++mapsWithNoCfg[0]] = i;
allconfigured = false;
} else {
if (!g_kv.JumpToKey("doors")) {
mapsWithNoCfg[++mapsWithNoCfg[0]] = i;
allconfigured = false;
}

g_kv.Rewind();
}
}

if (!allconfigured) {
PrintToConsole(client, "Not configured maps:");
for (int i = 1; i <= mapsWithNoCfg[0]; i++) {
MapList.GetString(i, mapName, sizeof(mapName));
MapList.GetString(mapsWithNoCfg[i], mapName, sizeof(mapName));
PrintToConsole(client, "%s", mapName);
}
}
Expand Down

0 comments on commit 190b1ad

Please sign in to comment.