[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Weapon usage limitations from skill training (got from an older post)

Weapon usage limitations from skill training (got from an older post)

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Oblisgr   (123 posts)  [Biography] bio
Date Sun 26 Jan 2020 05:11 PM (UTC)

Amended on Sun 26 Jan 2020 08:28 PM (UTC) by Oblisgr

Message
This post has inpiration from this old post.

https://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=9989

I am trying to do this myself for my mud but i get errors from obj_act. I have properly (without errors) added and registered my weapon skills in mud.h, db.c.

When i try to put them limit the weapon use in sct_obj.h it doesnt work.

I dont know if there is smothing else i didnt do.
Can you help me please?

*** and just tell me how i put spoiler messages***

Below as answers my code and the errors
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #1 on Sun 26 Jan 2020 05:12 PM (UTC)

Amended on Sun 26 Jan 2020 07:27 PM (UTC) by Fiendish

Message
my code to a point in act_obj.c:


void wear_obj( CHAR_DATA * ch, OBJ_DATA * obj, bool fReplace, short wear_bit )
{
OBJ_DATA *tmpobj = NULL;
short bit, tmp;
int *gsn_ptr = NULL;
 
   separate_obj( obj );
   /*if( get_trust( ch ) < obj->level )
    *{
    *   ch_printf( ch, "You must be level %d to use this object.\r\n", obj->level );
    *   act( AT_ACTION, "$n tries to use $p, but is too inexperienced.", ch, obj, NULL, TO_ROOM );
    *   return;
    *}
   */
 
   if( !IS_IMMORTAL( ch )
       && ( ( IS_OBJ_STAT( obj, ITEM_ANTI_WARRIOR ) && ch->Class == CLASS_WARRIOR )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_WARRIOR ) && ch->Class == CLASS_SAVAGE )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_WARRIOR ) && ch->Class == CLASS_PALADIN )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_MAGE ) && ch->Class == CLASS_MAGE )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_MAGE ) && ch->Class == CLASS_NEPHANDI )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_THIEF ) && ch->Class == CLASS_THIEF )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_VAMPIRE ) && ch->Class == CLASS_VAMPIRE )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_DRUID ) && ch->Class == CLASS_DRUID )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_WARRIOR ) && ch->Class == CLASS_RANGER )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_MAGE ) && ch->Class == CLASS_AUGURER )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_CLERIC ) && ch->Class == CLASS_CLERIC )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_GOOD ) && ch->alignment > 350 )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_NEUTRAL ) && ch->alignment >= -350 && ch->alignment <= 350 )
            || ( IS_OBJ_STAT( obj, ITEM_ANTI_EVIL ) && ch->alignment < -350 ) ) )
   {
      act( AT_MAGIC, "You are forbidden to use that item.", ch, NULL, NULL, TO_CHAR );
      act( AT_ACTION, "$n tries to use $p, but is forbidden to do so.", ch, obj, NULL, TO_ROOM );
      return;
   }
 
   if( IS_OBJ_STAT( obj, ITEM_PERSONAL ) && str_cmp( ch->name, obj->owner ) )
   {
      send_to_char( "That item is personalized and belongs to someone else.\r\n", ch );
      if( obj->carried_by )
         obj_from_char( obj );
      obj_to_room( obj, ch->in_room );
      return;
   }
 
   if( wear_bit > -1 )
   {
      bit = wear_bit;
      if( !CAN_WEAR( obj, 1 << bit ) )
      {
         if( fReplace )
         {
            switch ( 1 << bit )
            {
               case ITEM_HOLD:
                  send_to_char( "You cannot hold that.\r\n", ch );
                  break;
               case ITEM_WIELD:
               case ITEM_MISSILE_WIELD:
         switch ( obj->value[4] )
         {
         default:
            *gsn_ptr = -1;
            break;
         case DAM_HIT:
            *gsn_ptr = gsn_daggers;
            break;
         case DAM_SUCTION:
            *gsn_ptr = gsn_swords;
            break;
         case DAM_BITE:
            *gsn_ptr = gsn_greatswords;
            break;
         case DAM_BLAST:
            *gsn_ptr = gsn_hatchets;
            break;
         case DAM_SLASH:
            *gsn_ptr = gsn_greataxes;
            break;
         case DAM_SLICE:
            *gsn_ptr = gsn_maces;
            break;
         case DAM_PIERCE:
            *gsn_ptr = gsn_mauls;
            break;
         case DAM_STAB:
            *gsn_ptr = gsn_polearms;
            break;
         case DAM_WHIP:
            *gsn_ptr = gsn_fists;
            break;
         case DAM_CLAW:
            *gsn_ptr = gsn_staves;
            break;
         case DAM_POUND:
            *gsn_ptr = gsn_wands;
            break;
         case DAM_CRUSH:
            *gsn_ptr = gsn_guns;
            break;
         case DAM_BOLT:
            *gsn_ptr = gsn_bows;
            break;
         case DAM_ARROW:
            *gsn_ptr = gsn_crossbows;
            break;
         case DAM_DART:
         case DAM_STONE:
         case DAM_PEA:
            *gsn_ptr = gsn_thrown;
            break;
         }    
       
        if (*gns_ptr != NULL)
         ch_printf( ch, "gsn_ptr = %d", *gsn_ptr );
     
         if( LEARNED( ch, gsn_ptr ) < 1 )
         {
            send_to_char( "You have not trained in this form of weaponry.\r\n", ch );
            return;
         }
 
            }
         }
         return;
      }
   }
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #2 on Sun 26 Jan 2020 05:12 PM (UTC)

