SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/11/2016, 04:04 PM   #1
danielpalade
Huge Clucker
 
Join Date: Aug 2013
Posts: 387
Reputation: 1
Default How can I do this?

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?
danielpalade is offline   Reply With Quote
Old 27/11/2016, 04:31 PM   #2
iLearner
Guest
 
Posts: n/a
Default Re: How can I do this?

Okay nice. i like it.


Sir, we need your selldrugs code to help you.
  Reply With Quote
Old 27/11/2016, 04:46 PM   #3
danielpalade
Huge Clucker
 
Join Date: Aug 2013
Posts: 387
Reputation: 1
Default Re: How can I do this?

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.
danielpalade is offline   Reply With Quote
Old 27/11/2016, 09:35 PM   #4
danielpalade
Huge Clucker
 
Join Date: Aug 2013
Posts: 387
Reputation: 1
Default Re: How can I do this?

Bump.
danielpalade is offline   Reply With Quote
Old 27/11/2016, 09:52 PM   #5
Hiddos
High-roller
 
Hiddos's Avatar
 
Join Date: Sep 2008
Posts: 3,304
Reputation: 2184
Default Re: How can I do this?

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.
__________________
Quote:
Originally Posted by DeWolf View Post
For fuck's sake people, this whole thread is fucked up now.
Hiddos is offline   Reply With Quote
Old 27/11/2016, 10:06 PM   #6
danielpalade
Huge Clucker
 
Join Date: Aug 2013
Posts: 387
Reputation: 1
Default Re: How can I do this?

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.
danielpalade is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 04:41 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.