- Posts: 47
- Thank you received: 1
Trigger command without argument.
- cry1004
- Topic Author
- Offline
- Senior Member
-
I'm localizing Tbamud and adding the necessary code.
I'm sorry for asking questions often. :)
I couldn't study the c language separately.
I'm studying C language these days, but I forget what I've studied since I'm over 50.
Still, I enjoy making mud game because of your kind answer. Thank you.
So, I prepared a question again today.
I have to move to a specific room when a specific command is entered.
I looked for a trigger to refer to.
But there were too many triggers to find what I was looking for.
Something similar I found required an argument with a specific command.
I only want to enter commands with no arguments.
I need commands that are only used in certain rooms.
For example, if I enter the blue command in room 7, I moved to room 74.
I created a command because I couldn't find a trigger command that didn't require an argument.
It moves well, but is it correct to make it like this?
For information, 7 commands are required, and each command moves to the corresponding room.
Blue, cyan, yellow, white, purple, green, red
command --- room move
blud --- 74
cyan --- 75
yellow -- 76 etc..
ACMD(do_goto_blue), ACMD(do_goto_cyan), ACMD(do_goto_yellow) etc..
By the way, we made 7 similar commands, and will one trigger solve them?
ACMD(do_goto_blue)
{
char buf[MAX_STRING_LENGTH];
room_rnum location;
if ((location = find_target_room(ch, GET_NAME(ch))) == NOWHERE)
return;
if (location != 7) {
send_to_char(ch, "%s", CONFIG_HUH);
return;
}
snprintf(buf, sizeof(buf), "$n 파랑으로 갔다.");
act(buf, TRUE, ch, 0, 0, TO_ROOM);
char_from_room(ch);
char_to_room(ch, 73);
snprintf(buf, sizeof(buf), "$n$Hn0 왔다.");
act(buf, TRUE, ch, 0, 0, TO_ROOM);
look_at_room(ch, 0);
enter_wtrigger(&world[IN_ROOM(ch)], ch, -1);
}
char_to_room(ch, 73);
And, I have to go to number 74, but I had to enter 73.
Please Log in or Create an account to join the conversation.
- thomas
-
- Offline
- Administrator
-
- Posts: 751
- Thank you received: 143
Here's how I would go about it (you're very close - the bug is that the number is an rnum when it should have been a vnum):
diff --git a/src/act.h b/src/act.h
index 93cce58..124e170 100644
--- a/src/act.h
+++ b/src/act.h
@@ -152,6 +152,14 @@ ACMD(do_gen_door);
#define SCMD_UNLOCK 2
#define SCMD_LOCK 3
#define SCMD_PICK 4
+
+/* do_goto_color */
+ACMD(do_goto_color);
+#define SCMD_BLUE 1
+#define SCMD_RED 2
+#define SCMD_INDIGO 3
+#define SCMD_VIOLET 4
+#define SCMD_YELLOW 5
/* Functions without subcommands */
ACMD(do_enter);
ACMD(do_follow);
diff --git a/src/act.movement.c b/src/act.movement.c
index ffef0d8..edac770 100644
--- a/src/act.movement.c
+++ b/src/act.movement.c
@@ -926,6 +926,58 @@ ACMD(do_wake)
}
}
+struct color_goto_data {
+ room_vnum from_room;
+ room_vnum to_room;
+ int subcommand;
+};
+const struct color_goto_data goto_data[] = {
+ { 3100, 3102, SCMD_RED},
+ { 3100, 3103, SCMD_VIOLET},
+ { 3101, 3104, SCMD_BLUE},
+ { 3102, 3101, SCMD_VIOLET},
+ { 3, 4, SCMD_VIOLET},
+ { 4, 1, SCMD_VIOLET},
+ { NOWHERE, -1, 0}
+};
+
+ACMD(do_goto_color)
+{
+ char buf[MAX_STRING_LENGTH];
+ room_rnum location = NOWHERE;
+ room_vnum pc_room;
+ int i;
+
+ if (IN_ROOM(ch) == NOWHERE) {
+ send_to_char(ch, "%s", CONFIG_HUH);
+ return;
+ }
+ pc_room = world[IN_ROOM(ch)].number;
+
+ for (i = 0; goto_data[i].from_room != NOWHERE; i++) {
+ if (goto_data[i].from_room == pc_room && goto_data[i].subcommand == subcmd) {
+ location = real_room(goto_data[i].to_room);
+ }
+ }
+ if (location == NOWHERE) {
+ send_to_char(ch, "%s", CONFIG_HUH);
+ return;
+ }
+
+ snprintf(buf, sizeof(buf), "$n 파랑으로 갔다.");
+ act(buf, TRUE, ch, 0, 0, TO_ROOM);
+
+ char_from_room(ch);
+ char_to_room(ch, location);
+
+ snprintf(buf, sizeof(buf), "$n$Hn0 왔다.");
+ act(buf, TRUE, ch, 0, 0, TO_ROOM);
+
+ look_at_room(ch, 0);
+ enter_wtrigger(&world[IN_ROOM(ch)], ch, -1);
+}
+
diff --git a/src/interpreter.c b/src/interpreter.c
index 0dadad0..6fe64be 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -106,6 +106,7 @@ cpp_extern const struct command_info cmd_info[] = {
{ "bandage" , "band" , POS_RESTING , do_bandage , 1, 0 },
{ "balance" , "bal" , POS_STANDING, do_not_here , 1, 0 },
{ "bash" , "bas" , POS_FIGHTING, do_bash , 1, 0 },
+ { "blue" , "blu" , POS_STANDING, do_goto_color, 0, SCMD_BLUE },
{ "brief" , "br" , POS_DEAD , do_gen_tog , 0, SCMD_BRIEF },
{ "buildwalk", "buildwalk", POS_STANDING, do_gen_tog , LVL_BUILDER, SCMD_BUI
LDWALK },
{ "buy" , "bu" , POS_STANDING, do_not_here , 0, 0 },
@@ -262,6 +263,7 @@ cpp_extern const struct command_info cmd_info[] = {
{ "recite" , "reci" , POS_RESTING , do_use , 0, SCMD_RECITE },
{ "receive" , "rece" , POS_STANDING, do_not_here , 1, 0 },
{ "recent" , "recent" , POS_DEAD , do_recent , LVL_IMMORT, 0 },
+ { "red" , "red" , POS_STANDING, do_goto_color, 0, SCMD_RED },
{ "remove" , "rem" , POS_RESTING , do_remove , 0, 0 },
{ "rent" , "rent" , POS_STANDING, do_not_here , 1, 0 },
{ "report" , "repo" , POS_RESTING , do_report , 0, 0 },
@@ -332,6 +334,7 @@ cpp_extern const struct command_info cmd_info[] = {
{ "value" , "val" , POS_STANDING, do_not_here , 0, 0 },
{ "version" , "ver" , POS_DEAD , do_gen_ps , 0, SCMD_VERSION },
{ "visible" , "vis" , POS_RESTING , do_visible , 1, 0 },
+ { "violet" , "viole" , POS_STANDING, do_goto_color, 0, SCMD_VIOLET },
{ "vnum" , "vnum" , POS_DEAD , do_vnum , LVL_IMMORT, 0 },
{ "vstat" , "vstat" , POS_DEAD , do_vstat , LVL_IMMORT, 0 },
{ "vdelete" , "vdelete" , POS_DEAD , do_vdelete , LVL_BUILDER, 0 },
However, it's proably just as easy to make a trigger in the given rooms.
Add the commands as do_not_here:
diff --git a/src/interpreter.c b/src/interpreter.c
index 0dadad0..6fe64be 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -106,6 +106,7 @@ cpp_extern const struct command_info cmd_info[] = {
{ "bandage" , "band" , POS_RESTING , do_bandage , 1, 0 },
{ "balance" , "bal" , POS_STANDING, do_not_here , 1, 0 },
{ "bash" , "bas" , POS_FIGHTING, do_bash , 1, 0 },
+ { "blue" , "blu" , POS_STANDING, do_not_here, 0, 0 },
{ "brief" , "br" , POS_DEAD , do_gen_tog , 0, SCMD_BRIEF },
{ "buildwalk", "buildwalk", POS_STANDING, do_gen_tog , LVL_BUILDER, SCMD_BUI
LDWALK },
{ "buy" , "bu" , POS_STANDING, do_not_here , 0, 0 },
@@ -262,6 +263,7 @@ cpp_extern const struct command_info cmd_info[] = {
{ "recite" , "reci" , POS_RESTING , do_use , 0, SCMD_RECITE },
{ "receive" , "rece" , POS_STANDING, do_not_here , 1, 0 },
{ "recent" , "recent" , POS_DEAD , do_recent , LVL_IMMORT, 0 },
+ { "red" , "red" , POS_STANDING, do_not_here, 0, 0 },
{ "remove" , "rem" , POS_RESTING , do_remove , 0, 0 },
{ "rent" , "rent" , POS_STANDING, do_not_here , 1, 0 },
{ "report" , "repo" , POS_RESTING , do_report , 0, 0 },
@@ -332,6 +334,7 @@ cpp_extern const struct command_info cmd_info[] = {
{ "value" , "val" , POS_STANDING, do_not_here , 0, 0 },
{ "version" , "ver" , POS_DEAD , do_gen_ps , 0, SCMD_VERSION },
{ "visible" , "vis" , POS_RESTING , do_visible , 1, 0 },
+ { "violet" , "viole" , POS_STANDING, do_not_here, 0, 0 },
{ "vnum" , "vnum" , POS_DEAD , do_vnum , LVL_IMMORT, 0 },
{ "vstat" , "vstat" , POS_DEAD , do_vstat , LVL_IMMORT, 0 },
{ "vdelete" , "vdelete" , POS_DEAD , do_vdelete , LVL_BUILDER, 0 },
Name: 'move with command: blue', VNum: [ 3098], RNum: [ 762]
Trigger Intended Assignment: Rooms
Trigger Type: Command , Numeric Arg: 100, Arg list: blue
Commands:
if %actor.room.vnum%==3040
%teleport% %actor% 3012
%force% %actor% look
halt
end
if %actor.room.vnum%==3012
%teleport% %actor% 3040
%force% %actor% look
end
Please Log in or Create an account to join the conversation.
- cry1004
- Topic Author
- Offline
- Senior Member
-
- Posts: 47
- Thank you received: 1
I newly learned to add commands to interpreter.c.
I need to check the location of the current room in ACMD (do_goto_color).
I don't want the player to enter this command anywhere.
I want players to enter commands only in certain rooms.
For example, I want the command to work only when the current player is in room number 7.
if (location != 7) {
send_to_char(ch, "%s", CONFIG_HUH);
return;
}
I can use it as it is, right?
Please Log in or Create an account to join the conversation.
- Parnassus
- Offline
- Administrator
-
- Posts: 366
- Thank you received: 54
1) Name : Test for colour teleport commands
2) Intended for : Rooms
3) Trigger types: Command
4) Numeric Arg : 100
5) Arguments : *
6) Commands:
if %cmd% == blue || %cmd% == cyan || %cmd% == yellow || %cmd% == white || %cmd% == purple || %cmd% == green || %cmd% == red
* Switches will convert the colors into teleport rooms.
* Replace following numbers with the correct teleport rooms.
switch %cmd%
case blue
set teleportroom 100
break
case cyan
set teleportroom 200
break
set yellow
case blue
set teleportroom 400
break
case white
set teleportroom 500
break
case purple
set teleportroom 600
break
case green
set teleportroom 700
break
case red
set teleportroom 2500
break
done
%teleport% %actor% %teleportroom%
%force% %actor% look
else
* Allow other commands to go through.
return 0
end
Note the * wildcard as the argument. When using the wildcard, be very careful to have an escape (such as those last few lines). You can expand this to cover as many colours as you like.
Personally, I prefer to make the colour an argument instead of a command, such as pushing the button on the elevator pane. but everyone has different ways of doing things.
Please Log in or Create an account to join the conversation.
- thomas
-
- Offline
- Administrator
-
- Posts: 751
- Thank you received: 143
cry1004 wrote: I want players to enter commands only in certain rooms.
...
I can use it as it is, right?
Yes, the struct defines from_toom and to_room. So it will only work in the rooms listed in that list:
const struct color_goto_data goto_data[] = {
{ 3100, 3102, SCMD_RED},
{ 3100, 3103, SCMD_VIOLET},
{ 3101, 3104, SCMD_BLUE},
{ 3102, 3101, SCMD_VIOLET},
{ 3, 4, SCMD_VIOLET},
{ 4, 1, SCMD_VIOLET},
{ NOWHERE, -1, 0} // must be last
Note that I didn't add all the different colors, neither as SCMD_s or as actual commands. This is more of a proof of concept you can expand on.
Please Log in or Create an account to join the conversation.
- thomas
-
- Offline
- Administrator
-
- Posts: 751
- Thank you received: 143
Please Log in or Create an account to join the conversation.
- cry1004
- Topic Author
- Offline
- Senior Member
-
- Posts: 47
- Thank you received: 1
Personally, I prefer to make the colour an argument instead of a command, such as pushing the button on the elevator pane. but everyone has different ways of doing things.
I did it because I was used to LPMUD, which I played in the past.
I wanted the elevator buttons to be displayed in the exit description, not in the room description.
LPMUD made it easy to mark exits from room to room.
If my memory is correct, it seems to have been processed in one file.
However, it is difficult for Circlemud to display special exit names other than east, west, south, north.
In normal rooms, the exit is marked as shown below.
Exits: North, South
Sometimes I just want to have a specific name appear in a specific room.
Exits: East, South, Coffeeshop
In another room
Exits: North, Underground
So, I was asking how I could mark and move special exits.
Once again, thank you. :)
Please Log in or Create an account to join the conversation.
- Parnassus
- Offline
- Administrator
-
- Posts: 366
- Thank you received: 54
I'm not suggesting you change bases but you may want to look at their code to see if you can figure out how they did it. In my opinion, TBA is a much better base but it's interesting to see how other other coders did things.
SMAUG supports having more than one exit in the same direction, as well as the special direction 'somewhere', represented by a '?'. If you already have an exit leading north, and would like another one, use a plus sign '+' in front of the direction:
redit exit +n 3001 - Adds another exit north to room 3001
To modify an extra exit like this, or to remove it, you'll have to refer to it by number:
redit exit #2 3002 - Change the second exit to go to room 3002
To know what number an exit is, do an "rstat".
For someone to be able to use the second north exit, you have to set one of the extra flags (see Exflags) like CAN_CLIMB. It is also usually a good idea to set the HIDDEN flag for any special exit so that it looks nicer with autoexits on.
The AUTO flag makes it possible to go in a direction by simply typing the keyword for that exit:
redit exit ? 3001 - Create a 'somewhere' exit to 3001
redit exflags ? auto hidden - Set the proper flags
redit exname ? swim - Set the keyword "swim"
(If a player types 'swim' in the room, they will move to room 3001.)
Please Log in or Create an account to join the conversation.