Raised This Month: $51 Target: $400
 12% 

Sourcemod Time Scripting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
G[o]Q
Member
Join Date: Jan 2010
Location: Poland (Malopolska)
Old 11-02-2015 , 16:45   Sourcemod Time Scripting
Reply With Quote #1

Hi, I'm trying to make plugin which count a player time and give him points for it but my code doesn't work i try to getTime() in client post admin check and in disconect here is my code what I do wrong (log file doesn't work too)

Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0"

new Handle:sm_pgr_time_for_point = INVALID_HANDLE
new Handle:sm_pgr_bonus_flag = INVALID_HANDLE
new Handle:sm_pgr_bonus_rate = INVALID_HANDLE
new Handle:sm_pgr_name_pattern = INVALID_HANDLE

new userPoints[128];
new userRest[128];
new userConnect[128];
new userDisconnect[128];

public Plugin:myinfo = 
{
    name = "Player GameTime Rank",
    author = "G[o]Q",
    description = "Points for played time",
    version = PLUGIN_VERSION,
    url = "amxx.pl"
}


public OnPluginStart(){
    CreateConVar("sm_pgr_version", PLUGIN_VERSION, "Player GameTime Rank Version", FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_NOTIFY | FCVAR_DONTRECORD);
    
    RegConsoleCmd("sm_mypoints", Command_MyPoints, "gets your points for time spend on server")
    
    sm_pgr_time_for_point = CreateConVar("sm_pgr_time_for_point", "1", "Flag to give bonus points", FCVAR_NOTIFY);
    
    sm_pgr_bonus_flag = CreateConVar("sm_pgr_bonus_flag", "c", "Flag to give bonus points", FCVAR_NOTIFY);
    
    sm_pgr_bonus_rate = CreateConVar("sm_pgr_bonus_rate", "2", "Multiplier points for bonus flag", FCVAR_NOTIFY);
    
    sm_pgr_name_pattern = CreateConVar("sm_pgr_name_pattern", "lololo", "Pattern to give points");
    
    LoadTranslations("common.phrases");
    
    AutoExecConfig(true, "plugin.ptt")
}



public OnClientPostAdminCheck(client){
    new String:clientName[128];
    
    if (IsFakeClient(client)){
        return
    }
    
    GetClientName(client, clientName, sizeof(clientName));
    
    if(isClientNameOk(clientName)){
        loadData(client);
    }
}
public OnClientDisconnect(client){
    if (IsFakeClient(client)){
        return
    }
    saveData(client);
}
public isClientNameOk(String:clientName[]){
    decl String:cvar_pattern[3];
    GetConVarString(sm_pgr_name_pattern, cvar_pattern, sizeof(cvar_pattern));
    return StrContains(clientName,cvar_pattern) != -1;
}
public OnClientPutInServer( client){
    LogToFile("loads.txt","uP %d uRest %d uCon %d",userPoints[client],userRest[client],userConnect[client]);
}
public loadData(client){
    new String:clientName[128];
    GetClientName(client, clientName, sizeof(clientName));
    
    userPoints[client] = 123;
    userRest[client] = 321;
    userConnect[client] = GetTime();
    userDisconnect[client] = -1;
    
    LogToFile("load.txt","uP %d uRest %d uCon %d",userPoints[client],userRest[client],userConnect[client]);
}
public saveData(client){
    new String:clientName[128];
    GetClientName(client, clientName, sizeof(clientName));
    
    if(!isClientNameOk(clientName)){
        return;
    }
    
    userDisconnect[client] = GetTime();
    new uPoints = userPoints[client];
    new uTime = userDisconnect[client] - userConnect[client] + userRest[client];
    
    new cvar_points = GetConVarInt(sm_pgr_time_for_point);
    new cvar_rate = GetConVarInt(sm_pgr_bonus_rate);
    
    new points = uTime / cvar_points; 
    
    userRest[client] = points % cvar_points;
    
    LogToFile("save.txt","points %d uPoints %d uDis %d uTime %d uRest %d",points,uPoints,userDisconnect[client],uTime,userRest[client]);
    
    new total = points + uPoints;
    
}
p
public Action:Command_MyPoints(client, args){
    new currentTime = GetTime();
    new uPoints = userPoints[client];
    new uTime = currentTime - userConnect[client] + userRest[client];
    
    new cvar_points = GetConVarInt(sm_pgr_time_for_point);
    new cvar_rate = GetConVarInt(sm_pgr_bonus_rate);
    
    new points = uTime / cvar_points; 
    
    if(has_user_flag(client)){points*= cvar_rate;}
    
    new total = points + uPoints;
    PrintToChat(client,"current Time %d utime %d ",currentTime,uTime);
    
    
    PrintToChat(client, "\x04[PGR]\x01 Posiadasz %d punktów", total)
    PrintToChat(client, "\x04[PGR]\x01 uPoints %d uTime %d cpoints %d cRate %d points %d total %d",uPoints,uTime,cvar_points,cvar_rate,points, total)
    PrintToChat(client, "\x04[PGR]\x01 uConnect %d",userConnect[client]);
    
    return Plugin_Handled;
}
here it's screen after use commands sm_mypoints (time saved after connection is 0 and playing time is <0)

http://images.akamai.steamuserconten...0E68356B71B45/
G[o]Q is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 11-02-2015 , 17:01   Re: Sourcemod Time Scripting
Reply With Quote #2

I'm guessing it's never calling loadData in OnClientPostAdminCheck because your name isn't "lololo" or whatever you set sm_pgr_name_pattern to
Miu is offline
G[o]Q
Member
Join Date: Jan 2010
Location: Poland (Malopolska)
Old 11-02-2015 , 18:58   Re: Sourcemod Time Scripting
Reply With Quote #3

So ok but i change default value of convar for example to "[o]" i compiled plugin but when I change map and check conVar value is still "lololo" why?
G[o]Q is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 11-02-2015 , 19:09   Re: Sourcemod Time Scripting
Reply With Quote #4

the "plugin.ppt" config file that you're executing in OnPluginStart probably still has the other value
Miu is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 11-02-2015 , 19:50   Re: Sourcemod Time Scripting
Reply With Quote #5

headline is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:31.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode