02.11.2011, 16:06
Useful Snippets
05.11.2011, 16:19
This function will disable the player weapons in hand efficiently.
For avoid problems if the player weapons are forbiden, before of give a weapon for the player, toggle the player weapons, give the new weapons and forbid it again.
For avoid problems if the player weapons are forbiden, before of give a weapon for the player, toggle the player weapons, give the new weapons and forbid it again.
pawn Код:
new PlayerWeapons[MAX_PLAYERS][2][13]; //in the top
TogglePlayerWeapons(playerid, bool:toggle)
{
if(!toggle)
{
for(new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
if(PlayerWeapons[playerid][0][i]) GivePlayerWeapon(playerid, PlayerWeapons[playerid][0][i], - (PlayerWeapons[playerid][1][i] * 2) );
}
}
else
{
ResetPlayerWeapons(playerid);
for(new i = 0; i < 13; i++)
{
if(PlayerWeapons[playerid][0][i]) GivePlayerWeapon(playerid, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
}
}
return 1;
}
06.11.2011, 17:09
Anti Fake-Kill - 0.3d
pawn Код:
new
iLastDamage[MAX_PLAYERS];
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
if (damagedid != INVALID_PLAYER_ID)
{
iLastDamage[damagedid] = GetTickCount();
}
}
public OnPlayerDeath(playerid, killerid, reason)
{
if (killerid != INVALID_PLAYER_ID && (iLastDamage[playerid] + 2000) < GetTickCount())
{
static
szKickMessage[128],
szPlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
format(szKickMessage, 128, "* %s has been kicked because of doing a fake kill.", szPlayerName);
SendClientMessageToAll(-1, szKickMessage);
return Kick(playerid);
}
}
06.11.2011, 18:33
That will probably suffer a couple false-positives because the killer could be lead aiming each shot (using a deagle, for example), only hitting the player getting killed for him.
06.11.2011, 18:55
Sorry, but I cannot figure out what are you talking about. Could you please explain it further...?
06.11.2011, 19:50
OnPlayerGiveDamage is called when a player shoots another player *on their screen*, right? If someone is running around you in circles and you shoot ahead of the player you will hit him, but only *on his screen* (i.e. you won't see blood come out, but he'll lose damage).
Not only that, but if it were a 1-shot kill, and the shooter would be lagging, then the player that were shot will get kicked because the shooter didn't report to OnPlayerGiveDamage before the player that was shot reported OnPlayerDeath.
Not only that, but if it were a 1-shot kill, and the shooter would be lagging, then the player that were shot will get kicked because the shooter didn't report to OnPlayerGiveDamage before the player that was shot reported OnPlayerDeath.
07.11.2011, 15:40
I can now understand what you say, but not sure if it is 100% ok (needs further investigation).
If a player shoots somebody, the client sends a packet that he shot to a position. When this happens, SA-MP checks if there is a player on the position, and if so, fires up OnPlayerGiveDamage callback and inform the victim player about the shoot.
If a player shoots somebody, the client sends a packet that he shot to a position. When this happens, SA-MP checks if there is a player on the position, and if so, fires up OnPlayerGiveDamage callback and inform the victim player about the shoot.
05.01.2012, 20:33
Dynamic Object Creator
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/CreateObject", true) == 0)
{
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: {FF0000}/CreateObject [objectid]");
new Float:X,Float:Y,Float:Z,Float:A;
GetPlayerPos(playerid, X,Y,Z);
GetPlayerFacingAngle(playerid, A);
CreateObject(strval(tmp), X,Y,Z,0,0,A);
SendClientMessage(playerid,0xFFFFFFFF, "{33FF33}Object Created!");
return 1;
}
return 0;
}
01.03.2012, 21:18
Anti-Fake Kill. Needs more to it I guess but works.
There is a flaw with minigun, so make it admin immune or something.
pawn Code:
public OnPlayerDeath( playerid, killerid, reason )
{
if( IsPlayerConnected( killerid ) )
{
if( IsPlayerConnected( GetPVarInt( playerid, "LastKilled" ) ) && GetPVarInt( playerid, "LastKilled" ) == killerid )
{
if( ( GetPVarInt( playerid, "LastKilledTickcount" ) - GetTickCount( ) ) < 500 )
{
SetPVarInt( playerid, "LastKilledTick", GetPVarInt( playerid, "LastKilledTick" ) + 1 );
if( GetPVarInt( playerid, "LastKilledTick" ) > 1 ) Kick( playerid );
}
SetPVarInt( playerid, "LastKilledTickcount", GetTickCount( ) );
}
SetPVarInt( playerid, "LastKilled", killerid );
}
return 1;
}
03.03.2012, 05:03
(
Last edited by Jack_SMalls; 03/03/2012 at 04:07 PM.
)
Nevermind.
03.03.2012, 09:04
Quote:
pawn Code:
|
03.03.2012, 13:37
@Jack_SMalls DAFUQ?!
16.03.2012, 03:20
OnPlayerMovedCamera - The callback's 0.3e RC2 above Only
How to use(exemple)
pawn Код:
/*
*
* OnPlayerMovedCamera - Somente na versгo 0.3e RC2 ou superior.
*
* Crйditos: DarkScripter
* - Nгo retire os crйditos.
*
*
*/
new bool:Chamed_Int[MAX_PLAYERS char] = false;
forward _FinisOnPlayerMovedCamera(playerid);
forward OnPlayerMovedCamera(playerid);
public _FinisOnPlayerMovedCamera(playerid)
{
Chamed_Int{playerid} = false;
CallLocalFunction("OnPlayerMovedCamera", "d", playerid);
}
stock InterpolateCameraLookAt_(p, Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, time, style)
{
InterpolateCameraLookAt(p, Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, time, style);
return !Chamed_Int{p} ? (SetTimerEx("_FinisOnPlayerMovedCamera", time, false, "d", p), Chamed_Int{p} = true) : true;
}
stock InterpolateCameraPos_(p, Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, time, style)
{
InterpolateCameraPos(p, Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, time, style);
return !Chamed_Int{p} ? (SetTimerEx("_FinisOnPlayerMovedCamera", time, false, "d", p), Chamed_Int{p} = true) : true;
}
#define InterpolateCameraLookAt InterpolateCameraLookAt_
#define InterpolateCameraPos InterpolateCameraPos_
pawn Код:
#include <a_samp>
#define TIMER ( 60000 * 1 ) // time to move cam ( 1 minute )
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext,"/cam", true))
{
TogglePlayerSpectating(playerid, true);
InterpolateCameraLookAt(playerid, 2045.2523, 1689.3992, 10.3990 + 50, 1336.8778, -2271.4685, 13.1868 + 50, TIMER, CAMERA_MOVE);
InterpolateCameraPos(playerid, 2045.2523, 1689.3992, 10.3990 + 50, 1336.8778, -2271.4685, 13.1868 + 50, TIMER, CAMERA_MOVE);
return true;
}
if(!strcmp(cmdtext,"/b", true))
{
TogglePlayerSpectating(playerid, false);
SetCameraBehindPlayer(playerid);
return true;
}
return true;
}
public OnPlayerMovedCamera(playerid)
{
SendClientMessage(playerid, -1,"Arrived.");
return 1;
}
16.03.2012, 06:17
Quote:
OnPlayerMovedCamera - The callback's 0.3e RC2 above Only
pawn Код:
pawn Код:
|
18.03.2012, 02:19
its not much but is my addition..
some marcos to check a vehicle type,
it does not include every model because in my gm all other models will not have a job/objective tied to it.
might be usefull for a RPGM or the likes.,
tested and compiled!
usage
if there's a need for a version of this using stocks instead of marcos just ask as i have converted
all these from stocks.
some marcos to check a vehicle type,
it does not include every model because in my gm all other models will not have a job/objective tied to it.
might be usefull for a RPGM or the likes.,
tested and compiled!
pawn Код:
#define IsASemi(%0) ((%0) == 403 || (%0) == 514 || (%0) == 515 || (%0) == 443)
#define IsATrailor(%0) ((%0) == 435 || (%0) == 450 || (%0) == 584 || (%0) == 591 || (%0) == 606 || (%0) == 607 || (%0) == 608 || (%0) == 610 || (%0) == 611)
#define IsACopCar(%0) ((%0) == 523 || (%0) == 427 || (%0) == 490 || (%0) == 528 || (%0) == 596 || (%0) == 598 || (%0) == 597 || (%0) == 599 || (%0) == 601)
#define IsAMotorBike(%0) ((%0) == 462 || (%0) == 448 || (%0) == 581 || (%0) == 522 || (%0) == 461 || (%0) == 521 || (%0) == 523 || (%0) == 463 || (%0) == 586 || (%0) == 468)
#define IsABike(%0) ((%0) == 809 || (%0) == 481 || (%0) == 510)
#define IsAPizzaBike(%0) ((%0) == 448)
#define IsAFireTruck(%0) ((%0) == 407 || (%0) == 544)
#define IsATaxi(%0) ((%0) == 438 || (%0) == 420)
#define IsABus(%0) ((%0) == 431 || (%0) == 437)
#define IsAAmbulance(%0) ((%0) == 416)
#define IsALimo(%0) ((%0) == 409)
#define IsAPlane(%0) ((%0) == 460 || (%0) == 476 || (%0) == 511 || (%0) == 512 || (%0) == 513 || (%0) == 519 || (%0) == 520 || (%0) == 553 || (%0) == 577 || (%0) == 592 || (%0) == 593)
#define IsAHeli(%0) ((%0) == 542 || (%0) == 425 || (%0) == 417 || (%0) == 487 || (%0) == 488 || (%0) == 497 || (%0) == 563 || (%0) == 447 || (%0) == 469)
#define IsABoat(%0) ((%0) == 472 || (%0) == 473 || (%0) == 493 || (%0) == 595 || (%0) == 484 || (%0) == 430 || (%0) == 453 || (%0) == 452 || (%0) == 446 || (%0) == 454)
#define IsATrashTruck(%0) ((%0) == 408)
pawn Код:
if(IsASemi(vehiclemodelid)){/*code here*/}
all these from stocks.
19.03.2012, 22:04
Creating a "Strike" ability;
I'm aware this may not be the most efficient way to do things, but it works. For the purpose of this tutorial, I allow users to use the Strike ability against tanks only. Soo, let's get started.
Definitions
I know I really haven't explained anything, but this is why it's in the snippets thread, rather than a tutorial.
I'm aware this may not be the most efficient way to do things, but it works. For the purpose of this tutorial, I allow users to use the Strike ability against tanks only. Soo, let's get started.
Definitions
pawn Код:
#define MAX_TANKS 10
#define STRIKE_COOLDOWN 1 //I've defined this as one minute, however, you can change this as needed.
#define HOLDING(%0) \
((newkeys & (%0)) == (%0))
pawn Код:
new
StrikeCooldown[ MAX_PLAYERS ];
new
TanksSpawned = 0,
Tank[ MAX_TANKS ];
pawn Код:
//Tanks
Tank[ 0 ] = AddStaticVehicle( 432, 235.2255,17.2768,2.4297,143.3092, 3, 3 );
Tank[ 1 ] = AddStaticVehicle( 432, 212.7084,-21.6392,1.4297,94.7918, 3, 3 );
pawn Код:
public OnPlayerDisconnect( playerid, reason )
{
if( GetPVarInt( playerid, "ExpTank" ) == 1)
{
KillTimer( StrikeCooldown[ playerid ] );
}
return true;
}
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if( HOLDING( KEY_AIM ) )
{
if( GetPlayerWeapon( playerid ) == 43 )
{
new
Float: TankLoc[ 3 ];
for( new tk; tk < MAX_TANKS; tk ++ )
{
GetVehiclePos( Tank[ tk ], TankLoc[ 0 ], TankLoc[ 1 ], TankLoc[ 2 ] );
if( IsPlayerAimingAt( playerid, TankLoc[ 0 ], TankLoc[ 1 ], TankLoc[ 2 ], 3.0 ) )
{
if( GetPVarInt( playerid, "ExpTank" ) == 0 )
{
SetTimerEx( "ExplodeThatBitch", 5000, false, "ii", tk, playerid );
SendClientMessage( playerid, c_ORANGE, "Strike requested! Continue aiming at the Tank!" );
}
else return SendClientMessage( playerid, c_ORANGE, "You've recently called in an airstrike! Please wait 5 minutes." );
}
}
}
}
return true;
}
forward ExplodeThatBitch( TankID, playerid );
public ExplodeThatBitch( TankID, playerid )
{
new
Float: TankLoc[ 3 ],
String[ 128 ],
p_Name[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, p_Name, sizeof( p_Name ) );
for( new tk; tk < MAX_TANKS; tk ++ )
{
GetVehiclePos( Tank[ tk ], TankLoc[ 0 ], TankLoc[ 1 ], TankLoc[ 2 ] );
if( IsPlayerAimingAt( playerid, TankLoc[ 0 ], TankLoc[ 1 ], TankLoc[ 2 ], 3.0 ) )
{
CreateExplosion( TankLoc[ 0 ], TankLoc[ 1 ], TankLoc[ 2 ], 0, 10.0 );
format( String, sizeof( String ), "%s has called in a Strike!", p_Name );
SendClientMessageToAll( c_ORANGE, String );
SetPVarInt( playerid, "ExpTank", 1 );
StrikeCooldown[ playerid ] = SetTimerEx( "ResetCooldown", 60000*STRIKE_COOLDOWN, false, "i", playerid );
return true;
}
else
{
SendClientMessage( playerid, c_ORANGE, "Target not found!" );
SetPVarInt( playerid, "ExpTank", 0 );
return true;
}
}
return true;
}
forward ResetCooldown( playerid );
public ResetCooldown( playerid )
{
SetPVarInt( playerid, "ExpTank", 0 );
SendClientMessage( playerid, c_ORANGE, "You may now use your Strike capabilities!" );
return true;
}
pawn Код:
Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
new Float:TGTDistance;
TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
new Float:tmpX, Float:tmpY, Float:tmpZ;
tmpX = FrX * TGTDistance + CamX;
tmpY = FrY * TGTDistance + CamY;
tmpZ = FrZ * TGTDistance + CamZ;
return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius)
{
new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float:fz;
GetPlayerCameraPos(playerid, cx, cy, cz);
GetPlayerCameraFrontVector(playerid, fx, fy, fz);
return (radius >= DistanceCameraTargetToLocation(cx, cy, cz, x, y, z, fx, fy, fz));
}
//These are NOT my functions, although I'm not positive where they came from..
25.03.2012, 14:55
This one gives you 50 Health and 50 Armour
pawn Код:
stock FiftyFifty(playerid)
{
SetPlayerHealth(playerid,50)
SetPlayerArmour(playerid,50.0);
return 1;
}
27.03.2012, 21:25
Best "snippet" I've ever seen! :trolling
30.03.2012, 20:36
31.03.2012, 10:51
« Next Oldest | Next Newest »
Users browsing this thread: 2 Guest(s)