Amended on Sun 26 Jan 2020 06:41 PM (UTC) by Oblisgr

Message
and i get errors like:
---------------------------------------------------------

make -s smaug
  Compiling o/act_obj.o....
act_obj.c: In function ‘void wear_obj(CHAR_DATA*, OBJ_DATA*, bool, short int)’:
act_obj.c:1655:14: error: ‘gns_ptr’ was not declared in this scope
         if (*gns_ptr != NULL)
              ^~~~~~~
act_obj.c:1655:14: note: suggested alternative: ‘gsn_ptr’
         if (*gns_ptr != NULL)
              ^~~~~~~
              gsn_ptr
act_obj.c:1655:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
         if (*gns_ptr != NULL)
         ^~
act_obj.c:1658:10: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
          if( LEARNED( ch, gsn_ptr ) < 1 )
          ^~
In file included from act_obj.c:20:0:
mud.h:5112:83: error: invalid types ‘short int [500][int*]’ for array subscript
 #define LEARNED(ch,sn)     (IS_NPC(ch) ? 80 : URANGE(0, (ch)->pcdata->learned[(sn)], 101))
                                                                                   ^
mud.h:3067:43: note: in definition of macro ‘URANGE’
 #define URANGE(a, b, c )  ( urange( (a), (b), (c) ) )
                                           ^
act_obj.c:1658:14: note: in expansion of macro ‘LEARNED’
          if( LEARNED( ch, gsn_ptr ) < 1 )
              ^~~~~~~
Makefile:101: recipe for target 'o/act_obj.o' failed
make[1]: *** [o/act_obj.o] Error 1
Makefile:46: recipe for target 'all' failed
make: *** [all] Error 2
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sun 26 Jan 2020 06:29 PM (UTC)

Amended on Sun 26 Jan 2020 06:31 PM (UTC) by Fiendish

Message
You wrote gns_ptr instead of gsn_ptr.

Please use code tags when posting code with indentations.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #4 on Sun 26 Jan 2020 06:46 PM (UTC)

Amended on Sun 26 Jan 2020 06:48 PM (UTC) by Oblisgr

Message
Strange the code tag is not affecting the code post.
Anyway...

Yes that was a mistake that i had corrected before. Stored in a older code and when i pasted there is was again wrong. Anyway i corrected that but i still get errors:


  Compiling o/act_obj.o....
act_obj.c: In function ‘void wear_obj(CHAR_DATA*, OBJ_DATA*, bool, short int)’:
act_obj.c:1655:25: warning: NULL used in arithmetic [-Wpointer-arith]
         if (*gsn_ptr != NULL)
                         ^~~~
act_obj.c:1655:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
         if (*gsn_ptr != NULL)
         ^~
act_obj.c:1658:10: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
          if( LEARNED( ch, gsn_ptr ) < 1 )
          ^~
In file included from act_obj.c:20:0:
mud.h:5112:83: error: invalid types ‘short int [500][int*]’ for array subscript
 #define LEARNED(ch,sn)     (IS_NPC(ch) ? 80 : URANGE(0, (ch)->pcdata->learned[(sn)], 101))
                                                                                   ^
mud.h:3067:43: note: in definition of macro ‘URANGE’
 #define URANGE(a, b, c )  ( urange( (a), (b), (c) ) )
                                           ^
act_obj.c:1658:14: note: in expansion of macro ‘LEARNED’
          if( LEARNED( ch, gsn_ptr ) < 1 )
              ^~~~~~~
Makefile:101: recipe for target 'o/act_obj.o' failed
make[1]: *** [o/act_obj.o] Error 1
Makefile:46: recipe for target 'all' failed
make: *** [all] Error 2
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Sun 26 Jan 2020 07:22 PM (UTC)
Message
Quote:
Strange the code tag is not affecting the code post.

You must check the box for "Forum codes" when editing your post.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #6 on Sun 26 Jan 2020 07:24 PM (UTC)
Message
thats that worked.
any clue for these errors?
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #7 on Sun 26 Jan 2020 07:34 PM (UTC)

Amended on Sun 26 Jan 2020 07:35 PM (UTC) by Fiendish

Message
You probably shouldn't be using a pointer for this (gsn_ptr) when all you care about is the value. I don't think you can send a pointer as the second argument to LEARNED because the ch->pcdata->learned is an array of shorts.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #8 on Sun 26 Jan 2020 08:25 PM (UTC)

Amended on Sun 26 Jan 2020 08:28 PM (UTC) by Oblisgr

Message
can you give me an example please?
pleeeease :D

