Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battleground script command expansion #1534

Merged
merged 12 commits into from Sep 12, 2016
33 changes: 26 additions & 7 deletions doc/script_commands.txt
Expand Up @@ -8466,19 +8466,18 @@ Mark Color:
============================
---------------------------------------

*waitingroom2bg_single(<battle group>,"<map name>",<x>,<y>,"<npc name>");
*waitingroom2bg_single(<battle group>,{"<map name>",<x>,<y>{,"<npc name>"}});

Adds the first waiting player from the chat room of the given NPC to an
existing battleground group and warps it to the specified coordinates on
the given map.
Adds the first waiting player from the chat room of the given NPC to an existing battleground group.
The player will also be warped to the default spawn point of the battle group or to the specified coordinates <x> and <y> on the given <map>.

---------------------------------------

*waitingroom2bg("<map name>",<x>,<y>,"<On Quit Event>","<On Death Event>"{,"<NPC Name>"});
*waitingroom2bg("<map name>",<x>,<y>,{"<On Quit Event>","<On Death Event>"{,"<NPC Name>"}});

<map name>,<x>,<y> refer to where the "respawn" base is, where the player group will respawn when they die.
<On Quit Event> refers to an NPC label that attaches to the character and is run when they relog.
<On Death Event> refers to an NPC label that attaches to the character and is run when they die. Can be "" for empty.
<On Quit Event> refers to an NPC label that attaches to the character and is run when they relog. (Optional)
<On Death Event> refers to an NPC label that attaches to the character and is run when they die. (Optional)

Unlike the prior command, the latter will attach a GROUP in a waiting room to the battleground, and
sets the array $@arenamembers[0] where 0 holds the IDs of the first group, and 1 holds the IDs of the second.
Expand All @@ -8492,6 +8491,26 @@ Example:

---------------------------------------

*bg_create("<map name>",<x>,<y>{,"<On Quit Event>","<On Death Event>"});

Creates an instance of battleground battle group that can be used with other battleground commands.

<map name>,<x>,<y> refer to where the "respawn" base is, where the player group will respawn when they die.
<On Quit Event> refers to an NPC label that attaches to the character and is run when they relog. (Optional)
<On Death Event> refers to an NPC label that attaches to the character and is run when they die. (Optional)

Returns battle group ID on success. Returns 0 on failure.

---------------------------------------

*bg_join(<battle group>,{"<map name>",{<x>,<y>{,<char id>}});

Adds an attached player or <char id> if specified to an existing battleground group. The player will also be warped to the default spawn point of the battle group or to the specified coordinates <x> and <y> on the given <map>.

Returns true on success. Returns false on failure.

---------------------------------------

*bg_team_setxy <Battle Group ID>,<x>,<y>;

Updates the respawn point of the given Battle Group to x,y on the same map. <Battle Group ID> can be retrieved using getcharid(4).
Expand Down
131 changes: 108 additions & 23 deletions src/map/script.c
Expand Up @@ -18653,28 +18653,28 @@ BUILDIN_FUNC(waitingroom2bg)
}

map_name = script_getstr(st,2);
if( strcmp(map_name,"-") != 0 )
{
mapindex = mapindex_name2id(map_name);
if( mapindex == 0 )
{ // Invalid Map
script_pushint(st,0);
return SCRIPT_CMD_SUCCESS;
}
if (strcmp(map_name, "-") != 0 && (mapindex = mapindex_name2id(map_name)) == 0)
{ // Invalid Map
script_pushint(st, 0);
return SCRIPT_CMD_SUCCESS;
}

x = script_getnum(st,3);
y = script_getnum(st,4);
ev = script_getstr(st,5); // Logout Event
dev = script_getstr(st,6); // Die Event
if(script_hasdata(st,5))
ev = script_getstr(st,5); // Logout Event
if(script_hasdata(st,6))
dev = script_getstr(st,6); // Die Event

check_event(st, ev);
check_event(st, dev);

if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 )
{ // Creation failed
script_pushint(st,0);
return SCRIPT_CMD_SUCCESS;
}



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bonus tab?

for (i = 0; i < cd->users; i++) { // Only add those who are in the chat room
struct map_session_data *sd;
if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) ){
Expand All @@ -18694,15 +18694,27 @@ BUILDIN_FUNC(waitingroom2bg_single)
struct npc_data *nd;
struct chat_data *cd;
struct map_session_data *sd;
struct battleground_data *bg;
int x, y, mapindex, bg_id;

bg_id = script_getnum(st,2);
map_name = script_getstr(st,3);
if( (mapindex = mapindex_name2id(map_name)) == 0 )
return SCRIPT_CMD_SUCCESS; // Invalid Map
if ((bg = bg_team_search(bg_id)) == NULL) {
script_pushint(st, false);
return SCRIPT_CMD_SUCCESS;
}
if (script_hasdata(st, 3)) {
map_name = script_getstr(st, 3);
if ((mapindex = mapindex_name2id(map_name)) == 0)
return SCRIPT_CMD_SUCCESS; // Invalid Map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script_pushint missing here

x = script_getnum(st, 4);
y = script_getnum(st, 5);
}
else {
mapindex = bg->mapindex;
x = bg->x;
y = bg->y;
}

x = script_getnum(st,4);
y = script_getnum(st,5);
nd = npc_name2id(script_getstr(st,6));

if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL || cd->users <= 0 )
Expand All @@ -18711,13 +18723,84 @@ BUILDIN_FUNC(waitingroom2bg_single)
if( (sd = cd->usersd[0]) == NULL )
return SCRIPT_CMD_SUCCESS;

