getxyinfronofme
#1

Hello there,

Im trying to learn how to use the getxyifrontofme function

I checked the wiki about, still im doing something wrong and i just cant figure it out.

p.s. iknow every scripter must have the taxi npc script where i could check. But if i do that i wont 'understand' and learn how it works.

Here is what the piece of code where i go wrong somehow;

Код:
//------------------------------------------wikithing wich i want to use because im learning! XD
GetXYInFrontOfMe(Float:x, &Float:y, Float:distance)
{
	new Float:z,Float:a;
	GetMyPos( x, y, z);
	GetMyFacingAngle(a);

	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
//------------------------------------------
public OnNPCCheckplayer()
{
	new Float:x, Float:y ;
	GetXYInFrontOfMe(x, y, 5.0);
	for(new i = 0; i < MAX_PLAYERS; i++)
	if(IsPlayerInRangeOfPoint(i, 5.0, x,y,5.0))
	{
	SendChat("I 'see' a player is in front of me .");
	}

}
(OnNPCCheckplayer is a timer that repeats every 5 seconds)

P.S. 2 - If i understand this, then im going to make a tutorial because i saw very much questions about it
Reply
#2

is that the whole code?..
Reply
#3

No no its just the npc script part where the problem should be
Reply
#4

u tried already ONLY IsPlayerInRangeOfPoint without the "in front of me" code?
so just GetMyPos and IsPlayerInRangeOfPoint ? :P
Reply
#5

hmmm...not sure what you mean.. should xyinfrontofme under isplayerinpointofrange ?

well.. here is the whole npcscript to be sure;

Код:
#define RECORDING "npc15" 
#define RECORDING_TYPE 2 

#include <a_npc>
main(){}
public OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING);
public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);
public OnNPCExitVehicle() StopRecordingPlayback();

forward OnNPCCheckplayer();

public OnNPCSpawn()
{

  
  StartRecordingPlayback(RECORDING_TYPE, RECORDING);
  SetTimer("OnNPCCheckplayer",5000,1);

  return 1;
}




//------------------------------------------
stock GetXYInFrontOfMe(Float:x, &Float:y, Float:distance)
{
	new Float:z,Float:a;
	GetMyPos( x, y, z);
	GetMyFacingAngle(a);

	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
//------------------------------------------
public OnNPCCheckplayer()
{
	new Float:x, Float:y ;
	GetXYInFrontOfMe(x, y, 5.0);
	for(new i = 0; i < MAX_PLAYERS; i++)
	if(IsPlayerInRangeOfPoint(i, 5.0, x,y,5.0))
	{
	SendChat("I 'see' a player is in front of me !.");
	}

}

Reply
#6

Quote:

so just GetMyPos and IsPlayerInRangeOfPoint ?

Well..i thought if(IsPlayerInRangeOfPoint(i, 5.0, x,y,5.0)) would listen to the values getxyinfrontof.. just above it.

EDIT: i put getmypos in the timer just above isplayerinrange..but now it listens to the x,y,z postition of getmypos
and i want it to listen to getxyinfrontofme.

How?
Reply
#7

I wanted to make a tutorial about GetXYInfrontOfPlayer


pawn Код:
(opposite)          (d) = position infront of player (p) = player
      (d)____________          To get XY infront of player, you need player's position, player's facing angle and the distance you want infront of player.
        \      |         Lets make ourselves a random values:
        \     |            - distance(hypotenuse) = 20.0 feet
         \     |            - player's facing angle = 30.0 degrees
         \   |            
   (hypotenuse) \   | (adjacent)    opposite = sine 30.0 * 20.0   (try with your calculator)
          \  |         adjacent = cosine 30.0 * 20.0
           \  |        
           \ |         20.0 * floatsin(-30.0, degrees) = 10.0 feet (opposite) //floatsin(Float:value, anglemode) in this case anglemode is degrees
            \ |         20.0 * floatcos(-30.0, degrees) = 17.3 feet (adjacent) //-30.0 because SA-MP has angles inverted
            \ |        
             \ |         Add opposite to player'
s X position and adjacent to Y position.
             \|         X += opposite Y+= adjacent
             (p)         The function returns a new X and a new Y floatvalues.

In your code, you have '&' missing, meaning it only returns Y value.
GetXYInFrontOfMe(&Float, &Float:y, Float:distance)
Reply
#8

i don't know if this will work but u can at least try it:
pawn Код:
#define RECORDING "npc15"
#define RECORDING_TYPE 2

#include <a_npc>
main(){}
public OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING);
public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);
public OnNPCExitVehicle() StopRecordingPlayback();

forward OnNPCCheckplayer();

public OnNPCSpawn()
{
  StartRecordingPlayback(RECORDING_TYPE, RECORDING);
  SetTimer("OnNPCCheckplayer",5000,1);
  return 1;
}
//------------------------------------------
stock GetXYInFrontOfMe(&Float:x, &Float:y, Float:distance)
{
    new Float:z,Float:a;
    GetMyPos( x, y, z);
    GetMyFacingAngle(a);

    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
//------------------------------------------
public OnNPCCheckplayer()
{
    new Float:x, Float:y,Float:unusedx,Float:unusedy,Float:tempz;
    GetMyPos(unusedx,unusedy,tempz);
    GetXYInFrontOfMe(x, y, 5.0);
    for(new i = 0; i < MAX_PLAYERS; i++){
        if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 5.0, x,y,tempz))
        {
            SendChat("I 'see' a player is in front of me !.");
        }
    }
}
btw so & in a function lets you save the thingy to a variable.. hmm something new i learned ;x

and nice tut, i love maths ;]
Reply
#9

LoL i see..what i did wrong XD i figured it out now its working 'yeeh'

Thanks to both of you..and..nice tutorial

now im also going to try checking a player is standing behind the npc XD..i guess i just need to calculate the correct angle.

Reply
#10

just get the angle then add +180 and here u go ! XD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)