root/npc/sample/monster_controller.txt @ 8

Revision 1, 5.0 kB (checked in by jinshiro, 17 years ago)
Line 
1// Variables Logging:
2// .mc_moblist[] - ID list of mobs
3prontera,180,200,4      script  Monster Controller      123,{
4        function display_info {
5                getmobdata getarg(0), .@mob_data;
6                set .@array_size, getarraysize(.@mob_data);
7                for(set .@i, 0; .@i < .@array_size; set .@i, .@i + 1){
8                        mes .@i + " - " + .@mob_data[.@i];
9                }
10                return;
11        }
12
13        function remove_mob {
14                mobremove getarg(0);
15                set .@mob_size, getarraysize(.mc_moblist);
16                for(set .@i, 0; .@i < .@mob_size; set .@i, .@i + 1){
17                        if(.mc_moblist[.@i] == getarg(0))
18                                deletearray .mc_moblist[.@i], 1;
19                }
20        }
21
22        function make_menu {
23                set .@array_size, getarraysize(.mc_moblist);
24                set .@tmp_str$, "";
25                for(set .@i, 0; .@i < .@array_size; set .@i, .@i + 1){
26                        set .@tmp_str$, .@tmp_str$ + .mc_moblist[.@i] + ":";
27                }
28                select .@tmp_str$;
29                return .mc_moblist[@menu-1];
30        }
31
32        function summon_mob {
33                set .@mob_size, getarraysize(.mc_moblist);
34                set .mc_moblist[.@mob_size], mobspawn("Slave - " + .@mob_size, getarg(0), "prontera", 180, 200);
35                mobattach .mc_moblist[.@mob_size];
36                setmobdata .mc_moblist[.@mob_size], 25,
37                        AI_ACTION_TYPE_ATTACK|
38                        AI_ACTION_TYPE_DETECT|
39                        AI_ACTION_TYPE_DEAD|
40                        AI_ACTION_TYPE_ASSIST|
41                        AI_ACTION_TYPE_KILL|
42                        AI_ACTION_TYPE_UNLOCK|
43                        AI_ACTION_TYPE_WALKACK|
44                        AI_ACTION_TYPE_WARPACK;
45                return;
46        }
47
48        function list_mobs {
49                set .@mob_size, getarraysize(.mc_moblist);
50                for(set .@i, 0; .@i < .@mob_size; set .@i, .@i + 1){
51                        mes "- " + .mc_moblist[.@i];
52                }
53                return;
54        }
55
56        if(getarraysize(.ai_action) == 4){
57                mapannounce "prontera", "[Mob Control] AI Action Received from " + .ai_action[AI_ACTION_SRC] + "!",16;
58                switch(.ai_action[AI_ACTION_TAR_TYPE]){
59                        case AI_ACTION_TAR_TYPE_PC:
60                                set .@action_from$, "Player";
61                                set .@action_name$, rid2name(.ai_action[AI_ACTION_TAR]);
62                                break;
63                        case AI_ACTION_TAR_TYPE_MOB:
64                                set .@action_from$, "Monster";
65                                set .@action_name$, rid2name(.ai_action[AI_ACTION_TAR]);
66                                break;
67                        case AI_ACTION_TAR_TYPE_PET:
68                                set .@action_from$, "Pet";
69                                set .@action_name$, rid2name(.ai_action[AI_ACTION_TAR]);
70                                break;
71                        case AI_ACTION_TAR_TYPE_HOMUN:
72                                set .@action_from$, "Homunculus";
73                                set .@action_name$, rid2name(.ai_action[AI_ACTION_TAR]);
74                                break;
75                        default:
76                                set .@action_from$, "Unknown";
77                                set .@action_name$, ""+.ai_action[AI_ACTION_TAR];
78                                break;
79                }
80
81                switch(.ai_action[AI_ACTION_TYPE]){
82                        case AI_ACTION_TYPE_ATTACK:
83                                set .@action_type$, "Attacked by";
84                                break;
85                        case AI_ACTION_TYPE_DETECT:
86                                set .@action_type$, "Detected";
87                                break;
88                        case AI_ACTION_TYPE_DEAD:
89                                set .@action_type$, "Killed by";
90                                remove_mob .ai_action[AI_ACTION_SRC];
91                                break;
92                        case AI_ACTION_TYPE_ASSIST:
93                                set .@action_type$, "Assisting";
94                                break;
95                        case AI_ACTION_TYPE_UNLOCK:
96                                set .@action_type$, "Unlocked target";
97                                break;
98                        case AI_ACTION_TYPE_KILL:
99                                set .@action_type$, "Killed";
100                                break;
101                        case AI_ACTION_TYPE_WALKACK:
102                                set .@action_type$, "Completed Walking";
103                                break;
104                        case AI_ACTION_TYPE_WARPACK:
105                                set .@action_type$, "Warped";
106                                break;
107                }
108
109                mapannounce "prontera", "Details - " + .@action_type$ + " [" + .@action_from$ + "] " + .@action_name$ + "!", 16;
110                deletearray .ai_action, 4;
111                end;
112        }
113
114L_MainMenu:
115        mes "[Monster Controller]";
116        mes "Current active monsters:";
117        list_mobs;
118        switch(select("Summon","Remove","Information","Actions")){
119                case 1: // Summon
120                        next;
121                        mes "[Monster Controller]";
122                        mes "Monster ID -";
123                        input @mob_id;
124                        next;
125                        summon_mob @mob_id;
126                        goto L_MainMenu;
127                        break;
128                case 2: // Remove
129                        remove_mob make_menu();
130                        next;
131                        goto L_MainMenu;
132                        break;
133                case 3: // Information
134                        set .@tmp, make_menu();
135                        next;
136                        mes "[Monster Info]";
137                        display_info .@tmp;
138                        next;
139            goto L_MainMenu;
140                        break;
141                case 4: // Actions
142                        goto L_AttackMenu;
143                        break;
144        }
145
146L_AttackMenu:
147        switch(select("Walk","Follow","Attack","Stop","Defend","Talk","Emote","Random Walk","Callback","Back")){
148                case 1: // Walk
149                        set .@src, make_menu();
150                        input .@x;
151                        input .@y;
152                        unitwalk .@src,.@x,.@y; // Mode 1: Walk to location.
153                        break;
154                case 2: // Follow
155                        set .@src, make_menu();
156                        input .@tar;
157                        unitwalk .@src, .@tar; // Mode 2: Walk to target.
158                        break;
159                case 3: // Attack
160                        set .@src, make_menu();
161                        input .@tar;
162                        unitattack .@src, .@tar;
163                        break;
164                case 4: // Stop
165                        set .@src, make_menu();
166                        unitstop .@src;
167                        break;
168                case 5: // Defend/Assist
169                        set .@src, make_menu();
170                        input .@tar;
171                        mobassist .@src, .@tar;
172                        break;
173                case 6: // Talk
174                        set .@src, make_menu();
175                        input .@text$;
176                        unittalk .@src, .@text$;
177                        break;
178                case 7: // Emote
179                        set .@src, make_menu();
180                        input .@emote;
181                        unitemote .@src, .@emote;
182                        break;
183                case 8:
184                        set .@src, make_menu();
185                        input .@flag;
186                        setmobdata .@src, 26, .@flag;
187                        break;
188                case 9:
189                        set .@src, make_menu();
190                        input .@flag;
191                        setmobdata .@src, 25, .@flag;
192                        break;
193                case 10:
194                        next;
195                        goto L_MainMenu;
196        }
197        goto L_AttackMenu;
198}
Note: See TracBrowser for help on using the browser.