SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 20/05/2019, 11:42 PM   #1
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default How to grouping? 10 pcs equals 1 box

In this post, I want to ask something.
So, I'm confused how to do "Grouping".
I mean for example I sell 20 carrots to the warehouse. 10 carrots are 1 box. So in the warehouse there will be 2 Crates containing 20 carrots. How to do it?

This is my code:

PHP Code:
CMD:sellplant(playeridparams[])
{
    
//set the crate stock \/ \/ \/
    
CratePoints[0][CrateStock] += PlayerInfo[playerid][pWheat][0] + 5// Stock crate at the 0th crate point, plus pWheat0 (Carrot) + 5
    
PlayerInfo[playerid][pWheat][0] = 0;
    
GivePlayerCash(playerid10000);
    
UpdateCrateText(0);
    return 
1;
}

stock UpdateCrateText(pointid// Update pointid's 3D Text
{
    new 
string[512];
    
format(stringsizeof(string), "[Stock: {FFFF00}%d{FFFFFF} / {00FFFF}%d{FFFFFF}]\nGunakan {FFFF00}/getcrate{FFFFFF} untuk mengambil crate"CratePoints[pointid][CrateStock], MAX_CRATESTOCK);
    
UpdateDynamic3DTextLabelText(CratePoints[pointid][cratepointText], COLOR_WHITEstring);
    return 
1;

I have sold 123 carrots, and the crate stock is become 128



Really Need Help
KinxpIn is offline   Reply With Quote
Old 20/05/2019, 11:45 PM   #2
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: How to grouping? 10 pcs equals 1 box

PHP Code:
//enum data:

enum E_CratePoint
{
    
FloatcrateX,
    
FloatcrateY,
    
FloatcrateZ,
    
CrateStock,
    
Text3DcratepointText
    
//CratePointID
};
new 
CratePoints[3][E_CratePoint] =
{
    {-
375.4490, -1451.706825.8277}, // Farmer Point
    
{2836.5415, -1540.783211.0991}, // Fisher Point
    
{373.8647869.914020.4063// Miner Point
}; 
KinxpIn is offline   Reply With Quote
Old 21/05/2019, 06:11 AM   #3
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: How to grouping? 10 pcs equals 1 box

Help please
KinxpIn is offline   Reply With Quote
Old 21/05/2019, 07:50 AM   #4
Koreadars
Big Clucker
 
Join Date: Mar 2019
Location: Czech Republic, Prdelákov.
Posts: 116
Reputation: 6
Default Re: How to grouping? 10 pcs equals 1 box

Create a car in which you'll store the number of boxes. Simply.
Koreadars is offline   Reply With Quote
Old 21/05/2019, 01:25 PM   #5
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: How to grouping? 10 pcs equals 1 box

Quote:
Originally Posted by Koreadars View Post
Create a car in which you'll store the number of boxes. Simply.
You don't know what I mean right? Try reading again
KinxpIn is offline   Reply With Quote
Old 21/05/2019, 01:56 PM   #6
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,094
Reputation: 521
Default Re: How to grouping? 10 pcs equals 1 box

Number of carrots / Number of carrots per crate = Number of crates needed



20 / 10 = 2
__________________

Kar's Cops and Robbers 2019
Threshold is offline   Reply With Quote
Old 21/05/2019, 02:13 PM   #7
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: How to grouping? 10 pcs equals 1 box

Quote:
Originally Posted by Threshold View Post
Number of carrots / Number of carrots per crate = Number of crates needed



20 / 10 = 2
So,

CratePoints[0][CrateStock] += PlayerInfo[playerid][pWheat][0] / 10;



That means I have to limit if players want to sell carrots, at least 10 seeds must be in order for the crater stock to not be decimal
KinxpIn is offline   Reply With Quote
Old 21/05/2019, 02:43 PM   #8
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 460
Reputation: 100
Default Re: How to grouping? 10 pcs equals 1 box

You could do something like:

pawn Code:
new x = 20;
new y = 10;
printf("%d", roundUpwards(float(x) / float(y)) );

roundUpwards(Float:value)
{
    new n;

    if(0 > n < 1) n = 1;
    else n = floatround(value, floatround_ceil);

    return n;
}

This will always round upwards, so if you have like 1 carrot it will be 1 crate and if you have 11 carrots then it will be 2 crates
Macronix is offline   Reply With Quote
Old 21/05/2019, 09:22 PM   #9
KinxpIn
Little Clucker
 
Join Date: Dec 2018
Posts: 26
Reputation: 0
Default Re: How to grouping? 10 pcs equals 1 box

Ohhhh.... that's very useful... Thank you guys for the solution
KinxpIn 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field equals null nezo2001 Scripting Help 3 14/09/2015 09:07 PM
equals to or less than or what? xXitsgodzillaXx Scripting Help 3 10/07/2013 02:10 PM
How do I check if a string Equals a certain word? ViperSniper Help Archive 5 19/01/2011 05:35 PM
[QUESTION] How do I check if one string equals to another one? borisblat Help Archive 14 20/03/2010 08:43 PM
if strlen equals AdminPW. shitbird Help Archive 4 30/05/2009 07:43 PM


All times are GMT. The time now is 02:32 AM.


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