/stats command
#1

I've made a simple stats command it all seems to work fine but kills,deaths wont add ?

Код:
CMD:stats(playerid, params[])
{
  if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
  new string[500],name[MAX_PLAYER_NAME], stats[1028];
  GetPlayerName(playerid, name, sizeof(name));
  format(string, sizeof(string), "{4286f4}Name{FFFFFF}: %s\n{4286f4}Admin Level{FFFFFF}: %i\n{4286f4}Score{FFFFFF}: %i\n{4286f4}Kills{FFFFFF}: %i\n{4286f4}Deaths{FFFFFF}: %i\n{4286f4}Points{FFFFFF}: %i",name, pInfo[playerid][Admin],  pInfo[playerid][Score], pInfo[playerid][Kills], pInfo[playerid][Deaths],  pInfo[playerid][Points]);
  format(stats, sizeof stats, "%s", string);
  ShowPlayerDialog(playerid, 55, DIALOG_STYLE_MSGBOX, "Stats",stats,"Ok","");
  return 1;
}
Reply
#2

Something like this will set them to count up

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
pInfo[killerid][Kills] += 1;
pInfo[playerid][Deaths]  += 1;
return 
1;

Reply
#3

same.
Reply
#4

Quote:
Originally Posted by ivndosos
Посмотреть сообщение
same.
This will work 100%.
Reply
#5

nope it doesnt^^
Reply
#6

Quote:
Originally Posted by ivndosos
Посмотреть сообщение
nope it doesnt^^
Then you have done something wrong. Show your onplayerdeath
Reply
#7

Here's the original code

Код:
public OnPlayerDeath(playerid,killerid,reason)
{
    // sending the death message icon
	if(IsPlayerConnected(killerid)) SendDeathMessage(killerid, playerid, reason);
	
	// Getting the player's Health pickup
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid,x,y,z);
	Health[playerid] = CreatePickup(1240,4,x,y,z+0.2,GetPlayerVirtualWorld(playerid));
	SetTimerEx("Health_Timer", 15000, false, "i", playerid); // it's to destroy the pickup near the dead player's body if no one will take it. (15 seoncds)
	
	// Kills Deaths & Ratio TD.
	PlayerKills[killerid]++; // Addes a score to player killed.
	PlayerDeaths[playerid]++; // Addes a score to player death.
	new iString[100]; // string cells.
	format(iString, sizeof iString, "Kills: %i", PlayerKills[killerid]); // Here we put the amout of Killed players.
	TextDrawSetString(KILLS[killerid], iString);
	format(iString, sizeof iString, "Deaths: %i", PlayerDeaths[playerid]); // Here we put the amout of Deaths.
	TextDrawSetString(DEATHS[playerid], iString);
	format( iString, sizeof( iString ), "Ratio: %.2f", floatdiv(PlayerKills[playerid], PlayerDeaths[playerid]));
	TextDrawSetString(RATIO[playerid], iString);

	// Killing spree system.
 	PlayerTotalKills[killerid]++;
    PlayerTotalKills[playerid] = 0;

    // Killing Spree on 2 killed players
    if(PlayerTotalKills[killerid] == 2) {
      	new string[128];
      	new name[MAX_PLAYER_NAME];
	    GetPlayerName(killerid, name, sizeof(name));
		format(string, sizeof(string), "{F5A9E1}(SIMPLE!) %s is on a killing spree with 2 killed players! and earns (+5 points, + 10 score +100 respect) !",name);
		SendClientMessageToAll(-1, string);
        format(iString, sizeof iString, "KillingSpree: %d", PlayerTotalKills[killerid]); // TD's format to the actual KillingSpree system.
		TextDrawSetString(KILLINGSPREE[playerid], iString);
		SetPlayerScore(killerid, GetPlayerScore(killerid) + 10);
		pInfo[killerid][Score] += 10;
       	pInfo[killerid][Points] += 5;
       	pInfo[killerid][Respect] += 100;
       	GameTextForPlayer(playerid,"~y~+5", 500,4);
    }
    // Killing Spree on 4 killed players
    if(PlayerTotalKills[killerid] == 4) {
      	new string[128];
      	new name[MAX_PLAYER_NAME];
	    GetPlayerName(killerid, name, sizeof(name));
		format(string, sizeof(string), "{F5A9E1}(AMAZING!) %s is on a killing spree with 2 killed players! and earns (+10 points, + 20 score +200 respect) !",name);
		SendClientMessageToAll(-1, string);
        format(iString, sizeof iString, "KillingSpree: %d", PlayerTotalKills[killerid]); // TD's format to the actual KillingSpree system.
		TextDrawSetString(KILLINGSPREE[playerid], iString);
		SetPlayerScore(killerid, GetPlayerScore(killerid) + 20);
		pInfo[killerid][Score] += 20;
       	pInfo[killerid][Points] += 10;
       	pInfo[killerid][Respect] += 200;
       	GameTextForPlayer(playerid,"~y~+10", 500,4);
    }
    // Killing Spree on 8 killed players
    if(PlayerTotalKills[killerid] == 8) {
      	new string[128];
      	new name[MAX_PLAYER_NAME];
	    GetPlayerName(killerid, name, sizeof(name));
		format(string, sizeof(string), "{F5A9E1}(JACKER!) %s is on a killing spree with 2 killed players! and earns (+15 points, + 30 score +300 respect) !",name);
		SendClientMessageToAll(-1, string);
        format(iString, sizeof iString, "KillingSpree: %i", PlayerTotalKills[killerid]); // TD's format to the actual KillingSpree system.
		TextDrawSetString(KILLINGSPREE[killerid], iString);
		SetPlayerScore(killerid, GetPlayerScore(killerid) + 30);
		pInfo[killerid][Score] += 30;
       	pInfo[killerid][Points] += 15;
       	pInfo[killerid][Respect] += 300;
       	GameTextForPlayer(killerid,"~y~+15", 500,4);
    }
    // Killing Spree on 12 killed players
    if(PlayerTotalKills[killerid] == 12) {
      	new string[128];
      	new name[MAX_PLAYER_NAME];
	    GetPlayerName(killerid, name, sizeof(name));
		format(string, sizeof(string), "{F5A9E1}(WANTED!) %s is on a killing spree with 2 killed players! and earns (+20 points, + 40 score +400 respect) !",name);
		SendClientMessageToAll(-1, string);
        format(iString, sizeof iString, "KillingSpree: %i", PlayerTotalKills[killerid]); // TD's format to the actual KillingSpree system.
		TextDrawSetString(KILLINGSPREE[killerid], iString);
		SetPlayerScore(killerid, GetPlayerScore(killerid) + 40);
		pInfo[killerid][Score] += 40;
       	pInfo[killerid][Points] += 20;
       	pInfo[killerid][Respect] += 400;
       	GameTextForPlayer(killerid,"~y~+20", 500,4);
    }
    
	// If player kills someone he will be awarded with +1 point level and +50 respect
	SendClientMessage(killerid, -1,"{9FF781}* Player killed! and awarded with (+1 point level, +15 score and +50 respect) !");
	SendClientMessage(killerid, -1,"{D8D8D8}(INFO) You earned +50 respect !");
	pInfo[killerid][Points] += 1;
	pInfo[killerid][Respect] += 50;
	SetPlayerScore(killerid, GetPlayerScore(killerid) + 15);
	pInfo[killerid][Score] += 15;
	GameTextForPlayer(killerid,"~y~+15", 400,4);
    
	// If player die he will lose -5 points and -20 respect
	SendClientMessage(playerid, -1,"{FA5858}* You got killed! and suddenly lost (-3 points, -5 score and -20 respect lost) !");
	SendClientMessage(playerid, -1,"{D8D8D8}(INFO) You lost -20 respect !");
    pInfo[playerid][Points] -= 3;
    pInfo[playerid][Respect] += -20;
    SetPlayerScore(playerid, GetPlayerScore(playerid) - 5);
    GameTextForPlayer(playerid,"~r~-5", 400,4);
    pInfo[playerid][Score] -= 5;

    // Saving kills and deaths on player's config file.
	if(killerid != INVALID_PLAYER_ID) // Checking if the killer of the player is valid.
	{
		//Increasing the kills of the killer and the deaths of the player.
	    pInfo[killerid][Kills]++;
	    pInfo[playerid][Deaths]++;
	}
    if(IsBeingSpectated[playerid] == 1)
    {
	   for(new i = 0; i < MAX_PLAYERS; i++)
	   {
		  if(spectarget[i] == playerid)
		  {
		  TogglePlayerSpectating(i, false);
		  }
	   }
    }
    return 1;
}
Reply
#8

