• 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!

partyAddMember

Marcelo Druida

Intermediate OT User
Joined
Nov 17, 2014
Messages
429
Solutions
1
Reaction score
134
Location
Brazil
Hello OTLanders!
I'm using TFS 1.0:

Code:
int32_t LuaScriptInterface::luaPartyAddMember(lua_State* L)
{
    // party:addMember(player)
    Player* player = getPlayer(L, 2);
    Party* party = getUserdata<Party>(L, 1);
    if (party && player) {
        pushBoolean(L, party->joinParty(*player));
    } else {
        lua_pushnil(L);
    }
    return 1;
}

I want that when the party doesnt exist, the code auto create it
(maybe sending a table containing all members CID and random leader..)

Someone can help me?!

Thanks!
 
No!
You can only addMembers if the party already exists!
In my case, the party doesnt exist.

Ex Annihilator:
4 players are not in party.
Using the lever the script will create a party and add them
No invites needed
 
It wont work!!

Code:
int32_t LuaScriptInterface::luaPartyAddInvite(lua_State* L)
{
    // party:addInvite(player)
    Player* player = getPlayer(L, 2);
    Party* party = getUserdata<Party>(L, 1);
    if (party && player) {
        pushBoolean(L, party->invitePlayer(*player));
    } else {
        lua_pushnil(L);
    }
    return 1;
}

" Party* party = getUserdata<Party>(L, 1);"

there is not a userdata!
you cant create a party userdata as you do player (Player(cid))
 
Code:
local party = Party(...)
party:addMember(some_userdata)
Code:
local party = Party(...)
party:addInvite(some_userdata)
Code:
local player = Player(uid)
local player = Player(name or wildcard)
player returns userdata :)
 
if you think that is possible, help me

Code:
local function main(cid)

local party = Party(Player(cid))
party:addMember(cid)

end

Code:
local function main(cid)

local party = Party()
party:addMember(cid)

end

Code:
local function main(cid)

local party = Party(Player(cid):getParty())
party:addMember(cid)

end

attempt to call global 'Party' (a table value)
 
events.xml
Code:
    <event class="Party" method="onJoin" enabled="0" />
    <event class="Party" method="onLeave" enabled="0" />
    <event class="Party" method="onDisband" enabled="0" />
Write your methods in here or maybe rewrite these methods?
https://github.com/otland/forgottenserver/wiki/Metatable:Party
To work with these https://github.com/otland/forgottenserver/blob/master/src/party.cpp
Party.lua
Code:
function Party:onJoin(player)
    return true
end

function Party:onLeave(player)
    return true
end

function Party:onDisband()
    return true
end
Anyway that is what I would do.
 
Code:
function Player.someFunction(player, targetList)
    if(not player or type(targetList) ~= "table") then
        return false
    end
  
    local party = player:getParty()
    if(not party) then
        return false
    end
  
    for _, uid in pairs(targetList) do
        local targetPlayer = Player(uid)
        if(targetPlayer) then
            party:addMember(targetPlayer)
        end
    end
return true
end

https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp#L9387
The Player.getParty() returns the userdata of the party of nil.
That script should work, just use the function someFunction(array), array = the players that should be invited. The array can contain userdata values but you should use player:getId(), since it's better to push a uid value rather then a userdata value. But it's re-compiled anyways so it dosen't matter.

Oh: Btw you should always check if the player is there, not direcly using Player(cid):function(), trust me :p...
 
Code:
ps = Game.getPlayers()

    local party = Player(ps[1]):getParty()
    if(not party) then
        return false
    end

        local targetPlayer = Player(ps[2])
        if(targetPlayer) then
            party:addMember(targetPlayer)
        end

nothing happens

Code:
ps = Game.getPlayers()

    local party = Player(ps[1]):getParty()


        local targetPlayer = Player(ps[2])
        if(targetPlayer) then
            party:addMember(targetPlayer)
        end

attempt to index local party nil value
 
Re-read my script and post, as I said a userdata value gets returned nil when its empty.
A good way to learn this, is to try the "addEvent" function, ex. onUse then 10 secs later just push the userdata to teleport the player.
This will crash the server, that will make you learn to always use the "if(not userdata) then return false end" statment.

