Death value for users stuck on "1".
#1

Hello,

So i added a line to my users folder for the amount of death and kills they rack up :

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	/////// KILL AND DEATH SYSTEM.
	
	new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
	GetPlayerName(playerid, n, sizeof(n));
	GetPlayerName(killerid, on, sizeof(on));
	format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
	format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
	if(dini_Exists(file))
	    {
		 dini_IntSet(file,"Deaths", PInfo[playerid][Deaths] + 1 );
         return 1;
		}
	if(dini_Exists(file2))
	    {
         dini_IntSet(file2,"Kills", PInfo[playerid][Kills] + 1 );
         return 1;
		}
	        
	        
	return 1;
}
However, when i look into my own user file in scripfile after having /die myself and jump off buildings numerous times my " Death " value is stuck on 1 even though i killed myself in all the way possible.

Hope someone can find me find the issue at hand.
Cheers.
Reply
#2

That's because you just save the value in the ini file, you're not actually increasing the working variable! Instead, do
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.
   
    PInfo[killerid][Kills]++; //Increase the killcount with 1 for the killer
    PInfo[playerid][Deaths]++; //Increase the death count with 1 for the one who died
    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    GetPlayerName(playerid, n, sizeof(n));
    GetPlayerName(killerid, on, sizeof(on));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
    if(dini_Exists(file))
    {
     dini_IntSet(file,"Deaths", PInfo[playerid][Deaths]); //Use the changed variable here to save the data, no need to do +1 here or anything, because we did it in the beginning of the function
    }
    if(dini_Exists(file2))
    {
     dini_IntSet(file2,"Kills", PInfo[killerid][Kills]); //Same as the above.
    }
           
           
    return 1;
}
Note, that you used 'playerid' for the variables that should have been assigned to the killerid. I changed them for you, but be sure to keep an eye on that as it will cause trouble in the future.
Reply
#3

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.

    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    GetPlayerName(playerid, n, sizeof(n));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    if(dini_Exists(file))
        {
         dini_IntSet(file,"Deaths", PInfo[playerid][Deaths] + 1 );
         return 1;
        }
    if (killerid != INVALID_PLAYER_ID)
    {
    GetPlayerName(killerid, on, sizeof(on));
    format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
    if(dini_Exists(file2))
        {
         dini_IntSet(file2,"Kills", PInfo[playerid][Kills] + 1 );
         return 1;
        }
    }


    return 1;
}
try this,"if (killerid != INVALID_PLAYER_ID)" that's the problem I think, I had this problem once
Also use Jstylezzz method, he's right but don't forget to do as I told you, this might be the problem
---------------------
The final code should be like that:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.

    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    PInfo[playerid][Deaths]++;
    GetPlayerName(playerid, n, sizeof(n));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    if(dini_Exists(file))
        {
         dini_IntSet(file,"Deaths", PInfo[playerid][Deaths] );
         return 1;
        }
    if (killerid != INVALID_PLAYER_ID)
    {
    PInfo[playerid][Kills]++;
    GetPlayerName(killerid, on, sizeof(on));
    format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
    if(dini_Exists(file2))
        {
         dini_IntSet(file2,"Kills", PInfo[killerid][Kills] ); //Edit: this is so important , thanks to Jstylezzz, I didn't notice it to be honest.. killerid instead of playerid
         return 1;
        }
    }


    return 1;

}
Reply
#4

Quote:
Originally Posted by Sarra
Посмотреть сообщение
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.

    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    GetPlayerName(playerid, n, sizeof(n));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    if(dini_Exists(file))
        {
         dini_IntSet(file,"Deaths", PInfo[playerid][Deaths] + 1 );
         return 1;
        }
    if (killerid != INVALID_PLAYER_ID)
    {
    GetPlayerName(killerid, on, sizeof(on));
    format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
    if(dini_Exists(file2))
        {
         dini_IntSet(file2,"Kills", PInfo[playerid][Kills] + 1 );
         return 1;
        }
    }


    return 1;
}
try this,"if (killerid != INVALID_PLAYER_ID)" that's the problem I think, I had this problem once
Also use Jstylezzz method, he's right but don't forget to do as I told you, this might be the problem
In your code it still doesn't increase the variables. It just creates a calculation, but doesn't increase the actual values that he uses in the script.
Rest of it was good though, it's good to check for invalid killerid to prevent unwanted behaviour. Updated code would be
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.

    PInfo[playerid][Deaths]++;
    PInfo[killerid][Kills]++;
    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    GetPlayerName(playerid, n, sizeof(n));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    if(dini_Exists(file))
    {
        dini_IntSet(file,"Deaths", PInfo[playerid][Deaths]);
    }
    if (killerid != INVALID_PLAYER_ID)
    {
        GetPlayerName(killerid, on, sizeof(on));
        format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
        if(dini_Exists(file2))
        {
            dini_IntSet(file2,"Kills", PInfo[killerid][Kills]);
        }
    }


    return 1;
}
And again, just to be sure you get it, the 'kills' variable should be increased and used for the killerid, not for the playerid. That's why instead of [playerid] it is [killerid].

