Make a total
#1

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?
Reply
#2

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;

Reply
#3

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

Reply
#4

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.
Reply
#5

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.
Reply
#6

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
Reply
#7

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...)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)