i m noob in proggraming
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #9 on Sun 26 Jan 2020 09:34 PM (UTC)
Message
This is my code now as i compiled without errors. I did as you said and based that on integers.

it has -1 as default and then on each dam_type it get a new number. Then it checks if number is higher than 0 or it executes the lines.

of course it gives me nothing incide game.

it supposed to forbid player of equiping certain types of weapon based on damage type as it was posted in:

https://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=9989


         switch ( obj->value[4] )
         {
            default:
            gsn_ptr = -1;
            break;
case DAM_HIT:
            gsn_ptr = 1;
            break;
         case DAM_SUCTION:
            gsn_ptr = 2;
            break;
         case DAM_BITE:
            gsn_ptr = 3;
            break;
         case DAM_BLAST:
            gsn_ptr = 4;
            break;
         case DAM_SLASH:
            gsn_ptr = 5;
            break;
         case DAM_SLICE:
            gsn_ptr = 6;
            break;
         case DAM_PIERCE:
            gsn_ptr = 7;
            break;
         case DAM_STAB:
            gsn_ptr = 8;
            break;
         case DAM_WHIP:
            gsn_ptr = 9;
            break;
         case DAM_CLAW:
            gsn_ptr = 10;
            break;
         case DAM_POUND:
            gsn_ptr = 11;
            break;
         case DAM_CRUSH:
            gsn_ptr = 12;
            break;
         case DAM_BOLT:
            gsn_ptr = 13;
            break;
         case DAM_ARROW:
            gsn_ptr = 14;
            break;
         case DAM_DART:
         case DAM_STONE:
         case DAM_PEA:
            gsn_ptr = 15;
            break;
         }    

         ch_printf( ch, "gsn_ptr = %d", gsn_ptr );
         if( LEARNED( ch, gsn_ptr ) < 0 )
         {
            send_to_char( "You have not trained in this form of weaponry.\r\n", ch );
            return;
         }
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #10 on Sun 26 Jan 2020 10:02 PM (UTC)

Amended on Sun 26 Jan 2020 10:12 PM (UTC) by Fiendish

Message
You replaced all the right-side gsns with simple numbers, but are those the right skill numbers from your skill_table for the skills you want to check? I think you want to keep all of the `gsn_ptr = gsn_mauls;` etc, and just not use `*` anymore because gsn_ptr is now not a pointer. I bet their values just aren't 1-15.

You should print obj->value[4] and the result of LEARNED(ch, gsn_ptr) to see what they say. Now that it compiles cleanly, you need to make sure that the logic is correct.

You should probably also rename gsn_ptr to just gsn, since it isn't a pointer anymore.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #11 on Mon 27 Jan 2020 11:11 AM (UTC)
Message
I did my code as following and i still get no message in game and the weapon is wielded even if the skill is 0% and even if the class has not that skill at all.

I tried this if i could get any message but not

printf( "gsn = %d", gsn );


and i have this code that isnt working i dont know why...

void wear_obj( CHAR_DATA * ch, OBJ_DATA * obj, bool fReplace, short wear_bit )
{
OBJ_DATA *tmpobj = NULL;
short bit, tmp;

  int gsn = -1;


and


           case ITEM_WIELD:
               case ITEM_MISSILE_WIELD:
         switch ( obj->value[4] )
         {
            default:
            gsn = -1;
            break;
         case DAM_HIT:
            gsn = gsn_daggers;
            break;
         case DAM_SUCTION:
            gsn = gsn_swords;
            break;
         case DAM_BITE:
            gsn = gsn_greatswords;
            break;
         case DAM_BLAST:
            gsn = gsn_hatchets;
            break;
         case DAM_SLASH:
            gsn = gsn_greataxes;
            break;
         case DAM_SLICE:
            gsn = gsn_maces;
            break;
         case DAM_PIERCE:
            gsn = gsn_mauls;
            break;
         case DAM_STAB:
            gsn = gsn_polearms;
            break;
         case DAM_WHIP:
            gsn = gsn_fists;
            break;
         case DAM_CLAW:
            gsn = gsn_staves;
            break;
         case DAM_POUND:
            gsn = gsn_wands;
            break;
         case DAM_CRUSH:
            gsn = gsn_guns;
            break;
         case DAM_BOLT:
            gsn = gsn_bows;
            break;
         case DAM_ARROW:
            gsn = gsn_crossbows;
            break;
         case DAM_DART:
         case DAM_STONE:
         case DAM_PEA:
            gsn = gsn_thrown;
            break;
         }    

         ch_printf( ch, "gsn = %d", gsn );
         if( LEARNED( ch, gsn ) < 1 )
         {
            send_to_char( "You have not trained in this form of weaponry.\r\n", ch );
            return;
         }
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #12 on Tue 28 Jan 2020 04:12 AM (UTC)

Amended on Tue 28 Jan 2020 04:13 AM (UTC) by Fiendish

Message
If nothing is printing, then your code isn't reaching that line. That means you have a logic error. Try to figure out which lines are being executed, and it will help you figure out why your code isn't being run.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,513 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]