Jump to content
  • 0
Tio Akima

variable to store points

Question

Hi guys
I'm creating a system to store points for each Char.
(These points I will use in the future in the damage equation)

I'm having trouble making this variable store the points by char.
I believe my logic is wrong
Or I must be forgetting some detail.

I added with sd member

 int training_point; 


in pc.c (in pc_reg_received):
 

sd->training_point = pc_readglobalreg(sd,script->add_variable("TRAINING_POINT")); 

E também

else if( !strcmp(regname,"TRAINING_POINT") && sd->training_point != val ) { 
                val = cap_value(val, 0, battle_config->training_point); 
                sd->training_point = val;
            }

following the example of die_count
I also added a config in player.conf

// Number of training points that the player can accumulate
// Default: 200 | Max: 500
training_point: 200

and add in battle.c (h)

    { "training_point",                     &battle_config.training_point,                  200,      0,      255,           },


Then I created a command called @Training
to be able to add points per command

Spoiler

 


 ACMD(training)
 {
    int pontos = 0;
    int resultado = 0;
    
    pontos = sscanf(message, "%12d", &pontos);

    if (*message == '\0') { // No message, just show the list

        clif->message(fd, "please add a value"); 
        return false;
        
    } 
    

    if (pontos > 0) {
        if (pontos >= battle_config.training_point ) { 
            clif->message(fd, "The number of points can not be so high"); 
            return false;
        } // End Addition
        
        sd->training_point += pontos;
        clif->message(fd, "points acquired"); 
        
    } else {
        if (pontos == 0) {
            clif->message(fd, "POnts can not be zero"); 
            return false;
        }
        
        pontos*=-1;    
                
        sd->training_point -= pontos;
        clif->message(fd, "points removed"); 
        
    }
    
    resultado = sd->training_point;
    clif->message( fd, resultado + "/200"); // message - show points


    return true;
}

 

 

And in the end, when I add the points, it shows how many points you have
Then, when doing a quest, I would use the command to add pro player points.
But apparently the logic is all wrong.
the structure is apparently not right.


Each player must have their points, and using the command I should add or subtract points.
What am I doing wrong?

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

When you change the value on source, you have to update your registry instead of the sd-> variable.

Example:

pc_setglobalreg(sd,script->add_variable("TRAINING_POINT"), sd->training_point + pontos);

This would update both the script var and your sd-> data.

Also, your atcommand has some issues:

1. sscanf

pontos = sscanf(message, "%12d", &pontos);

// should be
sscanf(message, "%12d", &pontos);

because sscanf will set values from string in the pointers passed by parameter. sscanf return is actually how many of these variables were filled (in this case it would always set "pontos" to 1 if you gave one number in the command). (Reference: http://www.cplusplus.com/reference/cstdio/sscanf/ )

2. 
 

clif->message( fd, resultado + "/200"); // message - show points

C doesn't let you concat strings like that. You would need to use something like sprintf (Reference: http://www.cplusplus.com/reference/cstdio/sprintf/ ) to make a string to hold your value. Take a look on costume atcommand, it uses a safe version of sprintf. Something like: (untested)

	// Where your str will be stored
	char buffer [50];
	
	// writes into buffer a string in the format %d/200, where %d is the value of "resultado"
	sprintf (buffer, "%d/200", resultado); 

	// sends string to client
	clif->message(fd, buffer);

-------

If you fix the pc_setregistry you'll be able to use your TRAINING_POINT in scripts like:

prontera,150,150,4	script	TestGet	1_M_01,{
	mes "Hi";
	mes "> " + TRAINING_POINT;
	close;
}

prontera,150,152,4	script	TestSet	1_M_01,{
	mes "Hi";
	TRAINING_POINT++;
	close;
}

 

Edited by KirieZ

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.