Author Topic: One time stat or skill increase.  (Read 3964 times)

Offline AskMeLater

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
One time stat or skill increase.
« on: December 26, 2008, 06:28:04 pm »
I have a book that requires a user to be a certain level to read it.  I would also like this book to give the user a one time increase to their wisdom.  Currently I've overridden the book::GetRead function.  However, every time they read the book, their wisdom is increased.  Obviously that won't do.  What is a common way of adding one time stat or skill adjustments to actions that might be repeatedly performed by the player?  For example you want this stat or skill adjustment to only occur the first time the player performs this action.

Thanks,

Offline Sluggy

  • Friend
  • **
  • Posts: 91
    • View Profile
    • Stellarmass
Re: One time stat or skill increase.
« Reply #1 on: December 26, 2008, 08:50:04 pm »
For starters I would add an array and two functions to the player.c file. One function takes a string parameter and adds it to this array. The other would take a string parameter and return true or false depending if it found that string within the array's collection. For here, all you have to do within your book's read method is first check to see if the title of the book (or any unique identifying string you want) is already within the player's list. If not, add it and apply your bonus.

Technically properties aren't supposed to be saved with the character but for some reason this has not been my experience. You could also try this with properties but don't hold me to that.

Offline AskMeLater

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: One time stat or skill increase.
« Reply #2 on: December 26, 2008, 09:05:16 pm »
Thanks sluggy.  Create a reading list for the player.  I could do, as you suggested in another post, create a custom book object.  It would use the new functionality of player.c.  That way the reading list would be small and only include "special" books. 

Offline AskMeLater

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: One time stat or skill increase.
« Reply #3 on: December 27, 2008, 01:25:28 pm »
I added a string array and a function called HasRead to player.c.  I'm trying to use member_array to determine if the the string passed to HasRead exists in the array.  I keep getting an error saying:

*Bad argument 2 to member_array()
Expected: string or array Got: 0.


Here is the code:


string *books_read = ({});


int HasRead(string book_name) {
        return member_array(book_name, books_read);
}

Anyone know what I"m doing wrong?

Thanks,

Offline Sluggy

  • Friend
  • **
  • Posts: 91
    • View Profile
    • Stellarmass
Re: One time stat or skill increase.
« Reply #4 on: December 27, 2008, 04:36:50 pm »
Everything you show here seems in order. It probably means whatever is being passed to HasRead() is sending an int of 0. Are you passing a function call as a parameter to HasRead()? Perhaps you spelled it incorrectly and the system is return 0 because the function you named doesn't exist.

Scratch that I realized it is the second parameter that is zero. Check that instead. Again, is it a function call? Or did you simply forget to initialize the array like you have in this example?

« Last Edit: December 27, 2008, 04:44:08 pm by Sluggy »

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: One time stat or skill increase.
« Reply #5 on: December 27, 2008, 05:21:26 pm »
For single purposes like this, I would recommend you just use player->AddProperty("read_my_special_book", 1); instead of adding more code which would do the same thing. 'Properties' are just a general-purpose way of storing random information. It looks they are saved when quitting. You can check player->GetProperty("read_my_special_book"); to see if it's set.

Offline AskMeLater

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: One time stat or skill increase.
« Reply #6 on: December 27, 2008, 07:15:57 pm »
After restarting the mud, it appears to work.  I guess I wasn't updating correctly.  Anyway thanks for taking the time to respond.


Offline skullslayer

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Re: One time stat or skill increase.
« Reply #7 on: December 28, 2008, 06:50:40 pm »
Also remember that with member_array it will return -1 for no match, and 0..size-1 for a match. Your HasRead function usage should take that into account.