Custom functions

Custom functions

Custom functions can be a real helper if, lets say you need to reset a player when he does a teleport or respawns, e.g. remove his weapons, reset his world boundaries and set their interior back to 0 (the normal world), 3 lines might not seem like much but if you are reseting them in every teleport command then it starts to take up space.

Well heres how to do it, first off i need to create the function, im going to call mine "Reset(playerid)", take a look

Reset(playerid)
{
    SetPlayerWorldBounds(playerid, 20000.0, -20000.0, 20000.0, -20000.0);
    ResetPlayerWeapons(playerid);
    SetPlayerInterior(playerid,0);
}

Thats all there is to it, you say what you want the function to be called, in this case "Reset(playerid)", open brackets, what you want the function to do then close brackets

To use this function, just use the line Reset(playerid); under where ever you want them to be reset.


Some more examples are as follows

SetPlayerPosEx(playerid,Float:x,Float:y,Float:z,Float:a,interior,world)
SetPlayerPosEx(playerid,Float:x,Float:y,Float:z,Float:a,interior,world)
{
    SetPlayerPos(playerid,Float:x,Float:y,Float:z);
    SetPlayerFacingAngle(playerid,Float:a);
    SetPlayerInterior(playerid,interior);
    SetPlayerVirtualWorld(playerid,world);
}
FixCar(playerid)
FixCar(playerid)
{
    if(IsPlayerInAnyVehicle(playerid) == 1)
    {
        if(GetPlayerState(playerid) == 2)
        {
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
        SendClientMessage(playerid,COLOR_YELLOW,"Car fixed!");
        }
        else
        {
        SendClientMessage(playerid,COLOR_YELLOW,"You need to be the driver to fix your car");
        }
    }
    else
    {
        SendClientMessage(playerid,COLOR_YELLOW,"You need to be in a vehicle to fix it!");
    }
}

Back | Home