12.09.2010, 09:22
(
Last edited by miokie; 12/09/2010 at 06:40 PM.
)
Before we start with this tutorial; We're going to need the following Include:
https://sampforum.blast.hk/showthread.php?tid=105568 - (a_Angles)
Okay, Now that is sorted let's continue with the tutorial.
Things to define:
This is defining keys pressed as we are going to be using OnPlayerKeyStateChange.
We will use the following stock to gain the players ID from their name: (I did not write this)
Next go down to OnPlayerKeyStateChange and create the two keys we're going to be using, The Shooting key and the aiming key:
Next we're going to define and get some infomation we need, Place this in OnPlayerKeyStateChange:
Now we're going to see if we are close enough to the NPC for it to react using IsPlayerInRangeOfPoint:
Time to check if your weapon is a gun:
Now it's time to check you are facing the NPC. (This is where the include comes in...)
Now we're going to add the reactions to the aiming and shooting:
Done!
______________________________________Notes and other things:______________________________________
Idle NPC Definition: One without a recorded walking/driving path.
https://sampforum.blast.hk/showthread.php?tid=105568 - (a_Angles)
Okay, Now that is sorted let's continue with the tutorial.
Things to define:
pawn Code:
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
We will use the following stock to gain the players ID from their name: (I did not write this)
pawn Code:
stock GetPlayerIDFromName(const playername[], partofname=0)
{
new i;
new playername1[64];
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,playername1,sizeof(playername1));
if (strcmp(playername1,playername,true)==0)
{
return i;
}
}
}
new correctsigns_userid=-1;
new tmpuname[128];
new hasmultiple=-1;
if(partofname)
{
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,tmpuname,sizeof(tmpuname));
if(!strfind(tmpuname,playername1[partofname],true, 0))
{
hasmultiple++;
correctsigns_userid=i;
}
if (hasmultiple>0)
{
return -2;
}
}
}
}
return correctsigns_userid;
}
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_FIRE)) //Checks if the player is using the fire gun key.
{
}
if(PRESSED(KEY_HANDBRAKE)) //checks if the player is using the aim guy key.
{
}
return 1;
}
pawn Code:
new NPCID = GetPlayerIDFromName("NPC"); //Gets the NPC's ID and puts it into something easily usable.
//Note: Replace 'NPC' with your NPC's name.
new wid = GetPlayerWeapon(playerid); //Gets the players weapon which is going to be used to aim and shoot.
new Float:x,Float:y,Float:z; //Defines X,Y,Z
GetPlayerPos(NPCID,x,y,z); //Gets the NPC's Position.
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new NPCID = GetPlayerIDFromName("NPC");
new wid = GetPlayerWeapon(playerid);
new Float:x,Float:y,Float:z;
GetPlayerPos(NPCID,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,15,x,y,z)) //Checking if you're near the NPC
{
if(PRESSED(KEY_FIRE))
{
}
if(PRESSED(KEY_HANDBRAKE))
{
}
}
return 1;
}
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new NPCID = GetPlayerIDFromName("NPC");
new wid = GetPlayerWeapon(playerid);
new Float:x,Float:y,Float:z;
GetPlayerPos(NPCID,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,15,x,y,z))
{
if(PRESSED(KEY_FIRE))
{
if(wid > 10) //Is the weapon you're using a gun?
{
}
}
if(PRESSED(KEY_HANDBRAKE))
{
if(wid > 10) //Is the weapon you're using a gun?
{
}
}
}
return 1;
}
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new NPCID = GetPlayerIDFromName("NPC");
new wid = GetPlayerWeapon(playerid);
new Float:x,Float:y,Float:z;
GetPlayerPos(NPCID,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,15,x,y,z))
{
if(PRESSED(KEY_FIRE))
{
if(wid > 10)
{
if(IsPlayerFacingPlayer(playerid,NPCID,10) == 1) //Self explanitory
{
}
else if(IsPlayerFacingPlayer(playerid,NPCID,10) == 0)//Self explanitory
{
}
}
}
if(PRESSED(KEY_HANDBRAKE))
{
if(wid > 10)
{
if(IsPlayerFacingPlayer(playerid,NPCID,10) == 1)//Self explanitory
{
}
else if(IsPlayerFacingPlayer(playerid,NPCID,10) == 0)//Self explanitory
{
}
}
}
}
return 1;
}
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new NPCID = GetPlayerIDFromName("NPC");
new wid = GetPlayerWeapon(playerid);
new Float:x,Float:y,Float:z;
GetPlayerPos(NPCID,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,15,x,y,z))
{
if(PRESSED(KEY_FIRE))
{
if(wid > 10)
{
if(IsPlayerFacingPlayer(playerid,NPCID,10) == 1)
{
ApplyAnimation(NPCID,"CRACK","crckdeth4",3.0,0,0,0,1,0);
SetPlayerChatBubble(NPCID,"Ouch!",0xFFFFFFAA,50,5000);
}
else if(IsPlayerFacingPlayer(playerid,NPCID,10) == 0)
{
SetPlayerChatBubble(NPCID,"Don't Shoot near me!",0xFFFFFFAA,50,5000);
}
}
}
if(PRESSED(KEY_HANDBRAKE))
{
if(wid > 10)
{
if(IsPlayerFacingPlayer(playerid,NPCID,10) == 1)
{
ApplyAnimation(NPCID,"ped","handsup",3.0,0,0,0,1,0);
SetPlayerChatBubble(NPCID,"Please Don't Shoot me!",0xFFFFFFAA,50,5000);
}
else if(IsPlayerFacingPlayer(playerid,NPCID,10) == 0)
{
SetPlayerChatBubble(NPCID,"Watch where you are aiming that gun!",0xFFFFFFAA,50,5000);
}
}
}
}
return 1;
}
______________________________________Notes and other things:______________________________________
Idle NPC Definition: One without a recorded walking/driving path.