Opening & Closing gate when near it only with command [get in need help!]
#1

Well, i've been trying every thing to make PlayerToPoint works with if(!xxx)

Well here is the command iam trying to do:
pawn Код:
if(strcmp(cmdtext,"/dmv",true ) == 0 )
    {
      if(!dmvgate)
        {
        DestroyObject(dmv1);
        dmv2 = CreateObject(968, -2049.213379, -87.948311, 34.873291, 0.0000, 0.0000, 0.0000);
        SendClientMessage(playerid, 0x804040FF, "Department of Motor Vehicles gate is now opened !");
        dmvgate = true;
        } else {
        DestroyObject(dmv2);
        CreateObject(968, -2049.250977, -87.951797, 34.998360, 0.0000, 89.3814, 0.0000);
        SendClientMessage(playerid, 0x804040FF, "Department of Motor Vehicles gate is now closed !");
        dmvgate = false;
        }
        return 1;
 }
I want to add a PlayerToPoint so if he is near the coords i want he can use /dmv , if not, then he cannot.. i already putted the PlayerToPoint script and its forward, all i need is just how to merge it with /dmv..

i even tried to put PlayerToPoint before the If(!dmvgate) {

and i putted after the dmvgate =false; } return 1 } i putted the SendClientMessage(playerid, color, "You're not near any gate"); return 1; } and it compiled good but when i try the command in the game it keeps saying Department of Motor Vehicles gate is now closed !

So if you know how to do it, i will appreciate it!
Reply
#2

Should work
pawn Код:
new dmvgate=0, gate;

public OnGameModeInit()
{
    gate =CreateObject(968, -2049.250977, -87.951797, 34.998360, 0.0000, 89.3814, 0.0000); //in closed state
    return 1;
}

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 1;
  }
  return 0;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext,"/dmv",true ) == 0 )
    {
      if(PlayerToPoint(0.0,playerid,0.0,0.0,0.0)) //radius, playerid, x, y, z
        {
            if(dmvgate == 0)
            {
                MoveObject(gate,-2049.213379, -87.948311, 34.873291, 2.00 ); // id, x, y, z, speed
                SendClientMessage(playerid, 0x804040FF, "Department of Motor Vehicles gate is now opened !");
                dmvgate = 1;
            }
            else
            {
                MoveObject(gate,-2049.250977, -87.951797, 34.998360, 2.0);
                SendClientMessage(playerid, 0x804040FF, "Department of Motor Vehicles gate is now closed !");
                dmvgate = 0;
            }
            return 1;
        }
        else
        {
            SendClientMessage(playerid, 0x804040FF, "You're not near the gate!");
        }
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)