SA-MP Forums Archive
[FilterScript] TheLazySloth Functions - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] TheLazySloth Functions (/showthread.php?tid=326221)



TheLazySloth Functions - TheLazySloth - 16.03.2012

Dear SA-MP community,

This is a simple list of all functions I use, some were created by me and some I got off other scripts. Enjoy!


This will be updated as I think of more useful functions.
LAST FUNCTION: SetServerName, SetServerMode, SetServerMap, & SetServerWebsite
Come back for more and help me by thinking of a function everyone could benefit from and I'll give you the credit!


pawn Code:
/*...........................:: Server Functions ::..........................*/
IsValid[NameGoesHere]
pawn Code:
stock IsValidWeatherID(WeatherID) {
    switch(WeatherID) {
        case 1 .. 45: return true;
    }
    return false;
}

stock IsValidModelID(ModelID) {
    switch(ModelID) {
        case 400 .. 611: return true;
    }
    return false;
}

stock IsValidSkinID(SkinID) {
    switch(SkinID) {
        case 0 .. 299: return true;
    }
    return false;
}

stock IsValidWeaponID(WeaponID) {
    switch(WeaponID) {
        case 0 .. 46: return true;
    }
    return false;
}

stock GetWeaponSlotFromWeaponID(WeaponID) {
    switch(WeaponID) {
        case 0, 1:          return 0;
        case 2 .. 9:        return 1;
        case 22 .. 24:      return 2;
        case 25 .. 27:      return 3;
        case 28, 29, 32:    return 4;
        case 30, 31:        return 5;
        case 33 .. 34:      return 6;
        case 35 .. 38:      return 7;
        case 16 .. 18, 39:  return 8;
        case 41 .. 43:      return 9;
        case 10 .. 15:      return 10;
        case 44 .. 46:      return 11;
        case 40:            return 12;
    }
    return false;
}
Example Usages:
for(new Skin = 0; Skin < 500; Skin++) {
if(!IsValidSkinID(Skin)) printf("%d is an invalid skin ID!", Skin);
}

new ModelID = 405;
if(IsValidModelID(ModelID)) CreateVehicle(ModelID, 1684.7092, 1447.8268, 10.7705, 270.9431, -1, -1, -1);

Randomize
pawn Code:
stock Randomize(Minimum, Maximum) {
    new Result = random((Maximum + 1));
    while(Result < Minimum) {
        Result = random((Maximum + 1));
    }
    return Result;
}
Example Usage:
stock OnPlayerSpawn(playerid) {
new VehicleID, W, I, Float: X, Float: Y, Float: Z, Float: A;
GetPlayerPosition(playerid, W, I, X, Y, Z, A);
VehicleID = CreateVehicle(Randomize(400, 600), X, Y, Z, A, 128, 128, -1);
SetVehicleVirtualWorld(VehicleID, W);
LinkVehicleToInterior(VehicleID, I);
PutPlayerInVehicle(playerid, VehicleID, 0);
return true;
}

SetServerName, SetServerMode, SetServerMap & SetServerWebsite
pawn Code:
stock SetServerName(Name[]) {
    new RconCommand[100];
    format(RconCommand, 100, "hostname %s", Name);
    SendRconCommand(RconCommand);
    return true;
}

stock SetServerMode(Mode[]) {
    new RconCommand[100];
    format(RconCommand, 100, "gamemodetext %s", Mode);
    SendRconCommand(RconCommand);
    return true;
}

stock SetServerMap(Map[]) {
    new RconCommand[100];
    format(RconCommand, 100, "mapname %s", Map);
    SendRconCommand(RconCommand);
    return true;
}

stock SetServerWebsite(Website[]) {
    new RconCommand[100];
    format(RconCommand, 100, "weburl %s", Website);
    SendRconCommand(RconCommand);
    return true;
}
Example Usages:
public OnGamemodeInit() {
SetServerName("TheLazySloth's Server");
SetServerMode("Freeroam");
SetServerMap("Las Venturas");
SetServerWebsite("https://sampforum.blast.hk/showthread.php?pid=1735012#pid1735012");
return true;
}

