Help In Exp System
#1

This Codes in my Gamemode
PHP код:
new old_Exp[MAX_PLAYERS];
new 
new_Exp[MAX_PLAYERS];
public 
OnGameModeExit()
{
    for(new 
playerid 0playerid MAX_PLAYERSplayerid++)
    {
        
TextDrawHideForAll(Rank[playerid]);
        
TextDrawDestroy(Rank[playerid]);
         
TextDrawHideForAll(Exp[playerid]);
    
TextDrawDestroy(Exp[playerid]);
    }
return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
new_Exp[playerid] = 0;
    
old_Exp[playerid] = 120;
    new 
temp_str[10];
    
strcat(new_string "Exp:");
    
valstr(temp_str ,new_Exp[playerid]);
    
strcat(new_string ,temp_str[playerid]);
    
strcat(new_string "/");
    
valstr(temp_str ,old_Exp[playerid]);
    
strcat(new_string ,temp_str[playerid]);
    
Exp[playerid] = TextDrawCreate(484.00000098.559997,new_string);
    
TextDrawLetterSize(Exp[playerid], 0.3459981.413333);
    
TextDrawAlignment(Exp[playerid], 1);
    
TextDrawColor(Exp[playerid], -2139094785);
    
TextDrawSetShadow(Exp[playerid], 0);
    
TextDrawSetOutline(Exp[playerid], 1);
    
TextDrawBackgroundColor(Exp[playerid], 51);
    
TextDrawFont(Exp[playerid], 1);
    
TextDrawSetProportional(Exp[playerid], 1);
    
Rank[playerid] = TextDrawCreate(483.999877113.493309"Level: 0 Rank: Beginner");
    
TextDrawLetterSize(Rank[playerid], 0.3539991.450666);
    
TextDrawAlignment(Rank[playerid], 1);
    
TextDrawColor(Rank[playerid], -2139094785);
    
TextDrawSetShadow(Rank[playerid], 0);
    
TextDrawSetOutline(Rank[playerid], 1);
    
TextDrawBackgroundColor(Rank[playerid], 51);
    
TextDrawFont(Rank[playerid], 1);
    
TextDrawSetProportional(Rank[playerid], 1);
    
ExpFNL[playerid] = TextDrawCreate(472.000000126.186546"Exp For Next Level: 120");
    
TextDrawLetterSize(ExpFNL[playerid], 0.3739991.383466);
    
TextDrawAlignment(ExpFNL[playerid], 1);
    
TextDrawColor(ExpFNL[playerid], -2139094785);
    
TextDrawSetShadow(ExpFNL[playerid], 0);
    
TextDrawSetOutline(ExpFNL[playerid], 1);
    
TextDrawBackgroundColor(ExpFNL[playerid], 51);
    
TextDrawFont(ExpFNL[playerid], 1);
    
TextDrawSetProportional(ExpFNL[playerid], 1);
     
TextDrawShowForPlayer(playeridExp[playerid]);
      
TextDrawShowForPlayer(playeridRank[playerid]);
       
TextDrawShowForPlayer(playeridExpFNL[playerid]);
        return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid != INVALID_PLAYER_ID)
    {
        
SendDeathMessage(killeridplayeridreason);
    
GivePlayerMoney(playerid,-GetPlayerMoney(playerid)/2);
    
PlayerInfo[killerid][pKills] += 1;
    
PlayerInfo[killerid][pScore] += 1;
    
SetPlayerScore(killeridPlayerInfo[killerid][pScore]);
    new 
temp_str[10];
    
new_Exp[killerid] = new_Exp[killerid] + 90;
    
new_Exp[playerid] = new_Exp[playerid] - 90;
      if(
new_Exp[playerid] < 0)
    {
        
new_Exp[playerid] = 0;
      }
    if(
new_Exp[killerid] >= 120)
    {
           
old_Exp[killerid] = 380;
         
SendClientMessage(killerid,COLOR_YELLOW,"New Level");
      }
    
new_string "";
    
strcat(new_string "Exp:");
    
valstr(temp_str ,new_Exp[killerid]);
    
strcat(new_string ,temp_str);
    
strcat(new_string "/");
    
valstr(temp_str ,old_Exp[playerid]);
    
strcat(new_string ,temp_str);
    
TextDrawSetString(Exp[killerid], new_string);
    
TextDrawShowForPlayer(killeridExp[killerid]);
    
new_string "";
    
strcat(new_string "Exp:");
    
valstr(temp_str ,new_Exp[playerid]);
    
strcat(new_string ,temp_str);
    
strcat(new_string "/");
    
valstr(temp_str ,old_Exp[playerid]);
    
strcat(new_string ,temp_str);
    
TextDrawSetString(Exp[playerid], new_string);
    
TextDrawShowForPlayer(playeridExp[playerid]);
    }
    return 
1;

please help me what's Wrong i don't know why this have bugs and dos'nt work
Reply
#2

"new_string" should be indexed on it's declaration. You haven't mentioned the bug, so do explain the bug.
(NVM : Seems like 'new_string' is a global variable..)
Reply
#3

i can run the server and give you ip now for you Check it yor self if you want
Reply
#4

I edited my first post, you might want to check that out. What makes you unable to explain the bug? I can't connect to your SA-MP server right now. If you're not willing to explain the bug, wait for someone to connect to your server and solve.
Reply
#5

