View Single Post
JPTRON
Junior Member
Join Date: Jun 2020
Old 06-07-2020 , 01:53   Re: WriteFileLine - Exception reported: invalid handle 0 (error: 4)
Reply With Quote #7

Quote:
Originally Posted by DJ Tsunami View Post
This system with files is going to be a mess, you should use Client Preferences to store client information across connections.
Thank you very much dude!! I didn't think about using cookies... So, again, I changed my code to this and it's working:

PHP Code:
Handle g_hPointCookie;
int messagePoints;

public 
void OnPluginStart()
{
    
HookEvent("player_death"Event_PlayerDeath);
    
g_hPointCookie RegClientCookie("give_points""Give Points"CookieAccess_Protected);
}


public 
Action Event_PlayerDeath(Event event, const char[] namebool dontBroadcast) {

    
int victim GetClientOfUserId(event.GetInt("userid"));
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    
int assist GetClientOfUserId(event.GetInt("assister"));
    
char victimName[40], attackerName[40], assistName[40];
    
    
GetClientName(victimvictimNamesizeof(victimName));
    
GetClientName(attackerattackerNamesizeof(attackerName));
    
GetClientName(assistassistNamesizeof(assistName));
    
  
    if(
victim == attacker || attacker == 0){    
          return;
      }
    
    
GivePoints(attacker10);

    
PrintToChatAll("%s killed %s | Points: %i"attackerNamevictimNamemessagePoints);

    if(
assist){
        
GivePoints(assist2);
         
PrintToChatAll("%s helped killing %s | Points: %i"assistNamevictimNamemessagePoints);
    }    
}

public 
void GivePoints(int targetIDint points) {
    
    if (
AreClientCookiesCached(targetID))
    {
    
        
char sCookieValue[12];
        
GetClientCookie(targetIDg_hPointCookiesCookieValuesizeof(sCookieValue));
        
int Points StringToInt(sCookieValue);
        
Points += points;
        
         
messagePoints Points;
 
        
IntToString(PointssCookieValuesizeof(sCookieValue));
 
        
SetClientCookie(targetIDg_hPointCookiesCookieValue);
    }

Love you guys ;)
JPTRON is offline