Welcome to the Builder Academy

Question Trigger command without argument.

More
31 Aug 2020 01:53 - 31 Aug 2020 02:00 #9270 by cry1004
I became interested again in making mud.
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?

Code:
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.
Last edit: 31 Aug 2020 02:00 by cry1004.

Please Log in or Create an account to join the conversation.

More
31 Aug 2020 18:12 #9307 by thomas
It's very nice you've returned to mudding :)

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):
Code:
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:
Code:
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 },
Then create command triggers for the rooms, one for each color:
Code:
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
The following user(s) said Thank You: cry1004

Please Log in or Create an account to join the conversation.

More
31 Aug 2020 20:04 #9310 by cry1004
My knowledge has been +1 to your answer.

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.
Code:
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.

More
31 Aug 2020 23:10 #9318 by Parnassus
To answer the question about triggers, in case you can use the trigger somewhere else:
Code:
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.
The following user(s) said Thank You: cry1004

Please Log in or Create an account to join the conversation.

More
01 Sep 2020 19:51 #9364 by thomas

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:
Code:
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
This makes the command "red" work only in room 3100, where it teleports you to room 3102, the command "blue" only works in room 3101 and teleports you to room 3104, while you can use the command "violet" in a number of rooms.

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.
The following user(s) said Thank You: cry1004

Please Log in or Create an account to join the conversation.

More
01 Sep 2020 19:53 #9365 by thomas
For your use case, I'd go for triggers, by the way. It's by far the simplest approach - unless you're doing it to train your C ;)
The following user(s) said Thank You: cry1004

Please Log in or Create an account to join the conversation.

Time to create page: 0.301 seconds