viewing paste topic/4570- battleground.diff | Diff

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
 src/map/script.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 
diff --git a/src/map/script.c b/src/map/script.c
index be346cb..e690edb 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -18508,11 +18508,77 @@ bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)
        return script->add_builtin(&buildin, true);
 }
 
+//     createbgid <respawn map>, <respawn x>, <respawn y>, <On Quit event>, <On Death event>;
+BUILDIN(createbgid) {
+       unsigned int bg_id;
+       if ( ( bg_id = bg->create( mapindex->name2id( script_getstr(st,2) ), script_getnum(st,3), script_getnum(st,4), script_getstr(st,5), script_getstr(st,6) ) ) > 0 )
+               script_pushint( st, bg_id );
+       else
+               script_pushint( st, 0 );
+       return true;
+}
+
+//     setbgid <battleground ID> {, <player name> };
+//     setbgid <battleground ID> {, <player account ID> };
+BUILDIN(setbgid) {
+       unsigned int bg_id = script_getnum(st,2);
+       struct battleground_data *bgd = bg->team_search( bg_id );
+       struct map_session_data *sd;
+       if ( script_hasdata( st, 3 ) ) {
+               if ( data_isstring( script_getdata(st,3) ) )
+                       sd = map->nick2sd( script_getstr(st,3) );
+               else
+                       sd = map->id2sd( script_getnum(st,3) );
+       } else
+               sd = script->rid2sd(st);
+       if ( !sd ) {
+               script_pushint( st, -3 ); // player no attach
+               return true;
+       }
+       if ( !bgd && bg_id > 0 ) {
+               script_pushint( st, -1 ); // battleground team haven't created
+               return true;
+       }
+       if ( bg_id && sd->bg_id == bg_id ) {
+               script_pushint( st, -5 ); // the player has already join this battleground team
+               return true;
+       }
+       if ( sd->bg_id )
+               bg->team_leave( sd, 0 );
+       if ( bg_id == 0 ) {
+               script_pushint( st, 0 );
+               return true;
+       }
+       if ( !bg->team_join( bg_id, sd ) )
+               script_pushint( st, -2 ); // cannot join anymore, because has reached MAX_BG_MEMBERS
+       else
+               script_pushint( st, bg_id );
+       return true;
+}
+
+//     getbgusers <battleground ID>;
+BUILDIN(getbgusers) {
+       struct battleground_data *bgd = bg->team_search( script_getnum(st,2) );
+       int i;
+       if ( !bgd ) {
+               script_pushint( st, -1 );
+               return true;
+       }
+       for ( i = 0; bgd->members[i].sd; i++ )
+               mapreg->setreg( reference_uid( script->add_str("$@arenamembers"), i ), bgd->members[i].sd->bl.id );
+       mapreg->setreg( script->add_str("$@arenamembersnum"), i );
+       script_pushint( st, i );
+       return true;
+}
+
 #define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args }
 #define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args }
 void script_parse_builtin(void) {
        struct script_function BUILDIN[] = {
                // NPC interaction
+               BUILDIN_DEF(createbgid,"siiss"),
+               BUILDIN_DEF(setbgid,"i?"),
+               BUILDIN_DEF(getbgusers,"i"),
                BUILDIN_DEF(mes,"s*"),
                BUILDIN_DEF(next,""),
                BUILDIN_DEF(close,""),
 
Viewed 821 times, submitted by AnnieRuru.