Useful Snippets

Anti Drive By + Blocks weapons if there synced from the SA-MP bug.

pawn Код:
public OnPlayerUpdate(playerid)
{
  if(!IsPlayerConnected(playerid)) return 0;

  new gun = GetPlayerWeapon(playerid);

  if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
    if(gun == 28 || gun == 29 || gun == 32)
    {
      SetPlayerArmedWeapon(playerid,0);
      return 0;
    }
  }

  return 1;
}
Reply

Quote:
Originally Posted by FreshKilla [PR-RP
]
Anti Drive By + Blocks weapons if there synced from the SA-MP bug.
There have been better versions of anti drive by in 0.2 (it just needed some storage)
the only improvement is the new function SetPlayerArmedWeapon
Reply

Useful macros:

Код:
#define isEven(%1) \
        (!((%1)&(01)))
Код:
 
#define isPowerOfTwo(%1) \
        (!(%1)&(%1-1))
Reply

Updated RcVehicles system 0.3 samp version.

Код:
IsVehicleRc(vehicleid)
{
  	switch(GetVehicleModel(vehicleid)){
		case 441, 464, 465, 501, 564, 594: return true;
	}
	return false;
}
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	new
		Float:x,
		Float:y,
		Float:z;
	if(newkeys == KEY_SECONDARY_ATTACK )
	{
		new VehicleSeat = GetPlayerVehicleSeat(playerid);
		if(VehicleSeat == -1)
		{
			for(new forvehicleid; forvehicleid < MAX_VEHICLES; forvehicleid++)
			{
				if(!IsVehicleRc(forvehicleid)) continue;
				GetVehiclePos(forvehicleid, x, y, z);
				if(IsPlayerInRangeOfPoint(playerid, 6, x, y, z))
				{
					PutPlayerInVehicle(playerid, forvehicleid, 0);
					break;
				}
			}
		}
		else if(VehicleSeat == 0)
		{
			if(IsVehicleRc(GetPlayerVehicleID(playerid)))
			{
				GetPlayerPos(playerid, x, y, z);
				SetPlayerPos(playerid, x+1, y, z+1.0);
			}
		}
	}
	if(newkeys == KEY_FIRE || newkeys == 12 || newkeys == 36)
	{
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 564)
		{
			new Float:angle;
			GetPlayerPos(playerid,x,y,z);
			GetVehicleZAngle(GetPlayerVehicleID(playerid), angle);
			x += (30 * floatsin(-angle + 5, degrees));
			y += (30 * floatcos(-angle + 5, degrees));
			CreateExplosion(x,y,z,3,4.0);
		}
	}
	return 1;
}
Reply

Anti Non-RP Car jack, Ideal for RP servers.

pawn Код:
if(!ispassenger)
  {
    for(new i=0; i<MAX_PLAYERS; i++)
    {
      if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER)
      {
        new Float:cx, Float:cy, Float:cz;
        GetPlayerPos(playerid, cx, cy, cz);
        SetPlayerPos(playerid, cx, cy, cz);
        SendClientMessage(playerid,COLOR_GREY," Someone is driving this vehicle, You must take it Properly !");
      }
    }
  }
Reply

where do i have tho place that code freshkilla ?
Reply

Quote:
Originally Posted by radi
where do i have tho place that code freshkilla ?
OnPlayerEnterVehicle-callback.
Reply

itґs not from me, but this is cool:

Код:
if(strcmp(cmd, "/haha", true) == 0)
 {
 new player;
 tmp = strtok(cmdtext, idx);
 if(!strlen(tmp))
 {
  SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /haha [playerid]");
 }
 
 player = ReturnUser(tmp);
 if (player == playerid)
 {
  SendClientMessage(player, COLOR_RED, "You canґt laugh at yourself!");
  return 1;
 }
 if(IsPlayerConnected(player))
 {
   if(player != INVALID_PLAYER_ID)
   {
   new string[128];
  GetPlayerName(playerid, sendername, sizeof(sendername));
  format(string, sizeof(string), "* %s laughs at you!", sendername);
  SendClientMessage(playerid,COLOR_RED,string);
  }
  }
		return 1;
		}
Reply

