Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckInstaLog Added #310

Merged
merged 8 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/jsdocs.html
DragonSlayer62 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before. If you look at the diff here, it contains changes to large portions of the JS docs that are unrelated to this change. Make sure only the portion of the file that you touched for this PR is included, please, otherwise it kills revision checking for those other parts of the document.

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
Loading