Author Topic: help with attrib selection code  (Read 1582 times)

Offline thecreator

  • Acquaintance
  • *
  • Posts: 6
    • View Profile
help with attrib selection code
« on: October 21, 2006, 09:13:42 AM »

Hello,

This code is being like really weird, when I do add 5 to dex, it drops the remaining points by like 20, and then it adds the 5, but it won't work right with the remaining points. I tried abs, because I'm getting a negative val, but that didn't do much...

Any ideas?

<code language="lpc"></code>



//code//



 



 



#include <lib.h>

inherit LIB_ROOM;



mixed add(string str);

//mixed subtract(string str);

mixed points();



string *attribs=({"dex", "mech", "tech", "str"});



static void create() {

    room::create();

    SetClimate("indoors");

    SetAmbientLight(30);

    SetShort("Attribute selection and customization.");

    SetLong("This is where you will customize your character with your attribute

points. Type points to see a list of points that are available to you, type list to

see what attributes you can increase/decrease, and type add <points> to <attrib> or

subtract <points> from <attrib> to add and remove points.");

}



void init()

{

add_action((:add:), "add");

add_action((:points:), "points");

    ::init();

}



int CanReceive(object ob)

{

if (!ob->GetClass())

{

write("You must choose a profession.");

return 0;

}

return 1;

}



mixed add(string str)

{

mixed *cmds;

mixed res;

int num;

cmds=explode(str, " ");

if (!to_int(cmds[0]))

{

write("Syntax: add <points> to <attribute>\n");

return 1;

}

res=this_player()->AttribExists(cmds[2]);

if (!res)

{

write("Sorry, "+cmds[2]+" isn't a valid attribute.\nValud attributes are: dex, mech,

tech, and str.\n");

return 1;

}

res = 0; //initialize res to a known value.

switch (cmds[2])

{

case "dex":

num=(this_player()->GetDex());

num=num+to_int(cmds[0]);

res=this_player()->GetAttribBoundry("dex", num);

write(cmds[0]+"\n"+cmds[1]+"\n"+cmds[2]+"\n");

if (res == 1)

{

if (this_player()->GetPdistrib() < num)

{

write("Not enough points left to distribute. You have

"+this_player()->GetPdistrib()+" points left to distribute.");

return 1;

}

else

{

this_player()->SetPdistrib(abs((this_player()->GetPdistrib())-num));

write((this_player()->GetPdistrib())-num);

this_player()->SetDex(num);

write("Dex raised by "+cmds[0]+" your dex is now "+this_player()->GetDex()+".");

return 1;

}

return 1;

}

}

}



mixed points()

{

object player=this_player();

write("Dex: "+player->GetDex()+" Mech: "+player->GetMech()+" Tech:

"+player->GetTech()+" Str: "+player->GetStr()+" Points left to distribute:

"+player->GetPdistrib()+".");

return 1;

}



 



 





#include <lib.h>

inherit LIB_ROOM;



mixed add(string str);

//mixed subtract(string str);

mixed points();



string *attribs=({"dex", "mech", "tech", "str"});



static void create() {

    room::create();

    SetClimate("indoors");

    SetAmbientLight(30);

    SetShort("Attribute selection and customization.");

    SetLong("This is where you will customize your character with your attribute

points. Type points to see a list of points that are available to you, type list to

see what attributes you can increase/decrease, and type add <points> to <attrib> or

subtract <points> from <attrib> to add and remove points.");

}



void init()

{

add_action((:add:), "add");

add_action((:points:), "points");

    ::init();

}



int CanReceive(object ob)

{

if (!ob->GetClass())

{

write("You must choose a profession.");

return 0;

}

return 1;

}



mixed add(string str)

{

mixed *cmds;

mixed res;

int num;

cmds=explode(str, " ");

if (!to_int(cmds[0]))

{

write("Syntax: add <points> to <attribute>\n");

return 1;

}

res=this_player()->AttribExists(cmds[2]);

if (!res)

{

write("Sorry, "+cmds[2]+" isn't a valid attribute.\nValud attributes are: dex, mech,

tech, and str.\n");

return 1;

}

res = 0; //initialize res to a known value.

switch (cmds[2])

{

case "dex":

num=(this_player()->GetDex());

num=num+to_int(cmds[0]);

res=this_player()->GetAttribBoundry("dex", num);

write(cmds[0]+"\n"+cmds[1]+"\n"+cmds[2]+"\n");

if (res == 1)

{

if (this_player()->GetPdistrib() < num)

{

write("Not enough points left to distribute. You have

"+this_player()->GetPdistrib()+" points left to distribute.");

return 1;

}

else

{

this_player()->SetPdistrib(abs((this_player()->GetPdistrib())-num));

write((this_player()->GetPdistrib())-num);

this_player()->SetDex(num);

write("Dex raised by "+cmds[0]+" your dex is now "+this_player()->GetDex()+".");

return 1;

}

return 1;

}

}

}



mixed points()

{

object player=this_player();

write("Dex: "+player->GetDex()+" Mech: "+player->GetMech()+" Tech:

"+player->GetTech()+" Str: "+player->GetStr()+" Points left to distribute:

"+player->GetPdistrib()+".");

return 1;

}

~~TheCreator~~