Код:
if(strcmp(cmd, "/haha", true) == 0)
 {
 new player = ReturnUser(tmp);
 tmp = strtok(cmdtext, idx);
 if(!strlen(tmp)) SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /haha [playerid]");
 if (player == playerid) return SendClientMessage(player, COLOR_RED, "You canґt laugh at yourself!");
 if(!IsPlayerConnected(player)) return SendClientMessage(playerid,COLOR_RED,"Invalid Playerid");
  new string[128];
  GetPlayerName(playerid, sendername, sizeof(sendername));
  format(string, sizeof(string), "* %s laughs at you!", sendername);
  SendClientMessage(playerid,COLOR_RED,string);
    return 1;
    }
Reply

This is wrong, this will get the name of the player who used the command and it will send the message to him.
Reply

get the absolute value

Код:
forward fabs(a);
forward Float:ffabs(Float:a);
public fabs(a)//int
{
if(a<0)return -a;
else return a;
}
public Float:ffabs(Float:a)//float(for position,health etc.)
{
if(a<0)return -a;
else return a;
}
Reply

absolute to add/minus a value,uses for x,y,z 's value ++

Код:
forward fadd(a,value);
forward Float:ffadd(Float:a,Float:value);

public fadd(a,value)//int
{
if(a<0)return a-value;
else return a+value;
}
public Float:ffadd(Float:a,Float:value)//float(for position,health etc.)
{
if(a<0)return a-b;
else return a+b;
}
Reply

kymsar, there are already natives who do that -> Scripting Functions Old
they can be founded in the file "float.inc", too
Reply

Quote:
Originally Posted by FreshKilla [PR-RP
]
Anti Drive By + Blocks weapons if there synced from the SA-MP bug.

pawn Код:
public OnPlayerUpdate(playerid)
{
  if(!IsPlayerConnected(playerid)) return 0;

  new gun = GetPlayerWeapon(playerid);

  if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
    if(gun == 28 || gun == 29 || gun == 32)
    {
      SetPlayerArmedWeapon(playerid,0);
      return 0;
    }
  }

  return 1;
}
But it doesn't return the weapons to the player right?
Reply

Quote:
Originally Posted by RoamPT
But it doesn't return the weapons to the player right?
it never takes the weapon away
Reply

Quote:
Originally Posted by kymsar
absolute to add/minus a value,uses for x,y,z 's value ++

Код:
forward fadd(a,value);
forward Float:ffadd(Float:a,Float:value);

public fadd(a,value)//int
{
if(a<0)return a-value;
else return a+value;
}
public Float:ffadd(Float:a,Float:value)//float(for position,health etc.)
{
if(a<0)return a-b;
else return a+b;
}
Or just use + and - ?
Reply

/WhereAmI
Gives your location/coordinates X Y Z and facing angle

it also display them in the host console

Код:
	if(strcmp(cmdtext, "/whereami", true) == 0 && IsPlayerAdmin(playerid))
	{
		new Float:px, Float:py, Float:pz;
		GetPlayerPos(playerid, px, py, pz);
		new wherestringx[30];
		new wherestringy[30];
		new wherestringz[30];
		format(wherestringx,sizeof(wherestringx),"** Position: X: %f **", px);
		format(wherestringy,sizeof(wherestringy),"** Position: Y: %f **", py);
		format(wherestringz,sizeof(wherestringz),"** Position: Z: %f **", pz);
        SendClientMessage(playerid, COLOR_WHITE, "Your Coordinate are also display in host console");
		SendClientMessage(playerid, COLOR_WHITE, wherestringx);
		SendClientMessage(playerid, COLOR_WHITE, wherestringy);
		SendClientMessage(playerid, COLOR_WHITE, wherestringz);
		print(wherestringx);
		print(wherestringy);
		print(wherestringz);
		return 1;

	}
Reply

Quote:
Originally Posted by [KMA
Lord_Deji ]
/WhereAmI
Gives your location/coordinates X Y Z and facing angle

it also display them in the host console

