[Tutorial] How to fast forward timelapse In-Game
#1

Hey guys, I want to show you how to fast forward timelapse In-Game as I haven't found any tutorials according this. This is my first tutorial, I'll hope you can understand and make a use of it. It's just a simple use of timers and variables.

What can you use it for?

-It can be useful on roleplay servers (you can pay realistic amounts for players for 6-,8-,12 hours of in-game work - which can be 1 or 2 hours in real life for example).
-You can make a slowed down timelapse (compared to singleplayer, like GTA 4's or 5's).

In this tutorial I'll show you how to make 1 In-Game hour pass by 15 minutes in real life with the use of a variable and a simple timer.

First off, we have to declare 2 variables on the top of our script:
PHP Code:
new worldtime;        //we will use this to set and increase worldtime with the help of our timer
new timelapseTimer;        //timer 
After this, we have to set the world time under OnGameModeInit. Basically, this will be the starting time of our server.
PHP Code:
public OnGameModeInit()
{
    
worldtime 6;        // giving the value of the variable -> the starting time to be set
    
SetWorldTime(worldtime);        // will set the in-game time to the previously given value ^
    
timelapseTimer SetTimer("Timelapse"1000 9001);        // a 15-minute (900 sec) timer, repeating true (1) to continue and provide later timelapse. A higher interval will slow down, a lower one will fasten timelapse.
    
return 1;

Now we are forwarding and using a public function:
PHP Code:
forward Timelapse();
public 
Timelapse()
{
    
worldtime++;        // after 15 minutes, our variable's value is increased by 1
    
if(worldtime == 24worldtime 0;        // we have to reset worldtime, because the SA:MP world time ranges from 0 to 23
    
SetWorldTime(worldtime);        // success! with 15 minutes spent in real life, in game we already spent 1 hour.
    
SendClientMessageToAll(0xFFFFFFAA"One hour has passed.");
    return 
1// return 1, to continue

Finally, kill the timer under OnGameModeExit()
PHP Code:
public OnGameModeExit()
{
    
KillTimer(timelapseTimer);
    return 
1;

In one piece:

PHP Code:
#include <a_samp>
new worldtime;
new 
timelapseTimer;
forward Timelapse();
public 
Timelapse()
{
    
worldtime++;
    if(
worldtime == 24worldtime 0;
    
SetWorldTime(worldtime);
    
SendClientMessageToAll(0xFFFFFFAA"One hour has passed.");
    return 
1;
}
public 
OnGameModeInit()
{
    
worldtime 6;
    
SetWorldTime(worldtime);
    
timelapseTimer SetTimer("Timelapse"1000 9001);
    return 
1;
}
public 
OnGameModeExit()
{
    
KillTimer(timelapseTimer);
    return 
1;

Reply
#2

PHP Code:
public OnGameModeExit() 

    
KillTimer(timelapseTimer
    return 
1

You forgot " ; "
Reply
#3

Quote:
Originally Posted by Sunehildeep
View Post
PHP Code:
public OnGameModeExit() 

    
KillTimer(timelapseTimer
    return 
1

You forgot " ; "
Fixed
Reply
#4

A bit simple, but nonetheless will help others who are beginners.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)