• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved How to construct party?

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
I'm trying to create a party with Lua lines, but I can't seem to construct the Party userdata.
Can it be done in Lua? If not, what I need to do so I could make Party like that: Party(userdata)
 
Found this, maybe something works

Code:
party:addInvite(player)
party:addMember(player)
party:disband()
party:getInviteeCount()
party:getInvitees()
party:getLeader()
party:getMemberCount()
party:getMembers()
party:isSharedExperienceActive()
party:isSharedExperienceEnabled()
party:removeInvite(player)
party:removeMember(player)
party:setLeader(player)
party:setSharedExperience(active)
party:shareExperience(experience)
 
Found this, maybe something works

Code:
party:addInvite(player)
party:addMember(player)
party:disband()
party:getInviteeCount()
party:getInvitees()
party:getLeader()
party:getMemberCount()
party:getMembers()
party:isSharedExperienceActive()
party:isSharedExperienceEnabled()
party:removeInvite(player)
party:removeMember(player)
party:setLeader(player)
party:setSharedExperience(active)
party:shareExperience(experience)
Theese are function if you alrady have the party.
Party is already a metatable, you might write over it if you re-define it with userdata.
Code:
function Party:onJoin(player)
    return true
end
https://github.com/otland/forgotten...7f82d10769f205c/data/events/scripts/party.lua
Yet its not listed in the functions.

EDIT: But I found something interesting thanks to your hint.
<event class="Party" method="onJoin" enabled="0" />
This needs to be turned OFF then this method works.

EDIT2: However this wont still create new instance of party to use and manipulate.
Nice, Why this change has not taken place in master branch yet?
 
Last edited:
@Printer
How do you create party with your code?
Party(playerUserdata) does not work for me

(I compiled your changes to source in linux)

When I loop trough Party metatable, I also see no option to create it.
 
Code:
local party = Party(player)
if party then
print("Party has been created.")
else
print("Fail to create party.")
end
 
Code:
local party = Party(player)
if party then
print("Party has been created.")
else
print("Fail to create party.")
end
yep, doesnt work.
Sais Party is table value

Err: attempt to call global Party (a table value)

EDIT:

NVM me.. I was testing it on wrong server not on the one I did source edits. Yep works perfectly.
 
Last edited:
Is it possible to activate Shared Exp by LUA script when there is no option available for client? If so, does anyone have it?
 
A few months ago I did something like this:
Code:
diff --git a/src/luascript.cpp b/src/luascript.cpp
index 24cde70..d6d042a 100644
--- a/src/luascript.cpp
+++ b/src/luascript.cpp
@@ -2187,6 +2187,7 @@ void LuaScriptInterface::registerFunctions()
     registerMethod("Player", "getSlotItem", LuaScriptInterface::luaPlayerGetSlotItem);
+    registerMethod("Player", "createParty", LuaScriptInterface::luaPlayerCreateParty);
     registerMethod("Player", "getParty", LuaScriptInterface::luaPlayerGetParty);
     registerMethod("Player", "addOutfit", LuaScriptInterface::luaPlayerAddOutfit);
@@ -7474,6 +7475,7 @@ int LuaScriptInterface::luaPlayerCreate(lua_State* L)
     return 1;
}
+
int LuaScriptInterface::luaPlayerIsPlayer(lua_State* L)
{
     // player:isPlayer()
@@ -8721,6 +8723,32 @@ int LuaScriptInterface::luaPlayerGetSlotItem(lua_State* L)
     return 1;
}
+int LuaScriptInterface::luaPlayerCreateParty(lua_State* L)
+{
+    // player:createParty(targetPlayer[, joinTargetPlayer = false])
+    Player* player = getUserdata<Player>(L, 1);
+    Player* targetPlayer = getUserdata<Player>(L, 2);
+    if (!player || !targetPlayer) {
+        lua_pushnil(L);
+        return 1;
+    }
+
+    Party* partyPlayer = player->getParty();
+    Party* partyInvitedPlayer = targetPlayer->getParty();
+
+    if (!partyPlayer && !partyInvitedPlayer) {
+        partyPlayer = new Party(player);
+        partyPlayer->invitePlayer(*targetPlayer);
+        bool joinTargetPlayer = getBoolean(L, 3, false);
+        if (joinTargetPlayer) {
+            partyPlayer->joinParty(*targetPlayer);
+        }
+        pushUserdata<Party>(L, partyPlayer);
+        setMetatable(L, -1, "Party");
+    }
+    return 1;
+}
+
int LuaScriptInterface::luaPlayerGetParty(lua_State* L)
{
     // player:getParty()
diff --git a/src/luascript.h b/src/luascript.h
index 3f50e63..543de7f 100644
--- a/src/luascript.h
+++ b/src/luascript.h
@@ -928,6 +928,7 @@ class LuaScriptInterface
         static int luaPlayerGetSlotItem(lua_State* L);
+        static int luaPlayerCreateParty(lua_State* L);
         static int luaPlayerGetParty(lua_State* L);
         static int luaPlayerAddOutfit(lua_State* L);



You can use like this:
Code:
local other_player = Player(players[2])
player:createParty(other_player, true)
local party = player:getParty()
party:setSharedExperience(true)
for j = 3, 5 do
    local other_player = Player(players[j])
     party:addInvite(other_player)
    party:addMember(other_player)
end
 
Is it possible to activate Shared Exp by LUA script when there is no option available for client? If so, does anyone have it?
It's possible.
I don't have it.
What you need to do is pass unique exp value trough the addExperience() to activate custom exp part.

So lets say the maximum exp you can get at once is 20000.
This means whenever you add 20001 exp. You know its custom.
and it automatically uses different formula player:addExperince(exp-20000)
we need this because we don't want stackoverflow.


Only thing you need to do now is divide the exp in Player;onGainExperience(source, exp, rawExp) trough teammembers and give them divedExp+20000
now the same script executes again. but now it gets over 20000 exp and it will know that this exp came from party share. So it no longer divides it.

I prolly was too complicated and most likely there are better solutions. But this is how I would do that xD
 
Back
Top