PHP код:
CMD:stats(playeridparams[])
{
    if(
connected[playerid] == true) return GameTextForPlayer(playerid"~r~Spawn First"50005);
    new 
string[256], stats[256], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "{4286f4}Name{FFFFFF}: %s\n"name);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Admin Level{FFFFFF}: %i\n"pInfo[playerid][Admin]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Score{FFFFFF}: %i\n"pInfo[playerid][Score]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Kills{FFFFFF}: %i\n"PlayerKills[playerid]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Deaths:{FFFFFF}: %i\n"PlayerDeaths[playerid]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Points:{FFFFFF}: %i\n"pInfo[playerid][Points]);
    
format(statsstring);
    
ShowPlayerDialog(playerid55DIALOG_STYLE_MSGBOX"Stats"stats"Ok""");
    return 
1;

Reply
#9

nope still doesn't add.
Reply
#10

All wrong:

You're using format incorrectly.
Quote:
Originally Posted by willbedie
Посмотреть сообщение
PHP код:
CMD:stats(playeridparams[])
{
    if(
connected[playerid] == true) return GameTextForPlayer(playerid"~r~Spawn First"50005);
    new 
string[256], stats[256], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "{4286f4}Name{FFFFFF}: %s\n"name);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Admin Level{FFFFFF}: %i\n"pInfo[playerid][Admin]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Score{FFFFFF}: %i\n"pInfo[playerid][Score]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Kills{FFFFFF}: %i\n"PlayerKills[playerid]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Deaths:{FFFFFF}: %i\n"PlayerDeaths[playerid]);
    
format(statsstring);
    
format(stringsizeof(string), "{4286f4}Points:{FFFFFF}: %i\n"pInfo[playerid][Points]);
    
format(statsstring);
    
ShowPlayerDialog(playerid55DIALOG_STYLE_MSGBOX"Stats"stats"Ok""");
    return 
1;

OP:

format() the string in a holder then use strcat to concatenate the two. Example:

PHP код:
CMD:wooplayeridparams[] ) {
    new 
szPrimaryStr600 ], szSubStr128 ];
    
formatszSubStrsizeof szSubStr"My player ID is : %i\n"playerid );
    
strcatszPrimaryStrszSubStr );
    return 
1;

In that example, you would show szPrimaryStr as the dialogs text.

Regarding OnPlayerDeath,

you need to add a statement to check if the killerID is not INVALID_PLAYER_ID when it's relevant. i.e:
PHP код:
if( killerid != INVALID_PLAYER_ID ) {
     
gPlayerKillskillerid ] ++; 

If a player suicides, killerID will be 65535 and you'll end up accessing an out of bound index.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)