SA-MP Forums Archive
Make a total - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Make a total (/showthread.php?tid=657814)



Make a total - KinderClans - 15.08.2018

So, assuming i have:

Player[playerid][MarijuanaGrams] = 30 and Player[playerid][CocaineGrams] = 20

Is possible to do the total and show like: You have a total of 50 grams.

How?


Re: Make a total - brauf - 15.08.2018

Took me a while to figure out but...

PHP Code:
new TotalDrugs[MAX_PLAYERS];
CMD:drugs(playeridparams[])
{
   
    
TotalDrugs[playerid] = Player[playerid][MarijuanaGrams] + Player[playerid][CocaineGrams];
    
printf("total drugs %i"TotalDrugs[playerid]);
    return 
1;




Re: Make a total - iLearner - 15.08.2018

Quote:
Originally Posted by brauf
View Post
Took me a while to figure out but...

PHP Code:
new TotalDrugs[MAX_PLAYERS];
CMD:drugs(playeridparams[])
{
   
    
TotalDrugs[playerid] = Player[playerid][MarijuanaGrams] + Player[playerid][CocaineGrams];
    
printf("total drugs %i"TotalDrugs[playerid]);
    return 
1;


PHP Code:
CMD:drugs(playerid

    
printf("total drugs %i",(Player[playerid][MarijuanaGrams] + Player[playerid][CocaineGrams])); 
    return 
1




Re: Make a total - BornHuman - 15.08.2018

Quote:
Originally Posted by brauf
View Post
Took me a while to figure out but...

PHP Code:
new TotalDrugs[MAX_PLAYERS];
CMD:drugs(playeridparams[])
{
   
    
TotalDrugs[playerid] = Player[playerid][MarijuanaGrams] + Player[playerid][CocaineGrams];
    
printf("total drugs %i"TotalDrugs[playerid]);
    return 
1;

I wouldn't use a global variable, define it locally unless you're using it in multiple places.


Re: Make a total - brauf - 15.08.2018

Quote:
Originally Posted by iLearner
View Post

PHP Code:
CMD:drugs(playerid

    
printf("total drugs %i",(Player[playerid][MarijuanaGrams] + Player[playerid][CocaineGrams])); 
    return 
1

What if he wanted to use this elsewhere in the script, it would be much easier to make the calculation in that global variable.
I'm sorry if that meer 20-50ms wasted your valuable time when typing in the command waiting for a output.


Re: Make a total - BornHuman - 15.08.2018

Quote:
Originally Posted by brauf
View Post
What if he wanted to use this elsewhere in the script, it would be much easier to make the calculation in that global variable.
I'm sorry if that meer 20-50ms wasted your valuable time when typing in the command waiting for a output.
its called efficiency. every coder should practice efficiency. when you're teaching someone who is obviously new to coding something, you should teach them efficiency. one variable wouldn't kill you but its this way of thinking that makes you end up like ng:rp's script where very variable bugs out cause theres too fucking many


Re: Make a total - iLearner - 15.08.2018

Quote:
Originally Posted by brauf
View Post
What if he wanted to use this elsewhere in the script, it would be much easier to make the calculation in that global variable.
I'm sorry if that meer 20-50ms wasted your valuable time when typing in the command waiting for a output.
You do know the difference between global variables and locals right? Why would you create a global variable to contain a sum of 2 global variables (and just think… those variables change...)