The problem with your script is that you are using Player(ps[1]):getParty(), you have to check if there is a player first, and then check if there is a party.
And it's better to use, "for _, uid in pairs(Game.getPlayers()) do" insted of picking out each player by the array[number].
 
I took all the necessary precautions
these are not the main scripts

it was just to test, but dont work
your script will always return false
 
I took all the necessary precautions
these are not the main scripts

it was just to test, but dont work
your script will always return false

Okay, but how will my script always return false? The return false are only used if 1, the player userdata isen't there, 2, the player dosen't have a party.
Ex. of how you can use it;
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    if(not player) then
        return false
    end
   
    player:somePartyFunction(Game.getPlayers())
return true
end

function Player.somePartyFunction(player, targetList)
    if(not player or type(targetList) ~= "table") then
        return false
    end
   
    local party = player:getParty()
    if(not party) then
        return false
    end
   
    for _, uid in pairs(targetList) do
        local targetPlayer = Player(uid)
        if(targetPlayer) then
            party:addMember(targetPlayer)
        end
    end
return true
end

In this case the player uses the item, if the player isen't logged in / dies etc the function "somePartyFunction" will return false. It will also return false if the player isen't in a function.
The "somePartyFunction" function you can add in 2 ways, either global.lua(and use /reload global) or add a local before the function and keep it in the script file you are using.
And well, there is another way for it to escape and that is if the targetList parameter is not an array. A way to "fix" this is to add Game.getPlayers() to the parameter where you call the function.
 
Player(cid):getParty() doesnt return a party userdata nil, returns nil

Code:
print(Player(cid):getParty())  -- nil
if not Player(cid):getParty() then
   print('ola')                                          - ola
end

in other words.. will always return false

Code:
    local party = player:getParty()
    if(not party) then
        print(not party)             --nil
    end
 
Player(cid):getParty() doesnt return a party userdata nil, returns nil

Code:
print(Player(cid):getParty())  -- nil
if not Player(cid):getParty() then
   print('ola')                                          - ola
end

in other words.. will always return false

Code:
    local party = player:getParty()
    if(not party) then
        print(not party)             --nil
    end

There is no thing as "userdata nil", the userdata isen't returned at all. A nil value is pushed insted, sometimes a boolean false value.
Either I wrote it wrong or you diden't get me.

Just tested it and mine returns a userdata value when I use the Player.getParty() function. Update your TFS if it's an old version.
 
its an old version.#1643

i compiled it:

Code:
int32_t LuaScriptInterface::luaAddInviteParty(lua_State* L)
{
    // addInviteParty(cid, invitedid)
    Player* player1 = getPlayer(L, 1);
    Player* player2 = getPlayer(L, 2);
    if (player1 && player2) {
        g_game.playerInviteToParty(player1->getID(),player2->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}

int32_t LuaScriptInterface::luaJoinParty(lua_State* L)
{
    // joinParty(cid, leader)
    Player* player1 = getPlayer(L, 1);
    Player* player2 = getPlayer(L, 2);
    if (player1 && player2) {
        g_game.playerJoinParty(player1->getID(),player2->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}

but it dont works too. if you see what is wrong tell me

otherwise i got a better ideia, no party needed
 
otherwise i got a better ideia, no party needed
Well you asked for it :p

its an old version.#1643

i compiled it:

Code:
int32_t LuaScriptInterface::luaAddInviteParty(lua_State* L)
{
    // addInviteParty(cid, invitedid)
    Player* player1 = getPlayer(L, 1);
    Player* player2 = getPlayer(L, 2);
    if (player1 && player2) {
        g_game.playerInviteToParty(player1->getID(),player2->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}

int32_t LuaScriptInterface::luaJoinParty(lua_State* L)
{
    // joinParty(cid, leader)
    Player* player1 = getPlayer(L, 1);
    Player* player2 = getPlayer(L, 2);
    if (player1 && player2) {
        g_game.playerJoinParty(player1->getID(),player2->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}

but it dont works too. if you see what is wrong tell me

otherwise i got a better ideia, no party needed

The problems aren't those functions if you can't use the getParty function.
If you get a nil print in the console that tells you it can't find the function, then add that. Don't forget to add all variables needed for it tho. C++ is just a huge mess if you ask me :p
 
Back
Top