Frequently asked scripting questions

From GT-MP
Revision as of 05:15, 29 July 2017 by Kriestian (talk | contribs) (入门)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 native _SET_PED_HAIR_COLOR in combination with this list of Hair Colors. This only works on the freemode skins (GTAO characters).

Dialog-warning.png

Note: The native SET_PED_HEAD_BLEND_DATA 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.

References