16.03.2012, 19:21
(
Last edited by TheLazySloth; 19/04/2012 at 07:54 AM.
)
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!
IsValid[NameGoesHere]
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
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
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;
}
SetPlayerPosition & GetPlayerPosition
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
Example Usage:
public OnPlayerUpdate(playerid) {
new Float: Z;
GetPlayerZ(playerid, Z);
Z += 0.1;
SetPlayerZ(playerid, Z);
return true;
}
SetCameraInFrontOfPlayer
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 ~
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 ::..........................*/
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;
}
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;
}
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;
}
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 ::...........................*/
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;
}
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;
}
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;
}
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 ~