OnUpdate

From GT-MP
Jump to: navigation, search
OnUpdate
Shared Function
Utilities-terminal.png Server-Side System-users.png Client-Side
Csharp.png C# Javascript.png JavaScript

This type of event is mainly used for iterating code at a tick rate of 120Hz.

Requirements

First of all, if you want to call this on the server-side then it should be defined in your main constructor for it to be called, otherwise it wouldn't be initiated at all! On client-side this requirement is not necessary.

In C#
Server-Side Function

public Main()
{
	API.onUpdate += OnUpdateHandler;
}

Usage example(s)

In C#
Server-Side Function

public DateTime LastAnnounce; //We define the variable LastAnnounce as a DateTime type so we can store time in it
public void OnUpdateHandler()
{ 
	if (DateTime.Now.Subtract(LastAnnounce).TotalMinutes >= 15) //Checks if the time between now and the 'last announce' is more or equal than 15 minutes
	{
		LastAnnounce = DateTime.Now; //We store current time into the LastAnnounce variable
		API.consoleOutput("Foo! see you in 15 minutes!");
	}
}

In Javascript
Client-Side Function

API.onUpdate.connect(function () {
   // do stuff
});

References