EDIT: Exactly, your updated code is good. However, it still adds a kill to the playerid, which it should not. Kills are added for the killerid, and not the playerid.
EDIT2: I did notice your reply, hence my first edit
Reply
#5

Quote:
Originally Posted by Jstylezzz
Посмотреть сообщение
In your code it still doesn't increase the variables. It just creates a calculation, but doesn't increase the actual values that he uses in the script.
Rest of it was good though, it's good to check for invalid killerid to prevent unwanted behaviour. Updated code would be
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.

    PInfo[playerid][Deaths]++;
    PInfo[killerid][Kills]++;
    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    GetPlayerName(playerid, n, sizeof(n));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    if(dini_Exists(file))
    {
        dini_IntSet(file,"Deaths", PInfo[playerid][Deaths]);
    }
    if (killerid != INVALID_PLAYER_ID)
    {
        GetPlayerName(killerid, on, sizeof(on));
        format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
        if(dini_Exists(file2))
        {
            dini_IntSet(file2,"Kills", PInfo[killerid][Kills]);
        }
    }


    return 1;
}
And again, just to be sure you get it, the 'kills' variable should be increased for the killerid, not for the playerid. That's why instead of [playerid] it is [killerid].

EDIT: Exactly, your updated code is good. However, it still adds a kill to the playerid, which it should not. Kills are added for the killerid, and not the playerid.
If you read my edit :P I fixed it before your reply,
thanks ,
and sorry didn't notice the killerid/playerid thing
Reply
#6

Thank you for the help. Testing it as we speak...
Reply
#7

Quote:
Originally Posted by Jstylezzz
Посмотреть сообщение
That's because you just save the value in the ini file, you're not actually increasing the working variable! Instead, do
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    /////// KILL AND DEATH SYSTEM.
   
    PInfo[killerid][Kills]++; //Increase the killcount with 1 for the killer
    PInfo[playerid][Deaths]++; //Increase the death count with 1 for the one who died
    new n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME], file[256], file2[256];
    GetPlayerName(playerid, n, sizeof(n));
    GetPlayerName(killerid, on, sizeof(on));
    format (file, sizeof(file), "MyAdmin/Users/%s.txt",n);
    format (file2, sizeof(file2), "MyAdmin/Users/%s.txt", on);
    if(dini_Exists(file))
    {
     dini_IntSet(file,"Deaths", PInfo[playerid][Deaths]); //Use the changed variable here to save the data, no need to do +1 here or anything, because we did it in the beginning of the function
    }
    if(dini_Exists(file2))
    {
     dini_IntSet(file2,"Kills", PInfo[killerid][Kills]); //Same as the above.
    }
           
           
    return 1;
}
Note, that you used 'playerid' for the variables that should have been assigned to the killerid. I changed them for you, but be sure to keep an eye on that as it will cause trouble in the future.
Success 👌👌Just 1 thing, why was my code not elevating the kills/deaths valu even though I had :
PInfo [playerid][Deaths] + 1;
? Thanks
Reply
#8

That's because 'somevar+1' on itself is a calculation. If you save something like that, it will take the existing value of 'somevar', and add one to it while saving. It won't alter the original value (in this example 'somevar'). It will only alter the variable if you set it to a different value, which is done by for example 'somevar = x' (<- set the variable to x), 'somevar -= x' (<- subtract 'x' from the variable) or 'somevar += x' (<- add x tot the variable) or 'somevar++' (<- add 1 to the variable) or 'somevar--' (<- subtract 1 from the variable).
Reply
#9

Quote:
Originally Posted by Lofti
Посмотреть сообщение
Success 👌👌Just 1 thing, why was my code not elevating the kills/deaths valu even though I had :
PInfo [playerid][Deaths] + 1;
? Thanks
I replied your pm about that , he explained it also
Reply
#10

Quote:
Originally Posted by Jstylezzz
Посмотреть сообщение
That's because 'somevar+1' on itself is a calculation. If you save something like that, it will take the existing value of 'somevar', and add one to it while saving. It won't alter the original value (in this example 'somevar'). It will only alter the variable if you set it to a different value, which is done by for example 'somevar = x' (<- set the variable to x), 'somevar -= x' (<- subtract 'x' from the variable) or 'somevar += x' (<- add x tot the variable) or 'somevar++' (<- add 1 to the variable) or 'somevar--' (<- subtract 1 from the variable).
Theres one more issue, all stats save when the player dies, leaves etc however once I restart the server and login my deaths and kills count are back to 0 but my level is always the same and doesnt. The issue only seems to be with the death and kills count. Shall I share my filterscript?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)