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
21 changes: 21 additions & 0 deletions doc/script_commands.txt
Expand Up @@ -8492,6 +8492,27 @@ Example:

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

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

Creates an instance of battleground battle group that can be used in 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.
<On Death Event> refers to an NPC label that attaches to the character and is run when they die. Can be "" for empty.

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

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

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

Adds attached player or <char id> (if specified) to an existing battleground group and warps it to the specified coordinates
<x> and <y> on the given map.

Returns 1 on success. Returns 0 on failure.
Copy link
Member

Choose a reason for hiding this comment

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

Fits perfectly for true/false.


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

*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
78 changes: 77 additions & 1 deletion src/map/script.c
Expand Up @@ -18668,12 +18668,17 @@ BUILDIN_FUNC(waitingroom2bg)
ev = script_getstr(st,5); // Logout Event
dev = script_getstr(st,6); // Die Event

if (ev[0] != '\0')
Copy link
Member

Choose a reason for hiding this comment

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

Could be removed since it's done inside the function

check_event(st, ev);
if (dev[0] != '\0')
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;
Expand Down Expand Up @@ -18722,6 +18727,75 @@ BUILDIN_FUNC(waitingroom2bg_single)
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, bg_id;

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

Choose a reason for hiding this comment

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

Could be combined into a single if

if (mapindex == 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);
ev = script_getstr(st, 5); // Logout Event
dev = script_getstr(st, 6); // Die Event

if (ev[0] != '\0')
check_event(st, ev);
if (dev[0] != '\0')
check_event(st, dev);

if ((bg_id = bg_create(mapindex, x, y, ev, dev)) == 0)
{ // Creation failed
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.

if case is useless, since you just push the same value as when you would return bg_id directly

return SCRIPT_CMD_SUCCESS;
}

script_pushint(st, bg_id);
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;
int x, y, bg_id, mapindex;

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

x = script_getnum(st, 4);
y = script_getnum(st, 5);
sd = script_charid2sd(6, sd);

if (bg_team_join(bg_id, sd))
{
pc_setpos(sd, mapindex, x, y, CLR_TELEPORT);
Copy link
Member

Choose a reason for hiding this comment

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

You should check for pc_setpos return value

script_pushint(st, 1);
}
else
script_pushint(st, 0);

return SCRIPT_CMD_SUCCESS;
}

BUILDIN_FUNC(bg_team_setxy)
{
struct battleground_data *bg;
Expand Down Expand Up @@ -22229,6 +22303,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,"isii?"),
BUILDIN_DEF(bg_create,"siiss"),

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