AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   {req}Create Command (https://forums.alliedmods.net/showthread.php?t=310907)

ApoziX 09-25-2018 15:43

{req}Create Command
 
Hello Can Some one create !givept command for me?

The Command Will Give Play Time Points to someone

Here is the script

PHP Code:

#include <sourcemod>

static String:TPPath[PLATFORM_MAX_PATH];
new 
Handle:ClientTimer[32];
static 
Minutes[32];

//INFO
public Plugin:myinfo = {
    
name "HowLong",
    
author "hlsavior",
    
description "How long have you been playing?",
    
url "www.scnggames.com"
};


//ON START
public OnPluginStart()
{
    
CreateDirectory("addons/sourcemod/data/stats"0);
    
BuildPath(Path_SMTPPathsizeof(TPPath), "data/stats/timeplayed.txt");
    
RegConsoleCmd("sm_playedtime"Command_getTime"");
    
RegConsoleCmd("sm_pt"Command_getTime"");
}

//IN SERVER
public OnClientPutInServer(client)
{
    
AltTime(client1);
    
ClientTimer[client] = (CreateTimer(60.0TimerAddclientTIMER_REPEAT))
}

//LEAVE SERVER
public OnClientDisconnect(client)
{
    
CloseHandle(ClientTimer[client]);
    
AltTime(client0)
}

//TIMER
public Action:TimerAdd(Handle:timerany:client)
{
    if(
IsClientConnected(client) && IsClientInGame(client))
    {
        
Minutes[client]++;
    }
}

//COMMAND
public Action:Command_getTime(clientargs)
{
    
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minutes!"Minutes[client])
    return 
Plugin_Handled;
}  

//CHANGE
public AltTime(clientconnection)
{
    new 
Handle:DB CreateKeyValues("TimePlayed");
    
FileToKeyValues(DBTPPath);
    
    new 
String:SID[32];
    
GetClientAuthString(clientSIDsizeof(SID));
    
    if(
connection == 1)
    {
        
//Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            new 
String:name[MAX_NAME_LENGTH], String:temp_name[MAX_NAME_LENGTH];
            
GetClientName(clientnamesizeof(name));
            
            
KvGetString(DB"name"temp_namesizeof(temp_name), "NULL");
            
            
Minutes[client] = KvGetNum(DB"minutes"0);
        
            
KvSetNum(DB"minutes"Minutes[client])
        }
    }else if(
connection == 0)
    {
        
//Not Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            
KvSetNum(DB"minutes"Minutes[client]);
        }
    }
    
    
KvRewind(DB);
    
KeyValuesToFile(DBTPPath);
    
CloseHandle(DB);


Thanks for Helpers +rep

8guawong 09-26-2018 04:45

Re: {req}Create Command
 
why don't you just use https://forums.alliedmods.net/showthread.php?p=1751973

Cruze 09-26-2018 07:48

Re: {req}Create Command
 
PHP Code:

#include <sourcemod>

static String:TPPath[PLATFORM_MAX_PATH];
new 
Handle:ClientTimer[32];
static 
Minutes[32];

//INFO
public Plugin:myinfo = {
    
name "HowLong",
    
author "hlsavior",
    
description "How long have you been playing?",
    
url "www.scnggames.com"
};


//ON START
public OnPluginStart()
{
    
CreateDirectory("addons/sourcemod/data/stats"0);
    
BuildPath(Path_SMTPPathsizeof(TPPath), "data/stats/timeplayed.txt");
    
RegConsoleCmd("sm_playedtime"Command_getTime"");
    
RegConsoleCmd("sm_pt"Command_getTime"");
    
RegAdminCmd("sm_setpt"Command_setTimeADMFLAG_ROOT);
    
RegAdminCmd("sm_setplayedtime"Command_setTimeADMFLAG_ROOT);
}

//IN SERVER
public OnClientPutInServer(client)
{
    
AltTime(client1);
    
ClientTimer[client] = (CreateTimer(60.0TimerAddclientTIMER_REPEAT))
}

