Frequently asked scripting questions

From GT-MP
Jump to: navigation, search

Frequently asked scripting questions

Getting Started

First of all, you should check out our Getting Started section, a lot of things are already explained there. Also take a look at the Server Resources. A lot of things are already included. Like the NativeUI a simple login/register script and much more.

How do I get autocompletion?

You can follow any of these guides, depending on your OS:

How do I make a command accept more than 1 word as its parameter?

Use the GreedyArg parameter in the Command attribute, like this:

[Command("me", GreedyArg = true)]
public void TestCommand(Client sender, string message)

How do I change a command's usage text?

Set the second argument in the command's constructor, for example:

[Command("me", "Usage: ~r~/me [your message]", GreedyArg = true)]
public void TestCommand(Client sender, string message)

How do I get the vehicle a player is in?

Take a look at getPlayerVehicle. If you also want to know which seat a player is in, you can use getPlayerVehicleSeat.

How do I get the player's current ammo?

You can use getPlayerWeaponAmmo.

How do I set the player's hair color?

You can use the API Function SetPlayerHairColor in combination with this list of Hair Colors. This only works on the freemode skins (GTAO characters).


Note: The API Function SetPlayerHeadBlendData has to be called before the above native, otherwise the hair color will be default green.

How can I access functions and variables in other client scripts?

Check out Cross-file JavaScript variables.

How do I use CEF?

There's a brilliant example on the wiki which you can find here.

How do I show a blip/marker only for 1 player?

Use a clientside command instead of a serverside command. You can tell a client to do this from the server by triggering a client event using triggerClientEvent.

Do I have to inherit from the Script class for every class I make?

No, and you probably shouldn't. In most cases you will only need a single class that inherits from Script. You can also use the API from outside of your main class using the static API.shared.

How can I open doors on buildings like ammunation? (Doormanager)

Follow this short guide about the Doormanager.

My Server does not start under Linux?

If run the mono command to start your Server.exe but no console log appears (and your server runs Linux) the issue might be with the wrong Mono Version. Please make sure version 5.8 is installed. To downgrade have a look here: How to downgrade Mono. If you need to still setup your server have a look over here Setting Up a Development Environment on Linux.