Код:
	if(strcmp(cmdtext, "/whereami", true) == 0 && IsPlayerAdmin(playerid))
	{
		new Float:px, Float:py, Float:pz;
		GetPlayerPos(playerid, px, py, pz);
		new wherestringx[30];
		new wherestringy[30];
		new wherestringz[30];
		format(wherestringx,sizeof(wherestringx),"** Position: X: %f **", px);
		format(wherestringy,sizeof(wherestringy),"** Position: Y: %f **", py);
		format(wherestringz,sizeof(wherestringz),"** Position: Z: %f **", pz);
        SendClientMessage(playerid, COLOR_WHITE, "Your Coordinate are also display in host console");
		SendClientMessage(playerid, COLOR_WHITE, wherestringx);
		SendClientMessage(playerid, COLOR_WHITE, wherestringy);
		SendClientMessage(playerid, COLOR_WHITE, wherestringz);
		print(wherestringx);
		print(wherestringy);
		print(wherestringz);
		return 1;

	}
Hi.

pawn Код:
if(strcmp(cmdtext, "/whereami", true) == 0 && IsPlayerAdmin(playerid))
{
    new Float:px, Float:py, Float:pz, wherestringxyz[100];
    GetPlayerPos(playerid, px, py, pz);
    format(wherestringxyz,sizeof(wherestringxyz),"** Position X: %f Position Y: %f Position Z: %f **", px, py, pz);
    SendClientMessage(playerid, COLOR_WHITE, wherestringxyz);
    print(wherestringxyz);
    return 1;
}
SMF sucks at indenting.
Reply

Quote:
Originally Posted by [KMA
Lord_Deji ]
/WhereAmI
Gives your location/coordinates X Y Z and facing angle

it also display them in the host console
(oops old code for lines)
edited
Код:
	if(strcmp(cmdtext, "/whereami", true) == 0 && IsPlayerAdmin(playerid))
	{
		new Float:px, Float:py, Float:pz;
		new Float:A;
		GetPlayerPos(playerid, px, py, pz);
		GetPlayerFacingAngle(playerid, A);
		new wherestringx[30];
		new wherestringy[30];
		new wherestringz[30];
		new wherestringA[30];
		format(wherestringx,sizeof(wherestringx),"** Position: X: %f **", px);
		format(wherestringy,sizeof(wherestringy),"** Position: Y: %f **", py);
		format(wherestringz,sizeof(wherestringz),"** Position: Z: %f **", pz);
		format(wherestringA,sizeof(wherestringA),"** FacingAngle: %f **", A);
        SendClientMessage(playerid, COLOR_WHITE, "Your Coordinate are also display in host console");
		SendClientMessage(playerid, COLOR_WHITE, wherestringx);
		SendClientMessage(playerid, COLOR_WHITE, wherestringy);
		SendClientMessage(playerid, COLOR_WHITE, wherestringz);
		SendClientMessage(playerid, COLOR_WHITE, wherestringA);
		print(wherestringx);
		print(wherestringy);
		print(wherestringz);
		print(wherestringA);
		return 1;

	}
dammit i clicked on quote instead of modify -.-
Reply

Hide player blips on entering interiors
I'm not sure if it should be posted here or elsewhere as it's not an include or filterscript.
Just a proof-of-concept, which could be possibly modified or enhaced to fit one's needs.
It can be put either in FS or GM.


The thing is that if You enter certain interior and do not change the virtual world, Your blip will be still seen by other players and it will most likely be missplaced.

This tiny piece of code is ought to hide Your blip on entering interiors and re-show it when getting out.

Код:
// Hide player blips on entering interiors fix for samp 0.3

new gPlayerOldColor[MAX_PLAYERS];  // temp var if we need to change the color for a sec
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid) {

	// Entering interiors: hide player blip
	if(oldinteriorid == 0) {

	  gPlayerOldColor[playerid] = GetPlayerColor(playerid);
	  SetPlayerColor(playerid, ( gPlayerOldColor[playerid] & 0xFFFFFF00 ));
	}

	// Leaving interiors: restore player blip
	else if(newinteriorid == 0) SetPlayerColor(playerid, gPlayerOldColor[playerid]);

	return true;
}
Or use the pastebin link here: http://pastebin.com/f2ea7ab9a

It has a small bug, which re-enables the blip while player's char is still playing their "getting out of the interior" anim, so the blip will be missplaced on leaving interiors for a sec or two. It can be easily solved with timers, but i was too lazy... ;]

Also be carefull if Your gamemode/scripts has some other invisibility-applying functions as they may possibly colide with this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)