• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

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:

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
55
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?
 

Shalaby

Time has made me wiser, but no more patient.
Joined
Feb 17, 2011
Messages
305
Solutions
6
Reaction score
107
Location
Egypt
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.create(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:

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
55
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)
 

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
55
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:

Addams

1337
Senator
Premium User
Joined
Sep 29, 2009
Messages
2,833
Solutions
340
Reaction score
1,577
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)
 
Top