SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 16/03/2012, 07:21 PM   #1
TheLazySloth
Huge Clucker
 
TheLazySloth's Avatar
 
Join Date: Aug 2011
Location: United States > California > Los Angeles County > Antellope Valley > Lancaster
Posts: 398
Reputation: 31
Default TheLazySloth Functions

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("http://forum.sa-mp.com/showthread.php?p=1735012#post1735012");
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 ~
__________________
I'm in the Script Help section helping people the best I can.

Guidelines:
I won't respond to your help thread IF there's 2 or more posts already and I havn't previously viewed it.

I won't respond to your help thread IF the title doesn't relate to the question.

I won't respond to your help thread IF it isn't in understandable English.

If I've HELPED you and SOLVED your problem, +rep is appreciated but not expected.

"This forum requires that you wait 120 seconds between posts. Please try again in 69 seconds." Is the reason I'm probably not responding swiftly, so be patient.

Last edited by TheLazySloth; 19/04/2012 at 07:54 AM.
TheLazySloth is offline   Reply With Quote
Old 16/03/2012, 08:53 PM   #2
thefatshizms
High-roller
 
thefatshizms's Avatar
 
Join Date: Dec 2011
Location: England
Posts: 1,754
Reputation: 259
Default Re: TheLazySloth Functions

nice +rep
__________________
SFCNR ******* | SFCNR Forum
thefatshizms is offline   Reply With Quote
Old 16/03/2012, 09:09 PM   #3
dydjyz
Big Clucker
 
dydjyz's Avatar
 
Join Date: Apr 2010
Posts: 54
Reputation: 11
Default Re : TheLazySloth Functions

Good
dydjyz is offline   Reply With Quote
Old 16/03/2012, 11:17 PM   #4
SimonItaly
Huge Clucker
 
SimonItaly's Avatar
 
Join Date: Mar 2010
Location: 🇪🇺 🇮🇹
Posts: 244
Reputation: 87
Default Re: TheLazySloth Functions

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
__________________
SimonItaly is offline   Reply With Quote
Old 17/03/2012, 12:11 AM   #5
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,203
Reputation: 975
Default Re: TheLazySloth Functions

Ugly indentation is ugly and hard to read.
__________________
Click banner above for more info. View trailers here.
MP2 is offline   Reply With Quote
Old 17/03/2012, 06:04 AM   #6
TheLazySloth
Huge Clucker
 
TheLazySloth's Avatar
 
Join Date: Aug 2011
Location: United States > California > Los Angeles County > Antellope Valley > Lancaster
Posts: 398
Reputation: 31
Default Re: TheLazySloth Functions

@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.
__________________
I'm in the Script Help section helping people the best I can.

Guidelines:
I won't respond to your help thread IF there's 2 or more posts already and I havn't previously viewed it.

I won't respond to your help thread IF the title doesn't relate to the question.

I won't respond to your help thread IF it isn't in understandable English.

If I've HELPED you and SOLVED your problem, +rep is appreciated but not expected.

"This forum requires that you wait 120 seconds between posts. Please try again in 69 seconds." Is the reason I'm probably not responding swiftly, so be patient.
TheLazySloth is offline   Reply With Quote
Old 17/03/2012, 02:48 PM   #7
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: TheLazySloth Functions

Quote:
Originally Posted by thefatshizms View Post
nice +rep
second that
Jonny5 is offline   Reply With Quote
Old 18/03/2012, 02:00 AM   #8
TheLazySloth
Huge Clucker
 
TheLazySloth's Avatar
 
Join Date: Aug 2011
Location: United States > California > Los Angeles County > Antellope Valley > Lancaster
Posts: 398
Reputation: 31
Default Re: TheLazySloth Functions

Thanks you guys =]
__________________
I'm in the Script Help section helping people the best I can.

Guidelines:
I won't respond to your help thread IF there's 2 or more posts already and I havn't previously viewed it.

I won't respond to your help thread IF the title doesn't relate to the question.

I won't respond to your help thread IF it isn't in understandable English.

If I've HELPED you and SOLVED your problem, +rep is appreciated but not expected.

"This forum requires that you wait 120 seconds between posts. Please try again in 69 seconds." Is the reason I'm probably not responding swiftly, so be patient.
TheLazySloth is offline   Reply With Quote
Old 18/03/2012, 02:24 AM   #9
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: TheLazySloth Functions

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!
Jonny5 is offline   Reply With Quote
Old 18/03/2012, 04:40 PM   #10
TheLazySloth
Huge Clucker
 
TheLazySloth's Avatar
 
Join Date: Aug 2011
Location: United States > California > Los Angeles County > Antellope Valley > Lancaster
Posts: 398
Reputation: 31
Default Re: TheLazySloth Functions

Thanks ^^
__________________
I'm in the Script Help section helping people the best I can.

Guidelines:
I won't respond to your help thread IF there's 2 or more posts already and I havn't previously viewed it.

I won't respond to your help thread IF the title doesn't relate to the question.

I won't respond to your help thread IF it isn't in understandable English.

If I've HELPED you and SOLVED your problem, +rep is appreciated but not expected.

"This forum requires that you wait 120 seconds between posts. Please try again in 69 seconds." Is the reason I'm probably not responding swiftly, so be patient.
TheLazySloth is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 05:01 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.