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

TalkAction !invite / !join party in-game command [TFS1.3+]

S

Shadow_

Guest
Hello,

This code was requested by @Nokturno im a bit late but here we go.
the code is written with revscripts so there is nothing else required just place it in your scripts folder

!invite playername --send party invitation
!join inviterName --joins the inviter party
Lua:
local ptInvite = TalkAction("!invite")
function ptInvite.onSay(player, words, param)
    local party = player:getParty()
    if party then
        if party:getLeader():getId() == player:getId() then
            party:addInvite(Player(param))
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has invited you to join his party, say !join ".. player:getName() .."")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Party invitation has been sent to ".. Player(param):getName() .."")
        else
            player:sendCancelMessage("You need to be party leader to invite others")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end
    return false
end

ptInvite:separator(" ")
ptInvite:register()

local ptJoin = TalkAction("!join")
function ptJoin.onSay(player, words, param)
    local party = Player(param):getParty()
    if party then
        local invited = party:getInvitees()
        local flag = 0
        for i = 1, #invited do
            if invited[i]:getId() == player:getId() then
                flag = 1
            end
        end
        if flag > 0 then
            party:removeInvite(player)
            party:addMember(player)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have joined ".. Player(param):getName() .." party.")
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has joined the party.")
        else
            player:sendCancelMessage("You are not invited in this party.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    else
        player:sendCancelMessage(""..Player(param):getName().." is not a party member.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end

ptJoin:separator(" ")
ptJoin:register()
Till the next one.

ChangesLog:

- Fixed Variable Invited missing () after function
 
Last edited by a moderator:
Hello,

This code was requested by @Nokturno im a bit late but here we go.
the code is written with revscripts so there is nothing else required just place it in your scripts folder

!invite playername --send party invitation
!join inviterName --joins the inviter party
Lua:
local ptInvite = TalkAction("!invite")
function ptInvite.onSay(player, words, param)
    local party = player:getParty()
    if party then
        if party:getLeader():getId() == player:getId() then
            party:addInvite(Player(param))
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has invited you to join his party, say !join ".. player:getName() .."")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Party invitation has been sent to ".. Player(param):getName() .."")
        else
            player:sendCancelMessage("You need to be party leader to invite others")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end
    return false
end

ptInvite:separator(" ")
ptInvite:register()

local ptJoin = TalkAction("!join")
function ptJoin.onSay(player, words, param)
    local party = Player(param):getParty()
    if party then
        local invited = party:getInvitees()
        local flag = 0
        for i = 1, #invited do
            if invited[i]:getId() == player:getId() then
                flag = 1
            end
        end
        if flag > 0 then
            party:removeInvite(player)
            party:addMember(player)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have joined ".. Player(param):getName() .." party.")
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has joined the party.")
        else
            player:sendCancelMessage("You are not invited in this party.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    else
        player:sendCancelMessage(""..Player(param):getName().." is not a party member.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end

ptJoin:separator(" ")
ptJoin:register()
Till the next one.

ChangesLog:

- Fixed Variable Invited missing () after function

This idea is so good!!

Could you implement another code to create a Party? "!CreateParty"

In the current situation, the party is only created with 2 people at least. The leader invites someone and creates the party.

But I was thinking about the leader creating the party with just himself and then inviting other people later.

How could that be possible?
 
This idea is so good!!

Could you implement another code to create a Party? "!CreateParty"

In the current situation, the party is only created with 2 people at least. The leader invites someone and creates the party.

But I was thinking about the leader creating the party with just himself and then inviting other people later.

How could that be possible?
Lua:
-- !invite talk action
local ptInvite = TalkAction("!invite")
function ptInvite.onSay(player, words, param)
    local party = player:getParty()
    if party then
        if party:getLeader():getId() == player:getId() then
            party:addInvite(Player(param))
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has invited you to join his party, say !join ".. player:getName() .."")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Party invitation has been sent to ".. Player(param):getName() .."")
        else
            player:sendCancelMessage("You need to be party leader to invite others")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end
    return false
end

ptInvite:separator(" ")
ptInvite:register()

-- !join talk action
local ptJoin = TalkAction("!join")
function ptJoin.onSay(player, words, param)
    local party = Player(param):getParty()
    if party then
        local invited = party:getInvitees()
        local flag = 0
        for i = 1, #invited do
            if invited[i]:getId() == player:getId() then
                flag = 1
            end
        end
        if flag > 0 then
            party:removeInvite(player)
            party:addMember(player)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have joined ".. Player(param):getName() .." party.")
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has joined the party.")
        else
            player:sendCancelMessage("You are not invited in this party.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    else
        player:sendCancelMessage(""..Player(param):getName().." is not a party member.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end

ptJoin:separator(" ")
ptJoin:register()

-- !createparty talk action
local ptCreate = TalkAction("!createparty")
function ptCreate.onSay(player, words, param)
    -- Check if the player is already in a party
    if player:getParty() then
        player:sendCancelMessage("You are already in a party.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    -- Create a new party with the player as the leader
    local party = Party(player)

   -- Send a message to the player indicating that the party was created
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Party created! You can now invite other players to join using !invite <player name>.")
end

ptCreate:separator(" ")
ptCreate:register()
 
Last edited:
Lua:
-- !invite talk action
local ptInvite = TalkAction("!invite")
function ptInvite.onSay(player, words, param)
    local party = player:getParty()
    if party then
        if party:getLeader():getId() == player:getId() then
            party:addInvite(Player(param))
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has invited you to join his party, say !join ".. player:getName() .."")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Party invitation has been sent to ".. Player(param):getName() .."")
        else
            player:sendCancelMessage("You need to be party leader to invite others")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end
    return false
end

ptInvite:separator(" ")
ptInvite:register()

-- !join talk action
local ptJoin = TalkAction("!join")
function ptJoin.onSay(player, words, param)
    local party = Player(param):getParty()
    if party then
        local invited = party:getInvitees()
        local flag = 0
        for i = 1, #invited do
            if invited[i]:getId() == player:getId() then
                flag = 1
            end
        end
        if flag > 0 then
            party:removeInvite(player)
            party:addMember(player)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have joined ".. Player(param):getName() .." party.")
            Player(param):sendTextMessage(MESSAGE_INFO_DESCR, "".. player:getName() .." has joined the party.")
        else
            player:sendCancelMessage("You are not invited in this party.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    else
        player:sendCancelMessage(""..Player(param):getName().." is not a party member.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end

ptJoin:separator(" ")
ptJoin:register()

-- !createparty talk action
local ptCreate = TalkAction("!createparty")
function ptCreate.onSay(player, words, param)
    -- Check if the player is already in a party
    if player:getParty() then
        player:sendCancelMessage("You are already in a party.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    -- Create a new party with the player as the leader
    local party = Party.createParty(player)

   -- Send a message to the player indicating that the party was created
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Party created! You can now invite other players to join using !invite <player name>.")
end

ptCreate:separator(" ")
ptCreate:register()

Thank you for your help Shalaby!!

But, I got this error:
Lua:
attempt to call field 'createParty' (a nil value)
 
I edited the reply, Give it more try.
The same error,

I think it's because haven't any sentence to just "create a party". The party is just created when you invite someone, haven't any function for create it by yourself. I was trying to understand the server souces, but I don't have any knowledgment in c++.
 
Last edited:
I think it's because haven't any sentence to just "create a party". The party is just created when you invite someone, haven't any function for create it by yourself. I was trying to understand the server souces, but I don't have any knowledgment in c++.
Just change this local party = Party.create(player) to this local party = Party(player)
 
Back
Top