Author Topic: CanReceive func  (Read 2175 times)

Offline Money

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
CanReceive func
« on: September 22, 2008, 08:15:58 pm »
hmm i'm having a little trouble making a baldric/sheath for weapons, my first time doing any kind of coding lol :D

Basically i want it so that the baldric can only store 1 weapon of a specific type, i have achieved making the baldric only store blade type weapons, however i can't seem to restrict it to only 1.

It would also be great if someone could tell me how i can get started on making short/long name of the baldric change when a weapon is stored in it.

Thanks in advance!

*EDIT*

ok i changed the code to

Code: [Select]
#include <lib.h>
#include <armor_types.h>
#include <damage_types.h>
inherit LIB_WORN_STORAGE;

static void create(){
    ::create();
    SetKeyName("baldric");
    SetAdjectives( ({"leather"}) );
    SetId( ({"baldric"}) );
    SetShort("a leather baldric");
    SetLong("A light yet sturdy looking sword baldric.");
    SetCanClose(1);
    SetMaxCarry(100);
    SetMass(200);
    SetBaseCost("silver",10);
    SetDamagePoints(100);
    SetArmorType(A_PANTS);
    SetProtection(COLD, 1);

}

int CanReceive(object ob)
{
return ::CanReceive(ob)
    && ( sizeof(all_inventory(this_object())) < 1 )
    && ( ob->GetWeaponType() == "blade");
}

void init(){
    worn_storage::init();
   
}

and the restrictions are working, so how would i get the weapon to change its description when a sword is in it?
« Last Edit: September 22, 2008, 08:27:56 pm by Money »

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: CanReceive func
« Reply #1 on: September 22, 2008, 08:25:09 pm »
Code: [Select]
if( sizeof(all_inventory(this_object())) < 1 ){
            write ("This baldric is full");
            return 0;
        }

This says "if the number of things in this object is less than one,
don't let anything else in here."

That is probably not what you want.

-Crat

Offline Money

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Re: CanReceive func
« Reply #2 on: September 22, 2008, 10:16:24 pm »
ignore initial the edit above this code works thanks to crat pointing out my function didnt make sense

Code: [Select]
#include <lib.h>
#include <armor_types.h>
#include <damage_types.h>
inherit LIB_WORN_STORAGE;

static void create(){
    ::create();
    SetKeyName("baldric");
    SetAdjectives( ({"leather"}) );
    SetId( ({"baldric"}) );
    SetShort("a leather baldric");
    SetLong("A light yet sturdy looking sword baldric.");
    SetCanClose(1);
    SetMaxCarry(100);
    SetMass(200);
    SetBaseCost("silver",10);
    SetDamagePoints(100);
    SetArmorType(A_PANTS);
    SetProtection(COLD, 1);

}

mixed CanReceive(object ob){
    if(ob->GetWeaponType() != "blade") {
      write ("You can only store swords in here.");
      return 0;
      }
        if( sizeof(all_inventory(this_object())) >= 1 ){
            write ("this shit is full");
            return 0;
        }
    return 1;
}
void init(){
    worn_storage::init();
   
}