problem is Not Simple you if you kill One player Sometimes The first line Change to ALAM Sometimes Changes to
0/120 0/120
!
Reply
#6

i runned the server and i'm there if you want help join and kill me check this bug 151.246.24.31
Reply
#7

Please Someone give me a true Code
Reply
#8

Are you using NPCs? I don't know why, but NPCs always bug strings (atleast for me).

Use "format" instead "strcat".
Reply
#9

NPC is Include? no just i used this includes #include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
#include <sscanf2>
#include <AWC>
#include <mSelection>
#include <create_veh>
#include <moneyhax>
#include <foreach>


#include <mxINI>
Reply
#10

PHP код:
new old_Exp[MAX_PLAYERS];
new 
new_Exp[MAX_PLAYERS];
public 
OnGameModeExit()
{
    for(new 
playerid 0playerid MAX_PLAYERSplayerid++)
    {
        
TextDrawHideForAll(Rank[playerid]);
        
TextDrawDestroy(Rank[playerid]);
        
TextDrawHideForAll(Exp[playerid]);
        
TextDrawDestroy(Exp[playerid]);
    }
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
/* I declare new_string just in case of you don't have it. */
    
new new_string[15];
    
    
new_Exp[playerid] = 0;
    
old_Exp[playerid] = 120;
    
    
/* You don't have to convert integers to strings in this case, you can use format instead and the %d specifier. */
    
format(new_stringsizeof(new_string), "Exp: %d/%d"new_Exp[playerid], old_Exp[playerid]);
    
Exp[playerid] = TextDrawCreate(484.00000098.559997new_string);
    
TextDrawLetterSize(Exp[playerid], 0.3459981.413333);
    
TextDrawAlignment(Exp[playerid], 1);
    
TextDrawColor(Exp[playerid], -2139094785);
    
TextDrawSetShadow(Exp[playerid], 0);
    
TextDrawSetOutline(Exp[playerid], 1);
    
TextDrawBackgroundColor(Exp[playerid], 51);
    
TextDrawFont(Exp[playerid], 1);
    
TextDrawSetProportional(Exp[playerid], 1);
    
Rank[playerid] = TextDrawCreate(483.999877113.493309"Level: 0 Rank: Beginner");
    
TextDrawLetterSize(Rank[playerid], 0.3539991.450666);
    
TextDrawAlignment(Rank[playerid], 1);
    
TextDrawColor(Rank[playerid], -2139094785);
    
TextDrawSetShadow(Rank[playerid], 0);
    
TextDrawSetOutline(Rank[playerid], 1);
    
TextDrawBackgroundColor(Rank[playerid], 51);
    
TextDrawFont(Rank[playerid], 1);
    
TextDrawSetProportional(Rank[playerid], 1);
    
ExpFNL[playerid] = TextDrawCreate(472.000000126.186546"Exp For Next Level: 120");
    
TextDrawLetterSize(ExpFNL[playerid], 0.3739991.383466);
    
TextDrawAlignment(ExpFNL[playerid], 1);
    
TextDrawColor(ExpFNL[playerid], -2139094785);
    
TextDrawSetShadow(ExpFNL[playerid], 0);
    
TextDrawSetOutline(ExpFNL[playerid], 1);
    
TextDrawBackgroundColor(ExpFNL[playerid], 51);
    
TextDrawFont(ExpFNL[playerid], 1);
    
TextDrawSetProportional(ExpFNL[playerid], 1);
    
TextDrawShowForPlayer(playeridExp[playerid]);
    
TextDrawShowForPlayer(playeridRank[playerid]);
    
TextDrawShowForPlayer(playeridExpFNL[playerid]);
     return 
1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid != INVALID_PLAYER_ID)
    {
        
SendDeathMessage(killeridplayeridreason);
        
GivePlayerMoney(playerid, -GetPlayerMoney(playerid)/2);
        
PlayerInfo[killerid][pKills]++;
        
PlayerInfo[killerid][pScore]++;
        
SetPlayerScore(killeridPlayerInfo[killerid][pScore]);
        
new_Exp[killerid] += 90;
        
new_Exp[playerid] -= 90;
          if(
new_Exp[playerid] < 0)
        {
            
new_Exp[playerid] = 0;
          }
          
        if(
new_Exp[killerid] >= 120)
        {
            
old_Exp[killerid] += 380// You missed the + to increase its value, I guess it should be += 120 actually.
             
SendClientMessage(killerid,COLOR_YELLOW,"New Level");
          }
          
        
/* I declare new_string just in case of you don't have it. */
        
new new_string[15];
    
        
format(new_stringsizeof(new_string), "Exp: %d/%d"new_Exp[killerid], old_Exp[killer]);
        
        
TextDrawSetString(Exp[killerid], new_string);
        
TextDrawShowForPlayer(killeridExp[killerid]);
        
format(new_stringsizeof(new_string), "Exp: %d/%d"new_Exp[playerid], old_Exp[playerid]);
        
TextDrawSetString(Exp[playerid], new_string);
        
TextDrawShowForPlayer(playeridExp[playerid]);
    }
    return 
1;

I found many errors there, I added a comment where I could. You should move to PlayerTextdraws by the way.

Stop using ambiguous variable names.
PHP код:
new new_string[10]; // This hurts my eyes.
/* You should use something like: */
new p_CurrentExp[MAX_PLAYERS];
new 
p_OldExp[MAX_PLAYERS];
new 
exp_string[15]; 
It's up to you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)