PDA

View Full Version : How can I do this?


danielpalade
27/11/2016, 04:04 PM
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?

iLearner
27/11/2016, 04:31 PM
Okay nice. i like it.


Sir, we need your selldrugs code to help you.

danielpalade
27/11/2016, 04:46 PM
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.

danielpalade
27/11/2016, 09:35 PM
Bump.

Hiddos
27/11/2016, 09:52 PM
You'd probably want to create an array to keep track of any offers, with an enumerator for an offer object. Something like this:
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.

danielpalade
27/11/2016, 10:06 PM
You'd probably want to create an array to keep track of any offers, with an enumerator for an offer object. Something like this:
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.