Skip to content

Commit

Permalink
Cleaned up custom battleground scripts (#3025)
Browse files Browse the repository at this point in the history
Added a warning to script command delwall
  • Loading branch information
secretdataz authored and Lemongrass3110 committed Apr 11, 2018
1 parent 73d471b commit e2b9e42
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 65 deletions.
47 changes: 15 additions & 32 deletions npc/custom/battleground/bg_emp.txt
Expand Up @@ -3,14 +3,15 @@
//===== By: ==================================================
//= AnnieRuru
//===== Current Version: =====================================
//= 1.0
//= 1.1
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= A simple battleground script:
//= Destroy the opponent's Emperium to win the match.
//===== Additional Comments: =================================
//= 1.0 First version, edited. [Euphy]
//= 1.1 Use up to date battleground script commands [AnnieRuru]
//============================================================

- script bg_emp#control -1,{
Expand All @@ -19,36 +20,26 @@ OnInit:
.eventlasting = 20*60; // event duration before auto-reset (20 minutes * seconds)
setarray .rewarditem[0], // rewards for the winning team: <item>,<amount>,...
501, 10;

.team1name$ = "Red";
.team2name$ = "Blue";
end;
OnStart:
if ( getwaitingroomstate( 0, .rednpcname$ ) < .minplayer2start || getwaitingroomstate( 0, .bluenpcname$ ) < .minplayer2start )
end;

// create Battleground and teams
.red = waitingroom2bg( "bat_a01", 157,347, strnpcinfo(0)+"::OnRedQuit", strnpcinfo(0)+"::OnRedDead", .rednpcname$ );
copyarray .team1aid, $@arenamembers, $@arenamembersnum;
.team1count = .minplayer2start;
.blue = waitingroom2bg( "bat_a01", 142,51, strnpcinfo(0)+"::OnBlueQuit", strnpcinfo(0)+"::OnBlueDead", .bluenpcname$ );
copyarray .team2aid, $@arenamembers, $@arenamembersnum;
.team2count = .minplayer2start;
delwaitingroom .rednpcname$;
delwaitingroom .bluenpcname$;
disablenpc .rednpcname$;
disablenpc .bluenpcname$;
setwall "bat_a01", 164,347, 6, 4, 0, "bg_emp_town_red";
setwall "bat_a01", 154,51, 6, 4, 0, "bg_emp_town_blue";
bg_warp .red, "bat_a01", 171,346;
bg_warp .blue, "bat_a01", 162,50;
bg_updatescore "bat_a01", 0, 0;

// delay before match begins
sleep 6000;
mapannounce "bat_a01", "The rules are simple. The first team to break the opponent's Emperium wins!", bc_map;
sleep 3000;
for ( .@i = 5; .@i > 0; .@i-- ) {
for ( .@i = 5; .@i > 0; --.@i ) {
mapannounce "bat_a01", "["+ .@i +"]", bc_map;
sleep 1000;
}
Expand All @@ -67,32 +58,27 @@ OnStart:
killmonster "bat_a01", strnpcinfo(3)+"::OnRedDown";
killmonster "bat_a01", strnpcinfo(3)+"::OnBlueDown";
if ( .winside ) {
mapannounce "bat_a01", "- "+ getd( ".team"+ .winside +"name$" ) +" Team is victorious! -", bc_map;
for ( .@i = 0; .@i < getd(".team"+ .winside +"count"); .@i++ )
getitem .rewarditem[0], .rewarditem[1], getd(".team"+ .winside +"aid["+ .@i +"]" );
mapannounce "bat_a01", "- "+( (.winside == .red)? "Red" : "Blue" )+" Team is victorious! -", bc_map;
bg_get_data .winside, 1;
for ( .@i = 0; .@i < $@arenamemberscount; ++.@i )
getitem .rewarditem[0], .rewarditem[1], $@arenamembers[.@i];
} else
mapannounce "bat_a01", "- The match has ended in a draw! -", bc_map;
sleep 5000;
bg_warp .red, "prontera", 155,182;
bg_warp .blue, "prontera", 158,182;
bg_destroy .red;
bg_destroy .blue;
delwall "bg_emp_town_red";
delwall "bg_emp_town_blue";
deletearray .team1aid;
deletearray .team2aid;
.winside = .team1count = .team2count = 0;
enablenpc .rednpcname$;
enablenpc .bluenpcname$;
.winside = 0;
donpcevent .rednpcname$ +"::OnStart";
donpcevent .bluenpcname$ +"::OnStart";
end;

// Emperium destroyed
OnRedDown: callsub L_EmpDown, 1, 2;
OnBlueDown: callsub L_EmpDown, 2, 1;
OnRedDown: callsub L_EmpDown, "Red", .blue;
OnBlueDown: callsub L_EmpDown, "Blue", .red;
L_EmpDown:
mapannounce "bat_a01", strcharinfo(0) +" has destroyed "+ getd( ".team"+ getarg(0) +"name$" ) +" Team's Emperium.", bc_map;
mapannounce "bat_a01", strcharinfo(0) +" has destroyed "+ getarg(0) +" Team's Emperium.", bc_map;
.winside = getarg(1);
awake strnpcinfo(0);
end;
Expand All @@ -105,15 +91,12 @@ OnBlueDead:
end;

// "OnQuit" event
OnRedQuit: callsub L_Quit, 1, 2;
OnBlueQuit: callsub L_Quit, 2, 1;
OnRedQuit: callsub L_Quit, .red, "Red";
OnBlueQuit: callsub L_Quit, .blue, "Blue";
L_Quit:
percentheal 100, 100;
while ( getd( ".team"+ getarg(0) +"aid["+ .@i +"]" ) != getcharid(3) && .@i < getd(".team"+ getarg(0) +"count") ) .@i++;
deletearray getd( ".team"+ getarg(0) +"aid["+ .@i +"]" ), 1;
setd ".team"+ getarg(0) +"count", getd(".team"+ getarg(0) +"count") -1;
if ( getd(".team"+ getarg(0) +"count") ) end;
mapannounce "bat_a01", "All "+ getd( ".team"+ getarg(0) +"name$" ) +" team members have quit!", bc_map, 0xff3333;
if ( !bg_get_data( getarg(0), 0 ) )
mapannounce "bat_a01", "All "+ getarg(1) +" team members have quit!", bc_map, 0xff3333;
end;
}

Expand Down
51 changes: 22 additions & 29 deletions npc/custom/battleground/bg_pvp.txt
Expand Up @@ -3,14 +3,15 @@
//===== By: ==================================================
//= AnnieRuru
//===== Current Version: =====================================
//= 1.0
//= 1.1
//===== Compatible With: =====================================
//= rAthena Project
//===== Description: =========================================
//= A simple battleground script:
//= Kill players from the other team.
//===== Additional Comments: =================================
//= 1.0 First version, edited. [Euphy]
//= 1.1 Use up to date battleground script commands [AnnieRuru]
//============================================================

- script bg_pvp#control -1,{
Expand All @@ -26,29 +27,25 @@ OnStart:

// create Battleground and teams
.red = waitingroom2bg( "guild_vs3", 13,50, strnpcinfo(0)+"::OnRedQuit", strnpcinfo(0)+"::OnRedDead", .rednpcname$ );
copyarray .team1aid, $@arenamembers, $@arenamembersnum;
.team1count = .minplayer2start;
.blue = waitingroom2bg( "guild_vs3", 86,50, strnpcinfo(0)+"::OnBlueQuit", strnpcinfo(0)+"::OnBlueDead", .bluenpcname$ );
copyarray .team2aid, $@arenamembers, $@arenamembersnum;
.team2count = .minplayer2start;
delwaitingroom .rednpcname$;
delwaitingroom .bluenpcname$;
bg_warp .red, "guild_vs3", 13,50;
bg_warp .blue, "guild_vs3", 86,50;
.score[1] = .score[2] = .minplayer2start;
bg_updatescore "guild_vs3", .score[1], .score[2];
.red_score = .blue_score = .minplayer2start;
bg_updatescore "guild_vs3", .red_score, .blue_score;

// match duration
sleep .eventlasting * 1000;

// end match, destroy Battleground, reset NPCs
if ( .score[1] > .score[2] ) {
if ( .red_score > .blue_score ) {
mapannounce "guild_vs3", "- Red Team is victorious! -", bc_map;
callsub L_Reward, 1;
callsub L_Reward, .red;
}
else if ( .score[1] < .score[2] ) {
else if ( .blue_score > .red_score ) {
mapannounce "guild_vs3", "- Blue Team is victorious! -", bc_map;
callsub L_Reward, 2;
callsub L_Reward, .blue;
}
else
mapannounce "guild_vs3", "- The match has ended in a draw! -", bc_map;
Expand All @@ -61,37 +58,32 @@ OnStart:
end;

L_Reward:
for ( .@i = 0; .@i < getd(".team"+ getarg(0) +"count"); .@i++ )
getitem .rewarditem[0], .rewarditem[1], getd(".team"+ getarg(0) +"aid["+ .@i +"]" );
bg_get_data getarg(0), 1;
for ( .@i = 0; .@i < $@arenamemberscount; ++.@i )
getitem .rewarditem[0], .rewarditem[1], $@arenamembers[.@i];
return;

// "OnDeath" event
OnRedDead: callsub L_Dead, 1;
OnBlueDead: callsub L_Dead, 2;
OnRedDead: callsub L_Dead, .red_score;
OnBlueDead: callsub L_Dead, .blue_score;
L_Dead:
.score[ getarg(0) ]--;
bg_updatescore "guild_vs3", .score[1], .score[2];
while ( getd( ".team"+ getarg(0) +"aid["+ .@i +"]" ) != getcharid(3) && .@i < getd(".team"+ getarg(0) +"count") ) .@i++;
deletearray getd( ".team"+ getarg(0) +"aid["+ .@i +"]" ), 1;
setd ".team"+ getarg(0) +"count", getd(".team"+ getarg(0) +"count") -1;
set getarg(0), getarg(0) -1;
bg_updatescore "guild_vs3", .red_score, .blue_score;
bg_leave;
if ( !.score[ getarg(0) ] )
if ( !getarg(0) )
awake strnpcinfo(0);
sleep2 1250;
percentheal 100,100;
end;

// "OnQuit" event
OnRedQuit: callsub L_Quit, 1;
OnBlueQuit: callsub L_Quit, 2;
OnRedQuit: callsub L_Quit, .red_score;
OnBlueQuit: callsub L_Quit, .blue_score;
L_Quit:
.score[ getarg(0) ]--;
bg_updatescore "guild_vs3", .score[1], .score[2];
set getarg(0), getarg(0) -1;
bg_updatescore "guild_vs3", .red_score, .blue_score;
percentheal 100, 100;
while ( getd( ".team"+ getarg(0) +"aid["+ .@i +"]" ) != getcharid(3) && .@i < getd(".team"+ getarg(0) +"count") ) .@i++;
deletearray getd( ".team"+ getarg(0) +"aid["+ .@i +"]" ), 1;
setd ".team"+ getarg(0) +"count", getd(".team"+ getarg(0) +"count") -1;
if ( !.score[ getarg(0) ] )
if ( !getarg(0) )
awake strnpcinfo(0);
end;
}
Expand All @@ -116,6 +108,7 @@ OnStart:
end;
}

guild_vs3 mapflag gvg off
guild_vs3 mapflag battleground 2
guild_vs3 mapflag nosave SavePoint
guild_vs3 mapflag nowarp
Expand Down
5 changes: 3 additions & 2 deletions src/map/map.cpp
Expand Up @@ -3237,13 +3237,13 @@ void map_iwall_get(struct map_session_data *sd) {
dbi_destroy(iter);
}

void map_iwall_remove(const char *wall_name)
bool map_iwall_remove(const char *wall_name)
{
struct iwall_data *iwall;
int16 i, x1, y1;

if( (iwall = (struct iwall_data *)strdb_get(iwall_db, wall_name)) == NULL )
return; // Nothing to do
return false; // Nothing to do

for( i = 0; i < iwall->size; i++ ) {
map_iwall_nextxy(iwall->x, iwall->y, iwall->dir, i, &x1, &y1);
Expand All @@ -3256,6 +3256,7 @@ void map_iwall_remove(const char *wall_name)

map[iwall->m].iwall_num--;
strdb_remove(iwall_db, iwall->wall_name);
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/map/map.hpp
Expand Up @@ -919,7 +919,7 @@ void map_flags_init(void);

bool map_iwall_set(int16 m, int16 x, int16 y, int size, int8 dir, bool shootable, const char* wall_name);
void map_iwall_get(struct map_session_data *sd);
void map_iwall_remove(const char *wall_name);
bool map_iwall_remove(const char *wall_name);

int map_addmobtolist(unsigned short m, struct spawn_data *spawn); // [Wizputer]
void map_spawnmobs(int16 m); // [Wizputer]
Expand Down
7 changes: 6 additions & 1 deletion src/map/script.cpp
Expand Up @@ -13581,7 +13581,12 @@ BUILDIN_FUNC(setwall)
BUILDIN_FUNC(delwall)
{
const char *name = script_getstr(st,2);
map_iwall_remove(name);

if( !map_iwall_remove(name) ){
ShowError( "buildin_delwall: wall \"%s\" does not exist.\n", name );
return SCRIPT_CMD_FAILURE;
}

return SCRIPT_CMD_SUCCESS;
}

Expand Down

0 comments on commit e2b9e42

Please sign in to comment.