[Include] [INC]IsPlayerLookingAtPoint and others
#1

This is a function include that has a few functions to help make things better. As of right now it's pretty small but contains some pretty useful things to help renovate your gamemode. I shall maintain this include and add anything people would be interested in having on their server. It's kind of a 'Make It Comfortable' include, but these are slightly more useful and are optimized to the best of my abilties.

Functions

SavePVars(playerid) and LoadPVars(playerid)
This function will save every 'PVar' that has been assigned to the player without discrimination. This, in combination with LoadPVars, means you can have a player come and go and be right where he was when he left. Even if he was on the losing team of a fight or rotting in jail.
pawn Код:
public OnPlayerConnect(playerid)
{
  LoadPVars(playerid);
  if(GetPVarInt(playerid,"JailTime")>0)
  {
    SendtoJail(playerid);
    SendClientMessage(playerid,0xFF0000FF,"Finish your jail sentence!");
  }
  return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
  SavePVars(playerid);
  return 1;
}
*Removed/Changed -- v1.0 only
IsPlayerLookingAtPoint(playerid,Float:X,Float:Y,Fl oat:Z,Float:ViewWidth,Float:ViewHeight);
This major function The real reason why I even wanted to post this include =p is used to determine weither or not a player is looking at a position.

Using your head as an aiming scope (right about where the eyes are) this function will return 1 if what you're looking at the position.

ViewWidth and ViewHeight are used as a view cone from the player's head to decrease required accuracy with the aim. I find that 22.5 degrees (45 degrees from left to right) is a fair enough view cone for width (horizontal), and 10 degrees (20 degrees top to bottom) is good for height (vertical)

With this you can tell if someone head shots an NPC!

pawn Код:
public OnPlayerKeyStateChange(playerid,newstate,oldstate)
{
  if(newstate==KEY_SECONDARY_ATTACK)
  {
    if(IsPlayerInRangeOfPoint(playerid,2.0,1.234,5.678,9.0))
    {
      if(IsPlayerLookingAtPoint(playerid,1.234,5.678,9.0,22.5,10.0))
      {
        OpenLSPDGate();
        SendClientMessage(playerid,0xFFFFFFFF,"Gate opened!");
      }
    }
  }
  return 1;
}
*New v1.1 and up
IsPlayerLookingAtPlayer(playerid,playerid2);
This returns 1 if the player is looking at playerid2. Unfortunately, because of the offset that the reticle is at, it's only accurate if based on the center of the screen (right where the player's head is, generally)

Hopefully, the following script will show the player's health in green when looking at that player
pawn Код:
forward PlayerHUDUpdate();
public OnGameModeInit()
{
  SetTimer("PlayerHUDUpdate",500,1);
  return 1;
}
public OnPlayerConnect(playerid)
{
  SetPVarInt(playerid,"HUDTEXT",_:CreatePlayer3DTextLabel(playerid,"blank",0xFF,0.0,0.0,0.0,20.0,-1));
  return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
  DeletePlayer3DTextLabel(playerid,PlayerText3D:GetPVarInt(playerid,"HUDTEXT"));
  return 1;
}
public PlayerHUDUpdate()
{
  new tmpstr[6];
  new Float:HP;
  new playerfound=INVALID_PLAYER_ID;
  for(new playerid;playerid<MAX_PLAYERS;playerid++)
  {
    if(!IsPlayerConnected(playerid))continue;
    for(new playerid2;playerid2<MAX_PLAYERS;playerid2++)
    {
      if(playerid==playerid2)continue;
      if(!IsPlayerConnected(playerid2))continue;
      if(IsPlayerLookingAtPlayer(playerid,playerid2))
      {
        playerfound=playerid2;
        Attach3DTextLabelToPlayer(PlayerText3D:GetPVarInt(playerid,"HUDTEXT"),playerid2,0.0,0.0,0.0); //ERROR here, Can't attach PlayerText3D ??
        GetPlayerHealth(playerid2,HP);
        format(tmpstr,6,"%.00f",HP);
        UpdatePlayer3DTextLabelText(playerid,PlayerText3D:GetPVarInt(playerid,"HUDTEXT"),0xff,tmpstr);
      }
    }
    if(playerfound==INVALID_PLAYER_ID)
    {
      DeletePlayer3DTextLabel(playerid,PlayerText3D:GetPVarInt(playerid,"HUDTEXT"));
      SetPVarInt(playerid,"HUDTEXT",_:CreatePlayer3DTextLabel(playerid,"blank",0xFF,0.0,0.0,0.0,20.0,-1));
    }
    playerfound=INVALID_PLAYER_ID;
  }
  return 1;
}
VIDEO:



DOWNLOAD
Pastebin V1.1
Pastebin V1.0
Reply
#2

I like the idea with Load and Save, thanks!
Reply
#3

Nice work very helpfull :P
Reply
#4

So now we can do a script that detects if other player are aiming to the others payers head?
Reply
#5

Cant see the video
Anyways, nice!

- Cody Beer
Reply
#6

Quote:
Originally Posted by [DJ
[SF]Зурэ Яииr ∞™ ]
Cant see the video
Anyways, nice!

- Cody Beer
I just watched it.
Nice release Joe Staff; Like always
Reply
#7

Thanks its good to create a fireman job
Reply
#8

do you need a rapidshare mirror?
Reply
#9

Nice... i love your scripts Joe...
Reply
#10

Upgrading to 0.3b?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)