Help With PlayerToPoint
#1

I've fixed the other now i got another problem.
The gates appear in game but won't move.


These are above main:


Код:
PlayerToPoint(Float:radius, playerid, Float:X, Float:Y, Float:Z)
{
  new Float:oldpos[3], Float:temppos[3];
  GetPlayerPos(playerid, oldpos[0], oldpos[1], oldpos[2]);
  temppos[0] = (oldpos[0] -X);
  temppos[1] = (oldpos[1] -Y);
  temppos[2] = (oldpos[2] -Z);
  if(((temppos[0] < radius) && (temppos[0] > -radius)) && ((temppos[1] < radius) && (temppos[1] > -radius)) && ((temppos[2] < radius) && (temppos[2] > -radius)))
  {
    return true;
  }
  return false;
}
new OpenGate[MAX_PLAYERS];
new c_gate;
forward CheckGate();
These are under Publice OnGameModeInit:
Код:
c_gate = CreateObject(975, 2720.552, -2405.363, 14.150, 0.0, 0.0, 90.0);
SetTimer("checkgate", 500, true);
This is in the bottm of the script

Код:
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, 2720.552, -2405.363, 14.150) && OpenGate[i] == 0)
    {
      MoveObject(c_gate, 2720.552, -2396.363, 14.150);
      OpenGate[i] = 1;
    }
    else if(!PlayerToPoint(10.0, i, 2720.552, -2405.363, 14.150) && OpenGate[i] == 1)
    {
      MoveObject(c_gate, 2720.552, -2405.363, 14.150);
      OpenGate[i] = 0;
    }
  }
}
Reply
#2

Why you made this: new OpenGate[MAX_PLAYERS];
You want it to be open only for one Player? or all player at the same time?
Reply
#3

The wiki said i should. Why?
Reply
#4

It's to close the gate as soon as a player leaves, but it's clearly got some fallacies. For instance, if 2 people go near the gate, and only 1 leaves, the gate closes on the 2nd player.

It should probably be.

pawn Код:
public CheckGate()
{
  new tmpopen;
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i))
    {
      if(PlayerToPoint(10.0, i, 2720.552, -2405.363, 14.150))
      {
        tmpopen=1;
      }
    }
  }
  if(tmpopen)MoveObject(c_gate, 2720.552, -2396.363, 14.150);
   else MoveObject(c_gate, 2720.552, -2405.363, 14.150);
}
Reply
#5

Wait the PlayerToPoint code. Shall i edit that one?
Reply
#6

Bumb
Reply
#7

What's the problem, I didn't get?
Reply
#8

Код:
PlayerToPoint(Float:radius, playerid, Float:X, Float:Y, Float:Z)
{
  new Float:oldpos[3], Float:temppos[3];
  GetPlayerPos(playerid, oldpos[0], oldpos[1], oldpos[2]);
  temppos[0] = (oldpos[0] -X);
  temppos[1] = (oldpos[1] -Y);
  temppos[2] = (oldpos[2] -Z);
  if(((temppos[0] < radius) && (temppos[0] > -radius)) && ((temppos[1] < radius) && (temppos[1] > -radius)) && ((temppos[2] < radius) && (temppos[2] > -radius)))
  {
    return true;
  }
  return false;
}
This code shall i edit that one? If i shall, How?
And i just changed the title, so i didn't need to make another topic
Reply
#9

It should be IsPlayerNearPoint,simply because PlayerToPoint sounds like it should give back a distance between the player and a point

pawn Код:
IsPlayerNearPoint(playerid,Float:X,Float:Y,Float:Z,Float:radius)
{
  new Float:px,Float:py,Float:pz;
  GetPlayerPos(playerid,px,py,pz);
  if((((X-px)*(X-px))+((Y-py)*(Y-py))+((Z-pz)*(Z-pz)))<radius*radius)return 1;
  return 0;
}
Reply
#10

Hi there,

One of your problems here is that "checkgate" is not the same as "CheckGate". PAWN, when used in SA-MP, is case sensitive. Your "SetTimer" line doesn't run the timer as it doesn't find the function.

Have fun scripting.

Kind regards,

Francis Morissette
SA-MP Scripter
http://sa-mp.com
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)