pawn Code:
/*...........................:: Player Functions ::...........................*/
SetPlayerPosition & GetPlayerPosition
pawn Code:
stock SetPlayerPosition(PlayerID, W = 0, I = 0, Float: X = 0.0, Float: Y = 0.0, Float: Z = 0.0, Float: A = 0.0) {
    if(!IsPlayerConnected(PlayerID)) return false;

    if(IsPlayerInAnyVehicle(PlayerID)) RemovePlayerFromVehicle(PlayerID);

    SetPlayerVirtualWorld(PlayerID, W);
    SetPlayerInterior(PlayerID, I);
    SetPlayerPos(PlayerID, X, Y, Z);
    SetPlayerFacingAngle(PlayerID, A);
    return true;
}

stock GetPlayerPosition(PlayerID, &W, &I, &Float: X, &Float: Y, &Float: Z, &Float: A) {
    if(!IsPlayerConnected(PlayerID)) return false;

    W = GetPlayerVirtualWorld(PlayerID);
    I = GetPlayerInterior(PlayerID);
    GetPlayerPos(PlayerID, X, Y, Z);
    if(IsPlayerInAnyVehicle(PlayerID)) {
        GetVehicleZAngle(GetPlayerVehicleID(PlayerID), A);
    } else {
        GetPlayerFacingAngle(PlayerID, A);
    }
    return true;
}
Example Usages:
SetPlayerPosition(playerid, 0, 0, 1684.7092, 1447.8268, 10.7705, 270.9431);
SendClientMessage(playerid, -1, "Welcome to Las Venturas Airport!");

new W, I, Float: X, Float: Y, Float: Z, Float: A, VehicleID;
GetPlayerPosition(playerid, W, I, X, Y, Z, A);
VehicleID = CreateVehicle(506, X, Y, Z, A, 128, 128, -1);
SetVehicleVirtualWorld(VehicleID, W);
LinkVehicleToInterior(VehicleID, I);
PutPlayerInVehicle(playerid, VehicleID, 0);
SendClientMessage(playerid, -1, "You have spawned a royal blue SuperGT at your exact location!");

GetPlayerX, GetPlayerY, GetPlayerZ, SetPlayerX, SetPlayerY & SetPlayerZ
pawn Code:
stock SetPlayerX(PlayerID, Float: X = 0.0) {
    if(!IsPlayerConnected(PlayerID)) return false;
    new Float: Unused,
        Float: Y,
        Float: Z;
    GetPlayerPos(PlayerID, Unused, Y, Z);
    #pragma unused Unused
    SetPlayerPos(PlayerID, X, Y, Z);
    return true;
}

stock GetPlayerX(PlayerID, &Float: X) {
    if(!IsPlayerConnected(PlayerID)) return false;
    new Float: Y,
        Float: Z;
    GetPlayerPos(PlayerID, X, Y, Z);
    #pragma unused Y
    #pragma unused Z
    return true;
}

stock SetPlayerY(PlayerID, Float: Y = 0.0) {
    if(!IsPlayerConnected(PlayerID)) return false;
    new Float: X,
        Float: Unused,
        Float: Z;
    GetPlayerPos(PlayerID, X, Unused, Z);
    #pragma unused Unused
    SetPlayerPos(PlayerID, X, Y, Z);
    return true;
}

stock GetPlayerY(PlayerID, &Float: Y) {
    if(!IsPlayerConnected(PlayerID)) return false;
    new Float: X,
        Float: Z;
    GetPlayerPos(PlayerID, X, Y, Z);
    #pragma unused X
    #pragma unused Z
    return true;
}

stock SetPlayerZ(PlayerID, Float: Z = 0.0) {
    if(!IsPlayerConnected(PlayerID)) return false;
    new Float: X,
        Float: Y,
        Float: Unused;
    GetPlayerPos(PlayerID, X, Y, Unused);
    #pragma unused Unused
    SetPlayerPos(PlayerID, X, Y, Z);
    return true;
}

stock GetPlayerZ(PlayerID, &Float: Z) {
    if(!IsPlayerConnected(PlayerID)) return false;
    new Float: X,
        Float: Y;
    GetPlayerPos(PlayerID, X, Y, Z);
    #pragma unused X
    #pragma unused Y
    return true;
}
Example Usage:
public OnPlayerUpdate(playerid) {
new Float: Z;
GetPlayerZ(playerid, Z);
Z += 0.1;
SetPlayerZ(playerid, Z);
return true;
}