if( bg_team_join(bg_id, sd) )
if( bg_team_join(bg_id, sd) && pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) == SETPOS_OK)
{
pc_setpos(sd, mapindex, x, y, CLR_TELEPORT);
script_pushint(st,1);
script_pushint(st, true);
}
else
script_pushint(st,0);
script_pushint(st, false);

return SCRIPT_CMD_SUCCESS;
}


/// Creates an instance of battleground battle group.
/// *bg_create("<map name>",<x>,<y>{,"<On Quit Event>","<On Death Event>"});
/// @author [secretdataz]
BUILDIN_FUNC(bg_create) {
const char *map_name, *ev = "", *dev = "";
int x, y, mapindex = 0;

map_name = script_getstr(st, 2);
if (strcmp(map_name, "-") != 0 && (mapindex = mapindex_name2id(map_name)) == 0)
{ // Invalid Map
script_pushint(st, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one tab to many

return SCRIPT_CMD_SUCCESS;
}

x = script_getnum(st, 3);
y = script_getnum(st, 4);
if(script_hasdata(st, 5))
ev = script_getstr(st, 5); // Logout Event
if(script_hasdata(st, 6))
dev = script_getstr(st, 6); // Die Event

check_event(st, ev);
check_event(st, dev);

script_pushint(st, bg_create(mapindex, x, y, ev, dev));
return SCRIPT_CMD_SUCCESS;
}

/// Adds attached player or <char id> (if specified) to an existing
/// battleground group and warps it to the specified coordinates on
/// the given map.
/// bg_join(<battle group>,{"<map name>",<x>,<y>{,<char id>}});
/// @author [secretdataz]
BUILDIN_FUNC(bg_join) {
const char* map_name;
struct map_session_data *sd;
struct battleground_data *bg;
int x, y, bg_id, mapindex;

bg_id = script_getnum(st, 2);
if ((bg = bg_team_search(bg_id)) == NULL) {
script_pushint(st, false);
return SCRIPT_CMD_SUCCESS;
}
if (script_hasdata(st, 3)) {
map_name = script_getstr(st, 3);
if ((mapindex = mapindex_name2id(map_name)) == 0)
return SCRIPT_CMD_SUCCESS; // Invalid Map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also pushint

x = script_getnum(st, 4);
y = script_getnum(st, 5);
} else {
mapindex = bg->mapindex;
x = bg->x;
y = bg->y;
}

if ((sd = script_charid2sd(6, sd)) == NULL) {
Copy link

@Darkelfen Darkelfen Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this while compiling:

script.c: In function 'buildin_bg_join':
script.c:18801:10: warning: assignment makes pointer from integer without a cast [enabled by default]

Also, bg_join crashes the map server, probably it is caused by this.

This is the code that I've been using to test the new commands:

prontera,155,180,0  script  bg#bg_join  666,{
OnInit:
    waitingroom "BG Test",2;
    end;
}

bat_room,1,1,0      script  Flavius Init    -1,{
OnInit:
    bindatcmd "bgjoin","Flavius Init::OnBGJoin";
    bindatcmd "bgcreate","Flavius Init::OnBGCreate";
    bindatcmd "bgleave","Flavius Init::OnBGLeave";
    bindatcmd "bgdestroy","Flavius Init::OnBGDestroy";
    bindatcmd "bgwp","Flavius Init::OnBGWp";
    bindatcmd "bgchatjoin","Flavius Init::OnBGChatJoin";
    end;
OnBGJoin:
    bg_join($@FlaviusBG1_id1,"bat_b01",390,10,getcharid(0));
    end;
OnBGCreate:
    $@FlaviusBG1_id1 = bg_create("bat_b01",390,10);
    end;
OnBGLeave:
    bg_leave;
    end;
OnBGDestroy:
    if ($@FlaviusBG1_id1){
        bg_destroy ($@FlaviusBG1_id1);
    }
    end;
OnBGWp:
    bg_warp $@FlaviusBG1_id1,"bat_b01",390,10;
    end;
OnBGChatJoin:
    waitingroom2bg_single($@FlaviusBG1_id1,"bat_b01",390,10,"bg#bg_join");
    end;
}

bg_create successfully creates the BG group and attach the respawn coordinates to the battle group, I've tested this by waitingroom2bg_single since bg_join crashes map server.

script_pushint(st, false);
return SCRIPT_CMD_FAILURE;
}

if (bg_team_join(bg_id, sd) && pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) == SETPOS_OK)
{
script_pushint(st, true);
}
else
script_pushint(st, false);

return SCRIPT_CMD_SUCCESS;
}
Expand Down Expand Up @@ -22217,8 +22300,8 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(agitend2,""),
BUILDIN_DEF(agitcheck2,""),
// BattleGround
BUILDIN_DEF(waitingroom2bg,"siiss?"),
BUILDIN_DEF(waitingroom2bg_single,"isiis"),
BUILDIN_DEF(waitingroom2bg,"sii???"),
BUILDIN_DEF(waitingroom2bg_single,"i????"),
BUILDIN_DEF(bg_team_setxy,"iii"),
BUILDIN_DEF(bg_warp,"isii"),
BUILDIN_DEF(bg_monster,"isiisi?"),
Expand All @@ -22229,6 +22312,8 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(bg_get_data,"ii"),
BUILDIN_DEF(bg_getareausers,"isiiii"),
BUILDIN_DEF(bg_updatescore,"sii"),
BUILDIN_DEF(bg_join,"i????"),
BUILDIN_DEF(bg_create,"sii??"),

// Instancing
BUILDIN_DEF(instance_create,"s??"),
Expand Down