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

how to make a bonus every 24 hours?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Domenator
Junior Member
Join Date: Mar 2016
Old 02-17-2018 , 10:19   how to make a bonus every 24 hours?
Reply With Quote #1

public PanelHandler(Handle:menu, MenuAction:action, param1, param2)
{

if (action == MenuAction_Select && param2 == 1)
{


if()
{
PrintToChat(param1, "\x04 Bonus \x071E90FFYou received a daily bonus:" );
}
else
{
PrintToChat(param1, "\x04 Bonus \x071E90FFYou have already received a daily bonus:" );
}


}
Domenator is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 02-17-2018 , 13:33   Re: how to make a bonus every 24 hours?
Reply With Quote #2

Steps:

1) Create a Database (SQL or MySQL)
2) Create a Table (Primary key: SteamId, timestamp)
3) On Command -> check if an entry exists withing the last 24h (use date functions of the database)
4) If not -> Send the reward and update the timestamp of the last reward. If exists -> no reward
__________________
Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch is offline
Domenator
Junior Member
Join Date: Mar 2016
Old 02-18-2018 , 04:13   Re: how to make a bonus every 24 hours?
Reply With Quote #3

Quote:
Originally Posted by Totenfluch View Post
Steps:

1) Create a Database (SQL or MySQL)
2) Create a Table (Primary key: SteamId, timestamp)
3) On Command -> check if an entry exists withing the last 24h (use date functions of the database)
4) If not -> Send the reward and update the timestamp of the last reward. If exists -> no reward
php
Quote:
pragma semicolon 1
#include <sourcemod>
#include <shop>
#pragma tabsize 0
#include<sdktools>
#include<sdkhooks>

new Handle:g_hConVar_iDelayTime;
new String:g_sAuth[66][32];
new g_iLastTime[66];
new g_iDelay;
new HandleB_hndl;


public Plugin:myinfo =
{
name = "[Shop] Bonus",
author = "Delires",
description = "Adds shop bonus.",
version = "1.0",
}


public OnPluginStart()
{

g_hConVar_iDelayTime = CreateConVar("sm_shop_bonus_delaytime", "25", "after how many seconds the player can get the following bonus", 0, false, 0.0, false, 0.0);
AutoExecConfig(true, "/shop_bonus", "shop");
/

RegConsoleCmd("playerbonus", Command_Bonus, "", 0);
}



public OnMapStart()
{
g_iDelay = GetConVarInt(g_hConVar_iDelayTime);

if(DB_hndl != INVALID_HANDLE) CloseHandle(DB_hndl); /

decl String:szError[255];
DB_hndl = SQLite_UseDatabase("shop_bonus", szError, sizeof(szError));


if(DB_hndl == INVALID_HANDLE)
{
SetFailState("[shop_bouns] Unable to connect to database (%s)", szError);
return;
}

SQL_LockDatabase(DB_hndl); /
// создаем таблицу
SQL_FastQuery(DB_hndl, "CREATE TABLE IF NOT EXISTS `shop_bonus` (`auth` TEXT(32), `time` INTEGER);");

SQL_UnlockDatabase(DB_hndl);
}

public OnClientPutInServer(iClient)
{

if (!IsFakeClient(iClient) && !IsClientSourceTV(iClient))
{
GetClientAuthString(iClient, g_sAuth[iClient], 31, true);
g_iLastTime[iClient] = 0;
}
return;
}

public Action:Command_Bonus(iClient, iArgs)
{
TryGiveBonus(iClient);
return Action:0;
}

TryGiveBonus(iClient)
{
new iCurrentTime = GetTime({0,0});
if (g_iLastTime[iClient] > iCurrentTime)
{
PrintToConsole(iClient, "please, do not spam!");
PrintToChat(iClient, "1");
return 0;
}
g_iLastTime[iClient] = iCurrentTime + 2;
decl String:sQuery[256];
Format(sQuery, 255, "SELECT `time` FROM `shop_bonus` WHERE `auth` = '%s'", g_sAuth[iClient]);
SQL_TQuery(DB_hndl, SQL_OnTryGiveBonus, sQuery, iClient, DBPriority:1);
return 0;
}

public SQL_OnTryGiveBonus(Handle:hOwner, Handle:hQuery, String:sError[], any:iClient)
{
if (hQuery)
{
decl String:sQuery[256];
if (SQL_FetchRow(hQuery))
{
new zero1 = 0;
new zero2 = 0;
new iCurrentTime = GetTime({0,0});
new iExpiriedTime = SQL_FetchInt(hQuery, zero1, zero2);
if (iExpiriedTime < iCurrentTime)
{
iCurrentTime = g_iDelay + iCurrentTime;
Format(sQuery, 255, "UPDATE `shop_bonus` SET `time` = %d WHERE `auth` = '%s'", iCurrentTime, g_sAuth[iClient]);
SQL_TQuery(DB_hndl, SQL_OnEmptyCallback, sQuery, any:0, DBPriority:1);
GiveBonus(iClient);
}
else
{
decl String:sExpiriedTime[64];
decl String:sCurrentTime[64];
FormatTime(sExpiriedTime, 63, "%d/%m/%Y - %H:%M", iExpiriedTime);
FormatTime(sCurrentTime, 63, "%d/%m/%Y - %H:%M", iCurrentTime);
PrintToChat(iClient, "\x01You will be able to get the bonus no sooner \x04%d\x03, \x01now \x04%s", sExpiriedTime, sCurrentTime);
ClientCommand(iClient, "play buttons/button11.wav");
}
}
else
{
Format(sQuery, 255, "INSERT INTO `shop_bonus` (`auth`, `time`) VALUES ('%s', %d)", g_sAuth[iClient], GetTime({0,0}) + g_iDelay);
SQL_TQuery(DB_hndl, SQL_OnEmptyCallback, sQuery, any:0, DBPriority:1);
GiveBonus(iClient);
}
}
return 0;
}

public SQL_OnEmptyCallback(Handle:hOwner, Handle:hQuery, String:sError[], any:data)
{
return 0;
}

GiveBonus(iClient)
{
new iBonus = GetRandomInt(200, 5000);


PrintToChat(iClient, "\x04You received a daily bonus: \x03%d loans", iBonus);
Shop_GiveClientCredits(iClient, iBonus);





}



does not work,please help me to correct mistakes.

Last edited by Domenator; 02-18-2018 at 09:05.
Domenator is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 02-18-2018 , 07:17   Re: how to make a bonus every 24 hours?
Reply With Quote #4

can you please use

PHP Tags?

PHP Code:
CODE 
Otherwise I will not help you because it is impossible to read.
__________________
Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch 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 03:49.


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