Skip to content

Commit

Permalink
Merge pull request #310 from DragonSlayer62/InstalogOut-function
Browse files Browse the repository at this point in the history
CheckInstaLog  Added
  • Loading branch information
Xoduz authored Jan 28, 2025
2 parents fd4b542 + c63670d commit 65633f5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/jsdocs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5564,6 +5564,35 @@ <h4>January 9th, 2022</h4>
</div>
</div>

<div class="spoilerWrapper">
<input type="checkbox" id="spoiler_function_misc_CheckInstaLog" />
<label for="spoiler_function_misc_CheckInstaLog">CheckInstaLog <i class="fas fa-angle-down"></i></label>
<div class="spoiler">
<div class="settingsDiv">
<p><span class="hl">Prototype</span></p>
<p><em>JSBool CheckInstaLog( x, y, world, instanceID );</em></p>
</div>
<div class="settingsDiv">
<p><span class="hl">Purpose</span></p>
<p>Checks if a specific location ( x, y, world, instanceID ) is within an instant logout zone.</p>
</div>
<div class="settingsDiv">
<p><span class="hl">Example of usage</span></p>
<pre><code class="language-javascript">// Check if the player is in an instant logout zone
var isInstaLog = CheckInstaLog(targX, targY, worldNumber, instanceID);

if( isInstaLog )
{
// Handle instant logout
}
else
{
// Handle other logout scenarios
}</code></pre>
</div>
</div>
</div>

<div class="spoilerWrapper">
<input type="checkbox" id="spoiler_function_item_CalcTargetedItem"/>
<label for="spoiler_function_item_CalcTargetedItem">CalcTargetedItem <i class="fas fa-angle-down"></i></label>
Expand Down
3 changes: 3 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
Corrected a misspelling of IsBoat in magic.js.
Added support for iterating through items in boats using FirstItem(), NextItem() and FinishedItems() methods

14/10/2024 - Dragon Slayer
    Added the CheckInstaLog JS function to allow checking if a specific location is within an instant logout zone (SEFunctions.cpp). (thanks, Xuri)

12/10/2024 - Dragon Slayer
Added Mini-House Addons from AOS Expansion.

Expand Down
40 changes: 40 additions & 0 deletions source/SEFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,46 @@ JSBool SE_CalcCharFromSer( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN
return JS_TRUE;
}

//o------------------------------------------------------------------------------------------------o
//| Function - SE_CheckInstaLog()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Checks if a specific location is within an instant logout zone
//o------------------------------------------------------------------------------------------------o
JSBool SE_CheckInstaLog( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
if( argc != 4 )
{
ScriptError( cx, "CheckInstaLog: Invalid number of parameters (4)" );
return JS_FALSE;
}

SI16 targX = static_cast<SI16>( JSVAL_TO_INT( argv[0] ));
SI16 targY = static_cast<SI16>( JSVAL_TO_INT( argv[1] ));
UI08 targWorld = static_cast<UI08>( JSVAL_TO_INT( argv[2] ));
UI16 targInstanceId = static_cast<UI16>( JSVAL_TO_INT( argv[3] ));

auto logLocs = cwmWorldState->logoutLocs;

*rval = JSVAL_FALSE;

if( logLocs.size() > 0 )
{
for( size_t i = 0; i < logLocs.size(); ++i )
{
if( logLocs[i].worldNum == targWorld && logLocs[i].instanceId == targInstanceId )
{
if(( targX >= logLocs[i].x1 && targX <= logLocs[i].x2 ) && ( targY >= logLocs[i].y1 && targY <= logLocs[i].y2 ))
{
*rval = JSVAL_TRUE;
return JS_TRUE;
}
}
}
}

return JS_TRUE;
}

//o------------------------------------------------------------------------------------------------o
//| Function - SE_DoMovingEffect()
//o------------------------------------------------------------------------------------------------o
Expand Down
2 changes: 2 additions & 0 deletions source/SEFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ SEngineFunc SE_CalcCharFromSer; // ***
SEngineFunc SE_CalcItemFromSer; // ***
SEngineFunc SE_CalcMultiFromSer; // ***

SEngineFunc SE_CheckInstaLog;

SEngineFunc SE_MakeItem; // ***

SEngineFunc SE_CommandLevelReq; // *
Expand Down
1 change: 1 addition & 0 deletions source/cScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static JSFunctionSpec my_functions[] =
{ "CalcCharFromSer", SE_CalcCharFromSer, 1, 0, 0 },
{ "CalcItemFromSer", SE_CalcItemFromSer, 1, 0, 0 },
{ "CalcMultiFromSer", SE_CalcMultiFromSer, 1, 0, 0 },
{ "CheckInstaLog", SE_CheckInstaLog, 4, 0, 0 },
{ "GetHour", SE_GetHour, 0, 0, 0 },
{ "GetMinute", SE_GetMinute, 0, 0, 0 },
{ "GetDay", SE_GetDay, 0, 0, 0 },
Expand Down

0 comments on commit 65633f5

Please sign in to comment.