• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Arena Team on login

Status
Not open for further replies.

Intouch

Respected Member
Hello EMUDEVS!

Does anyone know how can I make code which will auto-create arena team for new characters

(ex. I made new char, I loged ingame and I have 2v2/3v3/5v5 (doesnt matter which one) arena team created)
 

Tommy

Founder
Not sure how well it will work since you need partners. I say it would bug out, but I'm not entirely sure what it would do if you do this. You can easily look at the arena create command function to see how to create arena teams programmatically and set everything up in the OnCreate hook or OnLogin hook, which ever you prefer.
 

Intouch

Respected Member
I tried to make it but I can't.

All what I made was (dont allow player to add someone in team) because I want solo team for this.

Can someone help me, please...
 

Neccta

Exalted Member
Code:
function FirstLogin(event, player)
    CharDBExecute("INSERT INTO [COLOR="#FF0000"]create arena team query here[/COLOR])
    CharDBExecute("UPDATE `characters` SET `[COLOR="#FF0000"]arenateam?[/COLOR]` where `guid` = "..player:GetGUIDLow())
    if not query then
        return
    end
end

RegisterPlayerEvent(30, FirstLogin)

Places in red need to be changed, I don't remember what the TC database structure looks like. For all I know the all the queries could be wrong, but it would look somewhat like this. It should create a new arena team and then place that character into it the first time they log in. Like Tommy said it could be buggy because you are the only member.
 
Last edited:

Tommy

Founder
Code:
function FirstLogin(event, player)
    CharDBExecute("INSERT INTO [COLOR="#FF0000"]create arena team query here[/COLOR])
    CharDBExecute("UPDATE `characters` SET `[COLOR="#FF0000"]arenateam?[/COLOR]` where `guid` = "..player:GetGUIDLow())
    if not query then
        return
    end
end

RegisterPlayerEvent(30, FirstLogin)

Places in red need to be changed, I don't remember what the TC database structure looks like. For all I know the all the queries could be wrong, but it would look somewhat like this. It should create a new arena team and then place that character into it the first time they log in. Like Tommy said it could be buggy because you are the only member.

If he was using Eluna the thread would be in Eluna support. :p
 

Rochet2

Moderator / Eluna Dev
Have you actually tried anything yet?
Do you have some code you need help with?
Post it. State a specific problem or problems you need help with.
Currently the topic only holds "how to make this entire arena team on login system" type of question
instead of "how do I do something on login" or "how do I create an arena team"

The statement that you tried something was a little unclear. Did you actually implement something and got into a problem with denying players to join or ?

This is not a request section.
You should usually try make something before asking for help.

If you dont know how to script at all, I suggest you start with something basic.
From there you learn where the base resources are and what can be done and how.
We can guide you to the resources and help with questions - there are many scripts that work as examples.
 
Last edited:

Intouch

Respected Member
Here is what I tried:

Code:
class arenacreate_login : public PlayerScript
{
public:
	arenacreate_login() : PlayerScript("arenacreate_login") {}

	void OnLogin(Player* player, bool firstLogin)
	{
	    if (player->GetTotalPlayedTime() < 3)
		{
            int i = 1;
            std::stringstream teamName;
            teamName << player->GetName();
            do
            {
                if (sArenaTeamMgr->GetArenaTeamByName(teamName.str()) != NULL) // teamname exist, so choose another name
                {
                    teamName.str(std::string());
                    teamName << player->GetName() << i++;
                }
                else
                    break;
            } while (i < 100); // should never happen

            // Create arena team
            ArenaTeam* arenaTeam = new ArenaTeam();

            if (!arenaTeam->Create(player->GetGUID(), ARENA_TEAM_5v5, teamName.str(), 4283124816, 45, 4294242303, 5, 4294705149))
            {
                delete arenaTeam;
                return false;
            }

            // Register arena team
            sArenaTeamMgr->AddArenaTeam(arenaTeam);
            arenaTeam->AddMember(player->GetGUID());

            return true;
        }
	}
};

void AddSC_arenacreate_login()
{
	new arenacreate_login;
}
 

Rochet2

Moderator / Eluna Dev
The code looks alright, though there are few small errors.
You sure the tabard etc numbers are correct? (4294705149)
The leader shouldnt be added to his own team.
Note that you should make handling for the error cases as well.

To be able to block inviting players you should edit the invite packet handler in core.
Same possibly applies to joining some arena maybe, if you want to solo. Im unsure how the system works ingame as I never tried.
You should try blocking either invite or join. See ArenaTeamHandler.cpp WorldSession::HandleArenaTeamInviteOpcode. and make the function return after reading recvData for example.
Or change the handler function to Handle_NULL in opcodes.cpp from HandleArenaTeamInviteOpcode

Code:
#include "ScriptPCH.h"
#include "ArenaTeam.h"
#include "ArenaTeamMgr.h"

class arenacreate_login : public PlayerScript
{
public:
    arenacreate_login() : PlayerScript("arenacreate_login") { }

    std::string GetArenaTeamName(std::string const& playerName)
    {
        // Use player name as team name
        std::string teamName = playerName;
        for (int i = 1; i <= 1000; ++i)
        {
            // Is free team name, return it
            if (!sArenaTeamMgr->GetArenaTeamByName(teamName))
                return teamName;

            // Increase number at end of team name
            teamName = playerName;
            teamName += i;
        }

        // Return empty string if couldnt find a free team name
        return "";
    }

    void OnLogin(Player* player, bool firstLogin) override
    {
        // Error, not first login
        if (!firstLogin)
            return;

        std::string teamName = GetArenaTeamName(player->GetName());
        // Error, no free name found. Need to handle this!
        if (teamName.empty())
            return;

        // Create arena team, leader is added automatically to team
        ArenaTeam* arenaTeam = new ArenaTeam();
        if (!arenaTeam->Create(player->GetGUID(), ARENA_TEAM_5v5, teamName, 4283124816, 45, 4294242303, 5, 4294705149))
        {
            // Error, couldnt create arena team. Invalid name? Need to handle this!
            delete arenaTeam;
            return;
        }

        // Register arena team
        sArenaTeamMgr->AddArenaTeam(arenaTeam);
    }
};

void AddSC_arenacreate_login()
{
    new arenacreate_login();
}
 
Last edited:

Intouch

Respected Member
I already disabled arena team invites for that arena type. And is possible to add same team names for every arena team (example: Arena Team name of every player will be like: 1vs1 Arena Team ) ?
 

Jpp

Administrator
I already disabled arena team invites for that arena type. And is possible to add same team names for every arena team (example: Arena Team name of every player will be like: 1vs1 Arena Team ) ?

Wouldn't it be better to just use the player's name as the name of the arena team?
 

Kaev

Super Moderator
Fix what? Rochet posted a modified code of yours - What's wrong with that, after he modified it?
And i think all teams with the same names COULD be possible, but we don't know. Why don't you try it by yourself? Would be way faster than waiting days or weeks until someone will try it for you.
 

Kaev

Super Moderator
Error message? What didn't work? We can't help if you just say "it doesn't work". We need more informations, describe your (new) problem.
 
Status
Not open for further replies.
Top