Re: Useful Functions -
ded - 24.12.2009
TelePlayerToPlayer
Код:
stock TeleportPlayerToPlayer(playerid, gotoID)
{
new Float: X, Float: Y, Float Z;
GetPlayerPos(gotoID,X,Y,Z);
if(IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z);
} else {
SetPlayerPos(playerid,X+2,Y,Z);
}
}
Re: Useful Functions -
yezizhu - 24.12.2009
Quote:
Originally Posted by » ραωпsтαг «
TelePlayerToPlayer
Код:
stock TeleportPlayerToPlayer(playerid, gotoID)
{
new Float: X, Float: Y, Float Z;
GetPlayerPos(gotoID,X,Y,Z);
if(IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z);
} else {
SetPlayerPos(playerid,X+2,Y,Z);
}
}
|
It's not a good idea that teleports the vehicle by the passenager
Re: Useful Functions -
ded - 24.12.2009
What? Why not ..
Re: Useful Functions -
heufix - 24.12.2009
Quote:
Originally Posted by » ραωпsтαг «
TelePlayerToPlayer
Код:
stock TeleportPlayerToPlayer(playerid, gotoID)
{
new Float: X, Float: Y, Float Z;
GetPlayerPos(gotoID,X,Y,Z);
if(IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z);
} else {
SetPlayerPos(playerid,X+2,Y,Z);
}
}
|
pawn Код:
stock TeleportPlayerToPlayer(playerid, gotoID)
{
new Float: X, Float: Y, Float Z;
GetPlayerPos(gotoID,X,Y,Z);
if(GetPlayerState(playerid) == 2) SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z);
else SetPlayerPos(playerid,X+2,Y,Z);
}
imho.
Re: Useful Functions -
LarzI - 24.12.2009
Quote:
Originally Posted by heufix
Quote:
Originally Posted by » ραωпsтαг «
TelePlayerToPlayer
Код:
stock TeleportPlayerToPlayer(playerid, gotoID)
{
new Float: X, Float: Y, Float Z;
GetPlayerPos(gotoID,X,Y,Z);
if(IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z);
} else {
SetPlayerPos(playerid,X+2,Y,Z);
}
}
|
pawn Код:
stock TeleportPlayerToPlayer(playerid, gotoID) { new Float: X, Float: Y, Float Z; GetPlayerPos(gotoID,X,Y,Z); if(GetPlayerState(playerid) == 2) SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z); else SetPlayerPos(playerid,X+2,Y,Z); }
imho.
|
pawn Код:
stock TeleportPlayerToPlayer(playerid, gotoID)
{
new Float: X, Float: Y, Float Z;
GetPlayerPos(gotoID,X,Y,Z);
if(GetPlayerState(playerid) == 2 || GetPlayerState(playerid) == 3) SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z+0.2);
else SetPlayerPos(playerid,X+2,Y,Z0.2);
}
imo
Re: Useful Functions -
ded - 24.12.2009
Depends how you like it .. all works the same way.
Re: Useful Functions -
Calon - 24.12.2009
IsPlayerInRangeOfVehicle
pawn Код:
public IsPlayerInRangeOfVehicle(playerid, vehicleid, radius)
{
new Float: CarPpX, Float: CarPpY, Float: CarPpZ;
GetVehiclePos(playerid, CarPpX, CarPpY, CarPpZ);
if(IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ))
{
return 1;
}
else
{
return 0;
}
}
NearByMessage
pawn Код:
public NearByMessage(playerid, color, string[], Float: range)
{
new Float: PlayerX, Float: PlayerY, Float: PlayerZ;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerPos(playerid, PlayerX, PlayerY, PlayerZ);
if(IsPlayerInRangeOfPoint(i, range, PlayerX, PlayerY, PlayerZ))
{
if(GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))
{
SendClientMessage(i, color, string);
}
}
}
}
}
RespawnVehicles
pawn Код:
public MassRespawn()
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
SetVehicleToRespawn(i);
}
}
SecondsToMinutes and MinutesToSeconds (not very useful, as you can simply use the sum every single math calculation):
pawn Код:
public MinutesToSeconds(minutes)
{
return minutes*60;
}
public SecondsToMinutes(seconds)
{
return seconds/60;
}
Re: Useful Functions -
Google63 - 24.12.2009
Quote:
Originally Posted by Calon
IsPlayerInRangeOfVehicle
pawn Код:
public IsPlayerInRangeOfVehicle(playerid, vehicleid, radius) { new Float: CarPpX, Float: CarPpY, Float: CarPpZ; GetVehiclePos(playerid, CarPpX, CarPpY, CarPpZ); if(IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ)) { return 1; } else { return 0; } }
|
Isn't it easier to do just
return IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ);
It will throw same result and it's more readable, people will laugh at you if you continue to do like that.
Re: Useful Functions - my Teleport System -
[HUN]Gamestar - 24.12.2009
http://forum.sa-mp.com/index.php?topic=140719.0
---
pawn Код:
stock CountConnectedPlayers() {
new ZeX_count=0;
for(new ZeX_i=0;ZeX_i<GetMaxPlayers();ZeX_i++)if(IsPlayerConnected(ZeX_i))ZeX_count++;
return ZeX_count;
}
Re: Useful Functions -
pspleo - 25.12.2009
Quote:
Originally Posted by JoeBullet
Quote:
Originally Posted by Calon
IsPlayerInRangeOfVehicle
pawn Код:
public IsPlayerInRangeOfVehicle(playerid, vehicleid, radius) { new Float: CarPpX, Float: CarPpY, Float: CarPpZ; GetVehiclePos(playerid, CarPpX, CarPpY, CarPpZ); if(IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ)) { return 1; } else { return 0; } }
|
Isn't it easier to do just return IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ);
It will throw same result and it's more readable, people will laugh at you if you continue to do like that.
|
And also, why not stock? You don't need any forward then. Oh, but then you can't do SetTimer(IsPlayerInRangeOfVehicle)...
Leo
Re: Useful Functions -
Calon - 25.12.2009
Quote:
Originally Posted by JoeBullet
Quote:
Originally Posted by Calon
IsPlayerInRangeOfVehicle
pawn Код:
public IsPlayerInRangeOfVehicle(playerid, vehicleid, radius) { new Float: CarPpX, Float: CarPpY, Float: CarPpZ; GetVehiclePos(playerid, CarPpX, CarPpY, CarPpZ); if(IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ)) { return 1; } else { return 0; } }
|
Isn't it easier to do just return IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ);
It will throw same result and it's more readable, people will laugh at you if you continue to do like that.
|
Well, not really. As you don't seem like the smartest of the apple in the fruit basket, it returns 1 if they're in range of the vehicle and 0 if they're not, it's not returning the radius result.
Re: Useful Functions -
dice7 - 25.12.2009
Quote:
Originally Posted by Calon
Quote:
Originally Posted by JoeBullet
Quote:
Originally Posted by Calon
IsPlayerInRangeOfVehicle
pawn Код:
public IsPlayerInRangeOfVehicle(playerid, vehicleid, radius) { new Float: CarPpX, Float: CarPpY, Float: CarPpZ; GetVehiclePos(playerid, CarPpX, CarPpY, CarPpZ); if(IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ)) { return 1; } else { return 0; } }
|
Isn't it easier to do just return IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ);
It will throw same result and it's more readable, people will laugh at you if you continue to do like that.
|
Well, not really. As you don't seem like the smartest of the apple in the fruit basket, it returns 1 if they're in range of the vehicle and 0 if they're not, it's not returning the radius result.
|
Yes, and returning a function means it will get executed, so the true/false returning will be done by IsPlayerInRangeOfPoint
Re: Useful Functions -
LarzI - 25.12.2009
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, radius, CarPpX, CarPpY, CarPpZ))
{
return 1;
}
else
{
return 0;
}
That practically does:
If the function IsPlayerInRangeOfPoint with arguments: playerid, radius, CarPpX, CarPpY and CarPpZ returns true, then return 1
Else (If the function IsPlayerInRangeOfPoint with arguments: playerid, radius, CarPpX, CarPpY and CarPpZ returns false), then return 0
So if you return the function, that will return whatever the function does (either true or false).
Re: Useful Functions -
Oxside - 25.12.2009
Код:
stock JailPlayer(playerid)
{
SetPlayerPos(id, 197.6661,173.8179,1003.0234);
SetPlayerInterior(id, 3);
}
stock UnJailPlayer(playerid)
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
}
Re: Useful Functions -
MJ! - 25.12.2009
Quote:
Originally Posted by .:: ZeX ::.
pawn Код:
stock IsFindIp(str[]) { new x=0,n=0,p=0; while(str[x]!=strlen(str)) { if((str[x]>='0') && (str[x]<='9'))n++; if(str[x]=='.')p++; x++; } return ((n>=4)&&(p>=3)) ? true : false; }
Example:
pawn Код:
public OnPlayerText(playerid,text[])if(IsFindIp(text))return 0;
|
Ok , i've noticed somethnig ...
Never an ip can't have the lenght lower than 8 (1.1.1.1) ...
And never 3 digits near dot can't be higher than 255
Am i right ?
So this must be something like this:
pawn Код:
stock IsFindIp(str[])
{
new nn,x,n,p;
while(str[x] != strlen(str))
{
if(nn > 255) return 0;
else nn = 0;
if((str[x] >= '0') && (str[x]<='9')) n++,nn++;
if(str[x] == '.') p++;
x++;
}
return ((n>=8)&&(p>=3)) ? true : false;
}
Re: Useful Functions -
LarzI - 25.12.2009
GetDriverID(vehicleid)
vehicleid -
ID of the vehicle you want to return the driver's playerid from
pawn Код:
stock GetDriverID(vehicleid)
{
for( new i = 0; i < MAX_PLAYERS; i++ )
{
if( GetPlayerState( i ) == PLAYER_STATE_DRIVER && GetPlayerVehicleID( i ) == vehicleid )
return i;
}
return INVALID_PLAYER_ID;
}
Re: Useful Functions -
yezizhu - 26.12.2009
Quote:
Originally Posted by lrZ^ aka LarzI
GetDriverID(vehicleid)
vehicleid - ID of the vehicle you want to return the driver's playerid from
pawn Код:
stock GetDriverID(vehicleid) { for( new i = 0; i < MAX_PLAYERS; i++ ) { if( GetPlayerState( i ) == PLAYER_STATE_DRIVER && GetPlayerVehicleID( i ) == vehicleid ) return i; } return INVALID_PLAYER_ID; }
|
Loop is not a good choice.
Re: Useful Functions -
[HiC]TheKiller - 26.12.2009
GetHigestValueInVariable
GetHigestValueInVariable - A long name, Yes but it's better in explaining it. It finds the highest value in a variable such as
It will return the person with the most kills.
GetHigestValueInVariable(
VarName,
Length)
VariableName - The variable that you want to find the highest value of
Length - The size of the variable
pawn Код:
GetHigestValueInVariable(VarName[], XLength)
{
new HighestNumber;
for(new i=0;i<XLength;i++)
{
if(VarName[i] > VarName[HighestNumber])
{
HighestNumber = i;
}
}
return HighestNumber;
}
The usage for this would be:
pawn Код:
new Kills[MAX_PLAYERS];
public OnPlayerDeath(playerid, killerid, reason)
{
Kills[killerid] ++;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp("/MostKills", cmdtext) == 0)
{
new String[135];
new Pname[24];
GetPlayerName(GetHigestValueInVariable(Kills, 500), Pname, 24);
format(String, sizeof(String), "%s(%d) has the highest kills with %d kills!", Pname, GetHigestValueInVariable(Kills, 500), Kills[GetHigestValueInVariable(Kills, 500)]);
SendClientMessage(playerid, 0x33CCCC, String);
return 1;
}
return 0;
}
I wasn't sure that this would work but it works with
this test code.
Re: Useful Functions -
M4S7ERMIND - 28.12.2009
Quote:
Originally Posted by Mастерминд
Long long time ago, I made a function.. and the time has come to release it.
pawn Код:
stock DecimalPoint(money) { new str[16]; if(money >= 0) { format(str, sizeof(str), "$%d", money); if(1000 <= money < 10000) strins(str, ".", 2, sizeof(str)); else if(10000 <= money < 100000) strins(str, ".", 3, sizeof(str)); else if(100000 <= money < 1000000) strins(str, ".", 4, sizeof(str)); else if(1000000 <= money < 10000000) { strins(str, ".", 2, sizeof(str)); strins(str, ".", 6, sizeof(str)); } else if(10000000 <= money < 100000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); } else if(100000000 <= money < 1000000000) { strins(str, ".", 4, sizeof(str)); strins(str, ".", 8, sizeof(str)); } else if(money >= 1000000000) { strins(str, ".", 2, sizeof(str)); strins(str, ".", 6, sizeof(str)); strins(str, ".", 10, sizeof(str)); } } else { format(str, sizeof(str), "-$%d", money-(money*2)); if(-1000 >= money > -10000) strins(str, ".", 3, sizeof(str)); else if(-10000 >= money > -100000) strins(str, ".", 4, sizeof(str)); else if(-100000 >= money > -1000000) strins(str, ".", 5, sizeof(str)); else if(-1000000 >= money > -10000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); } else if(-10000000 >= money > -100000000) { strins(str, ".", 4, sizeof(str)); strins(str, ".", 8, sizeof(str)); } else if(-100000000 >= money > -1000000000) { strins(str, ".", 5, sizeof(str)); strins(str, ".", 9, sizeof(str)); } else if(money <= -1000000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); strins(str, ".", 11, sizeof(str));} } return str; }
Usage:
pawn Код:
new str[40]; format(str, sizeof(str), "Your money: %s.", DecimalPoint(GetPlayerMoney(playerid))); SendClientMessage(playerid, WHITE, str);
(Note: it returns a string, so it must always be %s)
The max string it returns is -$2.147.483.647 (16 cells).
..I made that function real long time ago, when I was a beginner
|
my Macros & functions -
_[HuN]_Epsilon_ - 28.12.2009
// SetServerMap("map name")
#define SetServerMap(%1) SendRconCommand("mapname "%1)
// SpeakAdmin("message")
#define SpeakAdmin(%1) SendRconCommand("say "%1)
// RestartSRV()
#define RestartSRV() SendRconCommand("gmx")
// LoadFilterScript(fs name)
#define LoadFilterScript(%1) SendRconCommand("loadfs" %1)
// ReloadFilterScript(fs name)
#define ReloadFilterScript(%1) SendRconCommand("reloadfs" %1)
// UnloadFilterScript(fs name)
#define UnloadFilterScript(%1) SendRconCommand("unloadfs" %1)
// GetServerMap(variable)
#define GetServerMap(%1) GetServerVarAsString("mapname",%1,sizeof(%1))
// GetServerName(variable)
#define GetServerName(%1) GetServerVarAsString("hostname",%1,sizeof(%1))
// GetServerRcon(variable)
#define GetServerRcon(%1) GetServerVarAsString("rcon_password",%1,sizeof(%1) )
// GetServerSite(variable)
#define GetServerSite(%1) GetServerVarAsString("weburl",%1,sizeof(%1))
// TelePlayerToPlayer(teleid,destid)
#define TelePlayerToPlayer(%1, %2) \
new Float: p[3]; \
GetPlayerPos(%2,X,Y,Z);\
if(GetPlayerState(%1)-1) SetVehiclePos(GetPlayerVehicleID(%1),p[0],p[1]+2.5,p[2]); else SetPlayerPos(%1,p[0],p[1]+2.5,p[2]);
// TakePlayerHealth(playerid,health) /* GetHealth function needed! */
#define TakePlayerHealth(%1,%2) SetPlayerHealth((%1,floatsub(GetHealth(%1),%2))
// GivePlayerHealth(playerid,health) /* GetHealth function needed! */
#define GivePlayerHealth(%1,%2) SetPlayerHealth((%1,floatadd(GetHealth(%1),%2))
// TakePlayerArmour(playerid,health) /* GetArmour function needed! */
#define TakePlayerArmour(%1,%2) SetPlayerArmour((%1,floatsub(GetArmour(%1),%2))
// GivePlayerArmour(playerid,health) /* GetArmour function needed! */
#define GivePlayerArmour(%1,%2) SetPlayerArmour(%1,floatadd(GetArmour(%1),%2))
pawn Код:
Float: GetHealth(id)
{
new Float: pp;
GetPlayerHealth(id,pp);
return pp;
}
Float: GetArmour(id)
{
new Float: pp;
GetPlayerArmour(id,pp);
return pp;
}
Epsilon