SetCameraInFrontOfPlayer
pawn Code:
stock SetCameraInFrontOfPlayer(PlayerID, Float: Distance = 2.5, Float: Lift = 0.5) {
    if(IsPlayerConnected(PlayerID)) return false;
   
    new Float: X,
        Float: Y,
        Float: Z,
        Float: A;
    GetPlayerPos(PlayerID, X, Y, Z);
    if(IsPlayerInAnyVehicle(PlayerID)) {
        GetVehicleZAngle(GetPlayerVehicleID(PlayerID), A);
    } else {
        GetPlayerFacingAngle(PlayerID, A);
    }
    // GetPlayerPosition(PlayerID, W, I, X, Y, Z, A);

    SetPlayerCameraLookAt(playerid, X, Y, Z);

    // Credits to ****** for the GetXYInFrontOfPlayer function.
    X += (Distance * floatsin(-A, degrees));
    Y += (Distance * floatcos(-A, degrees));

    SetPlayerCameraPos(playerid, X, Y, (Z + Lift));
    return true;
}
Example Usage:
public OnPlayerSpawn(playerid) {
SetCameraInFrontOfPlayer(PlayerID);
return 1;
}

More to come!
Want to see a function? Ask me to make it for you below, I'll try my best a post it up here and give you the credit for the idea.
Comment, suggest, report, etc below! Your opinions matter to me.

~ TheLazySloth ~


Re: TheLazySloth Functions - thefatshizms - 16.03.2012

nice +rep


Re : TheLazySloth Functions - dydjyz - 16.03.2012

Good


Re: TheLazySloth Functions - SimonItaly - 16.03.2012

Quote:
pawn Code:
stock IsValidWeatherID(WeatherID) {
    switch(WeatherID) {
        case 1 .. 45: return true;
    }
    return false;
}

stock IsValidModelID(ModelID) {
    switch(ModelID) {
        case 400 .. 611: return true;
    }
    return false;
}

stock IsValidSkinID(SkinID) {
    switch(SkinID) {
        case 0 .. 299: return true;
    }
    return false;
}

stock IsValidWeaponID(WeaponID) {
    switch(WeaponID) {
        case 0 .. 46: return true;
    }
    return false;
}
Well, switch is a bit useless here, you can try

pawn Code:
#define IsValidSkinID(%0) \
0 <= %0 <= 299



Re: TheLazySloth Functions - MP2 - 17.03.2012

Ugly indentation is ugly and hard to read.


Re: TheLazySloth Functions - TheLazySloth - 17.03.2012

@Darkslyder;
My way works too =]

@MP2;
Yeah I didn't want to use Pawn/Code tags for the Usages, besides the function names pretty much speaks for themselves.


Re: TheLazySloth Functions - Jonny5 - 17.03.2012

Quote:
Originally Posted by thefatshizms
View Post
nice +rep
second that


Re: TheLazySloth Functions - TheLazySloth - 18.03.2012

Thanks you guys =]


Re: TheLazySloth Functions - Jonny5 - 18.03.2012

Quote:
Originally Posted by DarkSlyder
View Post
Well, switch is a bit useless here, you can try

pawn Code:
#define IsValidSkinID(%0) \
0 <= %0 <= 299
ill have to agree with this,

however these functions are useful!!

esp the setposx,y,z ect..

nice idea!


Re: TheLazySloth Functions - TheLazySloth - 18.03.2012

Thanks ^^


Re: TheLazySloth Functions - Soldier9221 - 19.03.2012

Very useful.

+rep


Re: TheLazySloth Functions - TheLazySloth - 21.03.2012

Will add more very soon.
Before I add some I would like anybody to tell me a useful function to make, one you would use for your server. I will make this idea of yours and put it in my list and point credits toward you. =]


Re: TheLazySloth Functions - Spooky - 19.04.2012

Great Work Brother


Re: TheLazySloth Functions - Wazner - 19.04.2012

Quote:
pawn Code:
stock Randomize(Minimum, Maximum) {
    new Result = random((Maximum + 1));
    while(Result < Minimum) {
        Result = random((Maximum + 1));
    }
    return Result;
}
Euhm, i don't think this will give good results.
When you do Randomize(5, 100), it will give a value between 5 and 95.

I'll suggest this
pawn Code:
#define RANDOM(%0,%1) (%0 + random(%1 - %0))
or as a stock function
pawn Code:
stock Random(min, max)
{
    return min + random(max - min);
}



Re: TheLazySloth Functions - Universal Member - 20.04.2012

Nice try and good job !