What am i missing ?

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6447 by JTP
What am i missing ? was created by JTP
  if (where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) {
    if (free_hands(ch) < 1 && !OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
    }
    if (free_hands(ch) < 2 && OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
 }
}
gcc -g -O2 -Wall    -c -o act.item.o act.item.c
act.item.c: In function ‘perform_wear’:
act.item.c:1312: error: too few arguments to function ‘free_hands’
act.item.c:1316: error: too few arguments to function ‘free_hands’
make[1]: *** [act.item.o] Error 1



And is if (OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
enough to replace IS_OBJ_STAT....... ?
  /* circlemud code */
 int free_hands(struct char_data *ch) {

    int used = 2;

    if(GET_EQ(ch, WEAR_HOLD)) { used -= 1; }
    if(GET_EQ(ch, WEAR_LIGHT)) { used -= 1; }
    if(GET_EQ(ch, WEAR_SHIELD)) { used -= 1; }
    if(GET_EQ(ch, WEAR_OFFHAND)) { used -= 1; }
    if(GET_EQ(ch, WEAR_WIELD)) {
       if(IS_OBJ_STAT(GET_EQ(ch, WEAR_WIELD), ITEM_TWO_HANDED)) {
         used -= 2;
       }
       else { used -= 1; }
    }
 
    return used;

 }
Last edit: 1 year 6 months ago by JTP.

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

More
1 year 6 months ago #6450 by thomas
Replied by thomas on topic What am i missing ?
This code looks ok to me. What's before the checks in the first bit?

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

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6451 by JTP
Replied by JTP on topic What am i missing ?
Original circlemud snippet, seems the IS_OBJ_STAT dont Work with tba
 Open act.item.c.
 
 Before the perform_put() function add:
 
 int free_hands(struct char_data *ch) {

    int used = 2;

    if(GET_EQ(ch, WEAR_HOLD)) { used -= 1; }
    if(GET_EQ(ch, WEAR_LIGHT)) { used -= 1; }
    if(GET_EQ(ch, WEAR_SHIELD)) { used -= 1; }
    if(GET_EQ(ch, WEAR_OFFHAND)) { used -= 1; }
    if(GET_EQ(ch, WEAR_WIELD)) {
       if(IS_OBJ_STAT(GET_EQ(ch, WEAR_WIELD), ITEM_TWO_HANDED)) {
         used -= 2;
       }
       else { used -= 1; }
    }
 
    return used;

 }
 
 
 Further down in act.item.c in the:
 
 void perform_wear(struct char_data * ch, struct obj_data * obj, int where) {
 
 function, look for this:
 
   if (GET_EQ(ch, where)) {
     send_to_char(already_wearing[where], ch);
     return;
   }
 
 
 Directly below that chunk of code add:
 
   if(where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) {
     if(free_hands(ch) < 1 && !IS_OBJ_STAT(obj, ITEM_TWO_HANDED)) {
        send_to_char("You hands are full!\r\n", ch);
        return;
     }
     if(free_hands(ch) < 2 && IS_OBJ_STAT(obj, ITEM_TWO_HANDED)) {
        send_to_char("Your hands are full!\r\n", ch);
        return;
     }
   }
 
 
 Save the file and exit.

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

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6452 by JTP
Replied by JTP on topic What am i missing ?
If i put it in as snippet says, still the 2 errors with too few arguments + the IS_OBJ_STAT

act.item.c: In function ‘free_hands’:
act.item.c:57: warning: implicit declaration of function ‘IS_OBJ_STAT’
act.item.c: In function ‘perform_wear’:
act.item.c:1312: error: too few arguments to function ‘free_hands’
act.item.c:1316: error: too few arguments to function ‘free_hands’
make[1]: *** [act.item.o] Error 1

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

More
1 year 6 months ago #6453 by thomas
Replied by thomas on topic What am i missing ?
When in doubt, refactor.

You are right, instead of IS_OBJ_STAT, we now use OBJ_FLAGGED. So far so good.
  if (where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) {
    int hands = free_hands(ch);
    if (hands < 1 && !OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
    }
    if (hands < 2 && OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
    }
}
Apart from the obvious change from two calls to the free_hands function to one call, does this alter your result?

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

More
1 year 6 months ago #6454 by thomas
Replied by thomas on topic What am i missing ?
Also, you might want to alter the free_hands function declaration slightly:
- int free_hands(struct char_data *ch) {
+ static int free_hands(struct char_data *ch) {

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

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6455 by JTP
Replied by JTP on topic What am i missing ?
Those two sets of changes gives:


act.item.c: In function ‘perform_wear’:
act.item.c:1312: error: too few arguments to function ‘free_hands’
make[1]: *** [act.item.o] Error 1


Line 1312:
int hands = free_hands(ch);


Code used for above:
static int free_hands(struct char_data *ch, struct obj_data *obj);

static int free_hands(struct char_data *ch, struct obj_data *obj) {
   int used = 2;
   if (GET_EQ(ch, WEAR_HOLD)) { used -= 1; }
   if (GET_EQ(ch, WEAR_LIGHT)) { used -= 1; }
   if (GET_EQ(ch, WEAR_SHIELD)) { used -= 1; }
   if (GET_EQ(ch, WEAR_WIELD)) {
       if (OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        used -= 2;
       }
       else { used -= 1; }
   }
   return used;
}

/* And in: static void perform_wear(struct char_data *ch, struct obj_data *obj, int where) */


  if (where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) {
    int hands = free_hands(ch);
    if (hands < 1 && !OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
    }
    if (hands < 2 && OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
 }
}



Last edit: 1 year 6 months ago by JTP.

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

More
1 year 6 months ago #6456 by Liko
Replied by Liko on topic What am i missing ?

JTP wrote: Those two sets of changes gives:


act.item.c: In function ‘perform_wear’:
act.item.c:1312: error: too few arguments to function ‘free_hands’
make[1]: *** [act.item.o] Error 1


Line 1312:
int hands = free_hands(ch);


Code used for above:

static int free_hands(struct char_data *ch, struct obj_data *obj);

static int free_hands(struct char_data *ch, struct obj_data *obj) {
   int used = 2;
   if (GET_EQ(ch, WEAR_HOLD)) { used -= 1; }
   if (GET_EQ(ch, WEAR_LIGHT)) { used -= 1; }
   if (GET_EQ(ch, WEAR_SHIELD)) { used -= 1; }
   if (GET_EQ(ch, WEAR_WIELD)) {
       if (GET_EQ(ch, WEAR_WIELD) || OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        used -= 2;
       }
       else { used -= 1; }
   }
   return used;
}

/* And in: static void perform_wear(struct char_data *ch, struct obj_data *obj, int where) */


  if (where == WEAR_WIELD || where == WEAR_SHIELD || where == WEAR_LIGHT || where == WEAR_HOLD) {
    int hands = free_hands(ch);
    if (hands < 1 && !OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
    }
    if (hands < 2 && OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
        send_to_char(ch, "Your hands are full!\r\n");
        return;
 }
}




If I am reading the above code right, your free_hands is calling for a character and object.
free_hands(ch, obj);

That is just an example.

DragonBall: Tournament (1.2.0)
Owner/Developer

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

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6459 by JTP
Replied by JTP on topic What am i missing ?
Ok I got it compiling and almost working..


If I Wear shield/light/hold first, and then try to wield the two-handed, then I cant do it, this works as it should.

BUT if I wield the two-handed first, and then Wear shield/light/hold, then I can do that, but should not be able to.



So why is that, any idea ?
Last edit: 1 year 6 months ago by JTP.

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

More
1 year 6 months ago #6460 by Liko
Replied by Liko on topic What am i missing ?

JTP wrote: Ok I got it compiling and almost working..


If I Wear shield/light/hold first, and then try to wield the two-handed, then I cant do it, this works as it should.

BUT if I wield the two-handed first, and then Wear shield/light/hold, then I can do that, but should not be able to.



So why is that, any idea ?


Sounds like you need to program a check that says if already holding a two-handed, then can't hold anything else.

DragonBall: Tournament (1.2.0)
Owner/Developer

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

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6461 by JTP
Replied by JTP on topic What am i missing ?
Kinda thought it did, int used = 2

And if you wield a two-handed its -=2

Then it should be at 0

Then with either a shield or hold or light it would end up at -1


So if anyone could show me how to fix this, i would apreciate it.

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

More
1 year 6 months ago - 1 year 6 months ago #6462 by thomas
Replied by thomas on topic What am i missing ?
Get rid of the useless "struct obj_data *obj " from that call. And fix this check:
   if (GET_EQ(ch, WEAR_WIELD)) {
-       if (GET_EQ(ch, WEAR_WIELD) || OBJ_FLAGGED(obj, ITEM_TWO_HANDED)) {
+       if (OBJ_FLAGGED(GET_EQ(ch, WEAR_WIELD), ITEM_TWO_HANDED)) {
        used -= 2;
       }
       else { used -= 1; }
   }
Last edit: 1 year 6 months ago by thomas.

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

  • JTP
  • Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6463 by JTP
Replied by JTP on topic What am i missing ?
That worked, thanks.

A final thing, before this is top dollar. I would like race giant to have used 3:
 if (GET_RACE(ch) == RACE_GIANT) {
   int used = 3;
} else {
   int used = 2;
}

But then i get error, and suddently used is unused, and further Down undeclared:

act.item.c: In function ‘free_hands’:
act.item.c:53: warning: unused variable ‘used’
act.item.c:55: warning: unused variable ‘used’
act.item.c:57: error: ‘used’ undeclared (first use in this function)
act.item.c:57: error: (Each undeclared identifier is reported only once
act.item.c:57: error: for each function it appears in.)
make[1]: *** [act.item.o] Error 1

Merry Christmas to all
Last edit: 1 year 6 months ago by JTP.

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

More
1 year 6 months ago #6464 by thomas
Replied by thomas on topic What am i missing ?
int used = 2;

if (GET_RACE(ch) == RACE_GIANT) {
   used = 3;
} 
You need to have the "int" part in the same {}-part it is used, or further out. If you put it inside the if's the variable will be unknown outside the if's.

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

Time to create page: 1.754 seconds