//LEAVE SERVER
public OnClientDisconnect(client)
{
    
CloseHandle(ClientTimer[client]);
    
AltTime(client0)
}

//TIMER
public Action:TimerAdd(Handle:timerany:client)
{
    if(
IsClientConnected(client) && IsClientInGame(client))
    {
        
Minutes[client]++;
    }
}

//COMMAND
public Action:Command_getTime(clientargs)
{
    if(
Minutes[client] == || Minutes[client] == -1)
    {
        
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minute!"Minutes[client])
    }
    else
        
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minutes!"Minutes[client])
    return 
Plugin_Handled;
}
public 
Action:Command_setTime(clientargs)
{
    if(!
IsValidClient(client))
    {
        return 
Plugin_Handled;
    }
    if(
args != 2)
    {
        
ReplyToCommand(client"[FZG] Usage: sm_setplayedtime <target> <amount>");
        return 
Plugin_Handled;
    }
    
char target_name[MAX_TARGET_LENGTH], buffer[512];
    
int target_list[MAXPLAYERS], target_countg_GivePlayedTime;
    
bool tn_is_ml;
    
    
GetCmdArg(1buffersizeof(buffer));
    if((
target_count ProcessTargetString(bufferclienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    
GetCmdArg(2buffersizeof(buffer));
    
g_GivePlayedTime StringToInt(buffer);
    for(
int i 0target_counti++)
    {
        
Minutes[target_list[i]] = g_GivePlayedTime;
    }
    if(
tn_is_ml)
    {
        
ReplyToCommand(client"[FZG] %s's playtime set to %d"target_nameg_GivePlayedTime);
    }
    else
    {
        
ReplyToCommand(client"[FZG] %s's playtime set to %d""_s"target_nameg_GivePlayedTime);
    }
    return 
Plugin_Handled;
}
    
//CHANGE
public AltTime(clientconnection)
{
    new 
Handle:DB CreateKeyValues("TimePlayed");
    
FileToKeyValues(DBTPPath);
    
    new 
String:SID[32];
    
GetClientAuthId(clientAuthId_Steam2SIDsizeof(SID));
    
    if(
connection == 1)
    {
        
//Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            new 
String:name[MAX_NAME_LENGTH], String:temp_name[MAX_NAME_LENGTH];
            
GetClientName(clientnamesizeof(name));
            
            
KvGetString(DB"name"temp_namesizeof(temp_name), "NULL");
            
            
Minutes[client] = KvGetNum(DB"minutes"0);
        
            
KvSetNum(DB"minutes"Minutes[client])
        }
    }
    else if(
connection == 0)
    {
        
//Not Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            
KvSetNum(DB"minutes"Minutes[client]);
        }
    }
    
    
KvRewind(DB);
    
KeyValuesToFile(DBTPPath);
    
CloseHandle(DB);
}

bool IsValidClient(clientbool bAllowBots truebool bAllowDead true)
{
    if(!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
    {
        return 
false;
    }
    return 
true;



ApoziX 09-28-2018 19:49

Re: {req}Create Command
 
Quote:

Originally Posted by Cruze (Post 2616830)
PHP Code:

#include <sourcemod>

static String:TPPath[PLATFORM_MAX_PATH];
new 
Handle:ClientTimer[32];
static 
Minutes[32];

//INFO
public Plugin:myinfo = {
    
name "HowLong",
    
author "hlsavior",
    
description "How long have you been playing?",
    
url "www.scnggames.com"
};


//ON START
public OnPluginStart()
{
    
CreateDirectory("addons/sourcemod/data/stats"0);
    
BuildPath(Path_SMTPPathsizeof(TPPath), "data/stats/timeplayed.txt");
    
RegConsoleCmd("sm_playedtime"Command_getTime"");
    
RegConsoleCmd("sm_pt"Command_getTime"");
    
RegAdminCmd("sm_setpt"Command_setTimeADMFLAG_ROOT);
    
RegAdminCmd("sm_setplayedtime"Command_setTimeADMFLAG_ROOT);
}

//IN SERVER
public OnClientPutInServer(client)
{
    
AltTime(client1);
    
ClientTimer[client] = (CreateTimer(60.0TimerAddclientTIMER_REPEAT))
}

//LEAVE SERVER
public OnClientDisconnect(client)
{
    
CloseHandle(ClientTimer[client]);
    
AltTime(client0)
}

//TIMER
public Action:TimerAdd(Handle:timerany:client)
{
    if(
IsClientConnected(client) && IsClientInGame(client))
    {
        
Minutes[client]++;
    }
}

//COMMAND
public Action:Command_getTime(clientargs)
{
    if(
Minutes[client] == || Minutes[client] == -1)
    {
        
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minute!"Minutes[client])
    }
    else
        
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minutes!"Minutes[client])
    return 
Plugin_Handled;
}
public 
Action:Command_setTime(clientargs)
{
    if(!
IsValidClient(client))
    {
        return 
Plugin_Handled;
    }
    if(
args != 2)
    {
        
ReplyToCommand(client"[FZG] Usage: sm_setplayedtime <target> <amount>");
        return 
Plugin_Handled;
    }
    
char target_name[MAX_TARGET_LENGTH], buffer[512];
    
int target_list[MAXPLAYERS], target_countg_GivePlayedTime;
    
bool tn_is_ml;
    
    
GetCmdArg(1buffersizeof(buffer));
    if((
target_count ProcessTargetString(bufferclienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    
GetCmdArg(2buffersizeof(buffer));
    
g_GivePlayedTime StringToInt(buffer);
    for(
int i 0target_counti++)
    {
        
Minutes[target_list[i]] = g_GivePlayedTime;
    }
    if(
tn_is_ml)
    {
        
ReplyToCommand(client"[FZG] %s's playtime set to %d"target_nameg_GivePlayedTime);
    }
    else
    {
        
ReplyToCommand(client"[FZG] %s's playtime set to %d""_s"target_nameg_GivePlayedTime);
    }
    return 
Plugin_Handled;
}
    
//CHANGE
public AltTime(clientconnection)
{
    new 
Handle:DB CreateKeyValues("TimePlayed");
    
FileToKeyValues(DBTPPath);
    
    new 
String:SID[32];
    
GetClientAuthId(clientAuthId_Steam2SIDsizeof(SID));
    
    if(
connection == 1)
    {
        
//Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            new 
String:name[MAX_NAME_LENGTH], String:temp_name[MAX_NAME_LENGTH];
            
GetClientName(clientnamesizeof(name));
            
            
KvGetString(DB"name"temp_namesizeof(temp_name), "NULL");
            
            
Minutes[client] = KvGetNum(DB"minutes"0);
        
            
KvSetNum(DB"minutes"Minutes[client])
        }
    }
    else if(
connection == 0)
    {
        
//Not Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            
KvSetNum(DB"minutes"Minutes[client]);
        }
    }
    
    
KvRewind(DB);
    
KeyValuesToFile(DBTPPath);
    
CloseHandle(DB);
}

bool IsValidClient(clientbool bAllowBots truebool bAllowDead true)
{
    if(!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
    {
        return 
false;
    }
    return 
true;



Thank you very much bro +rep but i wanted to players can give other players points from their points

Thank you

ApoziX 09-28-2018 19:55

Re: {req}Create Command
 
Quote:

Originally Posted by Cruze (Post 2616830)
PHP Code:

#include <sourcemod>

static String:TPPath[PLATFORM_MAX_PATH];
new 
Handle:ClientTimer[32];
static 
Minutes[32];

//INFO
public Plugin:myinfo = {
    
name "HowLong",
    
author "hlsavior",
    
description "How long have you been playing?",
    
url "www.scnggames.com"
};


//ON START
public OnPluginStart()
{
    
CreateDirectory("addons/sourcemod/data/stats"0);
    
BuildPath(Path_SMTPPathsizeof(TPPath), "data/stats/timeplayed.txt");
    
RegConsoleCmd("sm_playedtime"Command_getTime"");
    
RegConsoleCmd("sm_pt"Command_getTime"");
    
RegAdminCmd("sm_setpt"Command_setTimeADMFLAG_ROOT);
    
RegAdminCmd("sm_setplayedtime"Command_setTimeADMFLAG_ROOT);
}

//IN SERVER
public OnClientPutInServer(client)
{
    
AltTime(client1);
    
ClientTimer[client] = (CreateTimer(60.0TimerAddclientTIMER_REPEAT))
}

//LEAVE SERVER
public OnClientDisconnect(client)
{
    
CloseHandle(ClientTimer[client]);
    
AltTime(client0)
}

//TIMER
public Action:TimerAdd(Handle:timerany:client)
{
    if(
IsClientConnected(client) && IsClientInGame(client))
    {
        
Minutes[client]++;
    }
}

//COMMAND
public Action:Command_getTime(clientargs)
{
    if(
Minutes[client] == || Minutes[client] == -1)
    {
        
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minute!"Minutes[client])
    }
    else
        
PrintToChat(client"[FZG] \x05You have played on this server for \x03%d\x05 minutes!"Minutes[client])
    return 
Plugin_Handled;
}
public 
Action:Command_setTime(clientargs)
{
    if(!
IsValidClient(client))
    {
        return 
Plugin_Handled;
    }
    if(
args != 2)
    {
        
ReplyToCommand(client"[FZG] Usage: sm_setplayedtime <target> <amount>");
        return 
Plugin_Handled;
    }
    
char target_name[MAX_TARGET_LENGTH], buffer[512];
    
int target_list[MAXPLAYERS], target_countg_GivePlayedTime;
    
bool tn_is_ml;
    
    
GetCmdArg(1buffersizeof(buffer));
    if((
target_count ProcessTargetString(bufferclienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    
GetCmdArg(2buffersizeof(buffer));
    
g_GivePlayedTime StringToInt(buffer);
    for(
int i 0target_counti++)
    {
        
Minutes[target_list[i]] = g_GivePlayedTime;
    }
    if(
tn_is_ml)
    {
        
ReplyToCommand(client"[FZG] %s's playtime set to %d"target_nameg_GivePlayedTime);
    }
    else
    {
        
ReplyToCommand(client"[FZG] %s's playtime set to %d""_s"target_nameg_GivePlayedTime);
    }
    return 
Plugin_Handled;
}
    
//CHANGE
public AltTime(clientconnection)
{
    new 
Handle:DB CreateKeyValues("TimePlayed");
    
FileToKeyValues(DBTPPath);
    
    new 
String:SID[32];
    
GetClientAuthId(clientAuthId_Steam2SIDsizeof(SID));
    
    if(
connection == 1)
    {
        
//Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            new 
String:name[MAX_NAME_LENGTH], String:temp_name[MAX_NAME_LENGTH];
            
GetClientName(clientnamesizeof(name));
            
            
KvGetString(DB"name"temp_namesizeof(temp_name), "NULL");
            
            
Minutes[client] = KvGetNum(DB"minutes"0);
        
            
KvSetNum(DB"minutes"Minutes[client])
        }
    }
    else if(
connection == 0)
    {
        
//Not Connected
        
if(KvJumpToKey(DBSIDtrue))
        {
            
KvSetNum(DB"minutes"Minutes[client]);
        }
    }
    
    
KvRewind(DB);
    
KeyValuesToFile(DBTPPath);
    
CloseHandle(DB);
}

bool IsValidClient(clientbool bAllowBots truebool bAllowDead true)
{
    if(!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
    {
        return 
false;
    }
    return 
true;



But still thank you mate


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

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