SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/07/2019, 08:02 AM   #1
wilking
Big Clucker
 
Join Date: May 2017
Posts: 71
Reputation: 0
Default How to set time for player

Hello everyone

I want set time for player .

Ex : prisonfreezetime player 45'

When prison player . They /time show time to free = 45 minutes . But time not run . It will run if player work

Problem : how to set 45' for player . Gettime() + 60*45 ??

Help me pls . And sorry my english . Thanks all very much ...
wilking is offline   Reply With Quote
Old 12/07/2019, 08:38 AM   #2
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 865
Reputation: 43
Default Re: How to set time for player

save as new variable - seconds.

at the top of the code
PHP Code:
new PrisonSeconds[MAX_PLAYERS];
new 
PrisonTimer[MAX_PLAYERS]; 
when player goes in jail.
PHP Code:
PrisonSeconds[playerid] = 60*45//60 sec x 45 min = 2700 so code will calculate himself
PrisonTimer[playerid] = SetTimerEx("PrisonTimerAsSecond",1000,true,"i",playerid); 
function for prison timer
PHP Code:
forward PrisonTimerAsSecond(playerid);
public 
PrisonTimerAsSecond(playerid)
{
    
PrisonSeconds[playerid]--;
    if(
PrisonSeconds[playerid] <= 0)
    {
        
KillTimer(PrisonTimer[playerid]);
        
//unjail code here
        /*
        SetPlayerPos(playerid,x,y,z);
        SendClientMessage(playerid,-1,"You're free now!");
        */    
    
}
    return 
1;

also, KillTimer when player disconnects (OnPlayerDisconnect)
PHP Code:
KillTimer(PrisonTimer[playerid]); 
you can save that prison seconds in database too.

on command /time
PHP Code:
new string[128];
if(
PrisonSeconds[playerid] < 60format(string,sizeof(string),"You have %d seconds left for freedom",PrisonSeconds[playerid]);
else 
format(string,sizeof(string),"You have %d minutes left for freedom",PrisonSeconds[playerid] / 60);
SendClientMessage(playerid,-1,string); 
__________________
here to help
Mugala is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use dini save online player in to file every time player enter or out Chrisli520 Scripting Help 1 31/10/2013 07:04 AM
How to make when player type command one time to enable, second time to disable ? bustern Scripting Help 3 04/09/2013 08:35 AM
how to set player's time same as world time memeli11 Scripting Help 0 02/05/2013 07:35 PM
VIP Tag disappears for player 1 if player 2 uses it at the same time. OleKristian95 Scripting Help 6 10/05/2012 06:52 AM
Set Player Time scripter1 Help Archive 2 02/10/2010 03:34 PM


All times are GMT. The time now is 11:10 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.