How can I do this?
#1

I want to make it so when a user uses the command /selldrugs. He is able to sell to different people at the same time. Also, the receiver of drugs, should be able to get multiple offers from different users at the same time.
How can I do that?
Reply
#2

Okay nice. i like it.


Sir, we need your selldrugs code to help you.
Reply
#3

Quote:
Originally Posted by iLearner
View Post
Okay nice. i like it.


Sir, we need your selldrugs code to help you.
I'm not asking for the command. I'm asking for a way to do it. You don't have to make the command for me.
Reply
#4

Bump.
Reply
#5

You'd probably want to create an array to keep track of any offers, with an enumerator for an offer object. Something like this:
Code:
enum drugOffer {
  offererID, // seller
  offereeID, // potential buyer
  //Possible some more data like drug type, amount, price
}
#define MAX_OFFERS 200 // at most, 200 offers can exist
new drugOffers[MAX_OFFERS][drugOffer]
Then, when you sell drugs to someone you create an offer by finding the nearest empty ID in the array and fill that with the correct data. You then inform the seller and the (potential) buyer of the offer and the ID it has, e.g. "Player Foo has offered to sell you drugs of type X for price Y. Use /buydrugs id to accept.".

If the buyer decides to take the offer you can just use the ID to check the array if the offer indeed applies to the buyer (so the buyer cannot buy anyone's offer, just specific ones to him) and you can reset the values in the array to -1 to make it clear that the slot is empty.

Alternatively, if the buyer decides not to buy it, you could either make a /canceloffer function or wait for, say, 30 seconds before timing out the offer and resetting it.

If you want to sell to multiple people at the same time you could make it dependent on being near enough to the seller of the drugs, so your enum no longer contains an offereeID but instead you check if the buyer is near enough to the seller to buy the items.
Reply
#6

Quote:
Originally Posted by Hiddos
View Post
You'd probably want to create an array to keep track of any offers, with an enumerator for an offer object. Something like this:
Code:
enum drugOffer {
  offererID, // seller
  offereeID, // potential buyer
  //Possible some more data like drug type, amount, price
}
#define MAX_OFFERS 200 // at most, 200 offers can exist
new drugOffers[MAX_OFFERS][drugOffer]
Then, when you sell drugs to someone you create an offer by finding the nearest empty ID in the array and fill that with the correct data. You then inform the seller and the (potential) buyer of the offer and the ID it has, e.g. "Player Foo has offered to sell you drugs of type X for price Y. Use /buydrugs id to accept.".

If the buyer decides to take the offer you can just use the ID to check the array if the offer indeed applies to the buyer (so the buyer cannot buy anyone's offer, just specific ones to him) and you can reset the values in the array to -1 to make it clear that the slot is empty.

Alternatively, if the buyer decides not to buy it, you could either make a /canceloffer function or wait for, say, 30 seconds before timing out the offer and resetting it.

If you want to sell to multiple people at the same time you could make it dependent on being near enough to the seller of the drugs, so your enum no longer contains an offereeID but instead you check if the buyer is near enough to the seller to buy the items.
Thanks man! It's exactly what I needed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)