Wiki

Clone wiki

EFLC-Multiplayer / apiPlayer methods

apiPlayer

apiMath::Vector3 getPos()

void setPos(apiMath::Vector3& pos)

#!c++
apiMath::Vector3 pos = apiPlayer::get(playerid).getPos();
pos.z += 10.0f;
apiPlayer::get(playerid).setPos(pos);

int getID()

const char* getNick()

Maximum size is 22 chars

void setNick(const char* nick)

Updates the player name

void sendMsg(const char* msg, unsigned int hex)

Hex color is ARGB

#!c++
char msg[50] = "";
sprintf_s(msg, "Hello Mr %s", apiPlayer::get(playerid).getNick());
apiPlayer::get(playerid).sendMsg(msg, 0xFFFF0000); //ARGB for RED

void sendColoredMsg(int msgId)

void setSkin(unsigned int model)

#!c++
apiPlayer::get(playerid).setSkin(playerList::getModel(201)); //ID 201 is the MODEL_M_Y_SWAT skin
//You can also use the model hash directly
apiPlayer::get(playerid).setSkin(1754440500); //MODEL_F_Y_TOURIST_01 hash

void setWorld(unsigned int vWorld)

#!c++
/*Server entities such as players and vehicles are streamed based on their world ID.
This allows the server to use the same map for different features at the same time*/
apiPlayer::get(playerid).setWorld(ID); //IDs: 1 - 4294967295

unsigned int getWorld()

Returns the player current virtual world

void giveWeapon(unsigned int weaponId, unsigned int ammo)

WeaponIds LINK

#!c++
apiPlayer::get(playerid).giveWeapon(15, 300); //Gives the player 300 rounds of M4

void removeWeapon(unsigned int weaponId)

#!c++
apiPlayer::get(playerid).removeWeapon(13); //Removes only their SMG
//Or remove all their weapons with
apiPlayer::get(playerid).removeWeapon(0);

int getHealth()

Returns the current player HP, ranges from 0-200 or negative if the player is dead

void setHealth(int hp)

#!c++
apiPlayer::get(playerid).setHealth(apiPlayer::get(playerid).getHealth() - 10); //Removes 10 health points

void setColor(unsigned int hex)

Changes the player name & blip colors to the new RGBA hex

#!c++
apiPlayer::get(playerid).setColor(0x0000FFFF); //Blue hex

unsigned int getColor()

Returns the current RGBA hex color

void spawn(apiMath::Vector3& pos)

Must be used to spawn the player for the first time only

#!c++
bool onPlayerCredentials(int playerid)
{
    apiMath::Vector3 spawnPos(-205.476f, 630.067f, 13.8088f); //Makes the player spawn at the central park
    player.spawn(spawnPos);
    return true;
}

void setRespawnPos(apiMath::Vector3& pos)

Defines where the player will spawn once they die

int getDriving()

Return an ID for the vehicle the player is driving or NULL if none

int isInVehicle()

Return an ID for the vehicle the player is inside or NULL if none

void removeFromVehicle()

Removes the player from any vehicle

int getWeapon()

Returns the current weapon ID

int getAmmo()

Returns the amount of ammo the current weapon has

void setFrozen(bool b)

TRUE to freeze the player and FALSE to unfreeze

void disconnect()

Closes the client connection immediately

int getPing(bool average)

TRUE returns the player average ping, FALSE returns the last ping

int getAnim()

Returns the current anim ID

#!c++
int anim = apiPlayer::get(id).getAnim();
if(anim > 6383 && anim < 6410)
{
    //The player is parachuting
}

void setClothes(unsigned int part, unsigned int value)

Changes the skin clothes variation. Part: 0-8 (INDEX) Value: 0-99, where 0 is default

void setProperty(unsigned int part, unsigned int value)

Adds/removes skin components such as hats and glasses Part: 0-1 Value: 0-99 or -1 for default

void forceAnim(const char animGroup, const char animName, bool loop)

Makes the player perform an animation. Use openIV to view all the anims.

#!c++
//Sit down anim
apiPlayer::get(playerid).forceAnim("amb_sit_chair_m", "sit_down_l", false);

void stopAnims()

Stop whatever animations

void setKeyHook(unsigned int virtualKey, bool addOrRemove)

After using this function the client will MSG the server whenever they press the key.

#!c++
apiPlayer::get(playerid).setKeyHook(VK_RETURN, true); //VK_RETURN is the ENTER key
//Now you must register a callback function using apiPlayerInputs::registerKeyInputs

const char* getIp()

Returns the player IP

void showBlip(int blipId, bool show)

Shows/Hides a blip for the player. View the apiBlips page to learn how to create a blip.

void cam_setPos(apiMath::Vector3 pos, unsigned int camWorld)

Creates a new camera view for the player at the given position.

void cam_setLookAt(apiMath::Vector3 pos)

Points the player camera at the position "pos". Must be used after cam_setPos.

#!c++
//Points the camera at the Meadows Park
apiPlayer::get(playerid).cam_setPos(apiMath::Vector3(1477.24f, 445.437f, 70.8625f), 1);
apiPlayer::get(playerid).cam_setLookAt(apiMath::Vector3(1565.05f, 711.43f, 82.8732f));

void cam_attachOnPlayer(int playerid)

Attachs the camera on another player. Must be used after cam_setPos.

void checkSum(const char* file)

Returns the checkSum for a file. Used for integrity checks.

#!c++
//The result will arrive as a callback for registerPlayerCheckSum
apiPlayer::get(playerid).checkSum("common\\data\\handling.dat");

bool isObjectSpawned(int id)

Returns whether the client has the object spawned yet

bool isVehicleSpawned(int id)

Returns whether the client has the vehicle spawned yet

void requestWeapons()

This function will make the Client return all the weapons they have. The result will arrive as a callback for registerPlayerWeaponsArrived. A example is available at the Demo Project.

unsigned int getWeaponsSize()

Returns how many weapons the player has. The amount is only updated after using requestWeapons(). A example is available at the Demo Project.

void getWeaponData(unsigned int index, int& weapon, int& ammo)

Copies the weapon id and ammo to the references. They only update after using requestWeapons(). A example is available at the Demo Project. Index throws out_of_range exception, use getWeaponsSize for array size

unsigned int getRoomKey()

Returns the GTA Interior Key.

#!c++
if(apiPlayer::get(playerid).getRoomKey() != 0)
{
    //The player is inside a building
}

void playStream(const char stream, apiMath::Vector3 pos)

Makes the Client to play a radio stream or an audio file. Use NULL for pos to play the stream on the frontend or give it coordinates to stream from.

#!c++
apiPlayer::get(playerid).playStream(http://some-radio-link:radioPort/listen.pls, NULL);

void stopStreams()

Stops the current stream. Must always be used before playing a new stream.

void setArmor(int i)

Armor range is: 0-200

int getArmor()

Returns the current armor points

void setMoney(int i)

Changes the player money display to the amount given. Seems like GTA doesn't support negative values on GTA4.

void setDoorStat(unsigned int model, apiMath::Vector3* pos, bool status)

Allows the client to Lock/Unlock doors.

Params:

unsigned int model: OBJ hash model of the door. Use 0 to lock/unlock all pre defined doors.

apiMath::Vector3* pos: OBJ coordinates.

bool status: TRUE locks and FALSE unlocks

Updated