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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Modification to buy command
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Modification to buy command
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Robert Powell   Australia  (367 posts)  [Biography] bio
Date Mon 01 Nov 2004 07:51 AM (UTC)  quote  ]
Message
All the different variables for pc's are in mud.h under pc data, and as Mirrodan has aluded to you can access them by ch->varname.

Peace.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
[Go to top] top

Posted by Mirrodan   USA  (28 posts)  [Biography] bio
Date Sun 31 Oct 2004 10:04 PM (UTC)  quote  ]
Message
I can give ya some advice...as to how to go about starting to look for the variables and functions that are already in place to do what you're asking...

first there's a few files that you'll need to become familiar with...

build.c
mud.h
player.c
save.c
shops.c

traditiondally in smaug most skills/commads start of like so....

void do_mynewcommand(CHAR_DATA * ch, char *argument)
{
arguements blah blah
{

ch-> will access player data or victim-> depending on the type of command/skill....

I'd give ya more but, I'm a little bit tired.. there's just some stuff to go off of...

-Mirrodan

Admin and Head Coder
For Techno-Magicka
techno-magicka.dreasphere.org 4000
AIM: tchnmgck
MSN: newell_everett@hotmail.com
YAHOO: everettnewell
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Sun 31 Oct 2004 09:47 PM (UTC)  quote  ]
Message
Well, here is how I would do it.

There is a certain structure to each command, in which you take the characters data and what they put as input, which looks like:

void do_commandname( CHAR_DATA *ch, char *argument )
{
  /* command stuff here */
}

Also, in order to add a command, you must add it in tables.c and do something such as DECLARE_DO_FUN( do_haggle ); in mud.h.

In this case, I think a better solution would be this. Modify do_buy and do_sell, and just add in a haggle function. That way you just call it from either do_sell or do_buy, and it automatically haggles.

Here's some code to give you some structure:

int haggle( CHAR_DATA *ch, CHAR_DATA *keeper, OBJ_INDEX_DATA * obj, bool is_selling )
{
 int endprice = obj->price;

 if ( !ch || !keeper || !obj )
  return 100;

 if ( ch->pcdata->learned[gsn_haggle] )
 {  
   if ( is_selling == TRUE )
   {
     /* equations go here */
     endprice += (int)(ch->pcdata->learned[gsn_haggle]/10);

     if ( get_curr_int(ch) > get_curr_int(keeper) )
       endprice += endprice*1.5;

     if ( get_curr_lck(ch) > number_range( 5, 50 ) )
      endprice += endprice*2;
   }
   else /* buying */
   {
     if ( get_curr_cha(ch) > get_curr_wis(keeper) )
      endprice = endprice-(endprice*.5);

     endprice = endprice-(ch->pcdata->learned[gsn_haggle]/10);
   }
 }
 
  return endprice;
}

There is a VERY basic example. I wouldnt really support using that function, as it definitely needs a way to balance the cost of things. However, it does illustrate my thinking. The function returns the final cost of the object. But you will need to jump into the do_buy and do_sell code a lot more to get a good haggle function.

To call it from do_buy or do_sell, you just need to do something such as:
For do_buy:
buyprice = haggle( ch, keeper, obj, FALSE );

For do_sell:
sellprice = haggle(ch, keeper, obj, TRUE );


This code is also implying that you added haggle as a skill.

Hopefully that helpped you, maybe it didn't. Good luck :)

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,631 posts)  [Biography] bio   Forum Administrator
Date Sun 31 Oct 2004 09:36 PM (UTC)  quote  ]
Message
I'm not sure what the exact problem is here. It is quite time-consuming to make up a general example of something to solve a fairly undefined problem.

If you illustrate what you have tried, and where it went wrong, it is easier to help.

I've moved your question to "SMAUG coding" because that is what it is really about.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Skaphia   (1 post)  [Biography] bio
Date Sun 31 Oct 2004 08:32 PM (UTC)  quote  ]
Message
This is my first post here, let me know if I'm posting in the wrong place.

I have been a coder of C/C++ for 3 years, but I stopped using it for 3 years. I've re-read a book of mine, and I can build with C just fine. I understand it perfectly.

My issue is that to get back into the swing of things, I've taken on a pretty simplistic project for SMAUG codebase, which is obviously based in C. In a nutshell, this would be to create a command 'haggle' that would allow a player to 'haggle itemname price' and based on int/cha/lck and some randomization allow the player to either get a lower shop price on that item (for the rest of the shop's hours), or to fail and have ALL store prices go up for the rest of the store's hours.

My problem isn't constructing this in C. My problem is that I have to reference a number of functions to get information from them in order to do this. Character statistics, etc plus the shop commands to update. I'm not sure if this is really a question more than frustration.

If I started from scratch, the simple mathematics of it would be fine. Referencing other functions that are pretty large and confusing to me is my problem, and I'm finding myself unable to really construct it to pull those variables and "do" the command.

Could someone maybe give me a shell on how I might construct this? Feel free to use imaginary function names etc, just so I have an idea of maybe how to approach this better. I think my approach is overwhelming and I'm diving in the middle of the SMAUG codebase
[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.


2,568 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [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.

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]