Animated Rotation?
#1

Hi!
I don't know if this is a noob question, but:
How can i change the rotation of an object animated (like in MoveObject, but for the rotation)?
thx for any help!
Reply
#2

I guess you should use this:
Quote:

SetObjectRot

https://sampwiki.blast.hk/wiki/SetObjectRot
Reply
#3

You could do something like this:

pawn Code:
forward rotation(); // The call back Timer.

public OnGameModeInit()

{
SetTimer("rotation", 100, 1); // The timer which will go off every millisecond.
object = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ); // The object (Fill in the spaces)

}

public rotation() // The callback

{
SetObjectRot(object, 0, 0, +0.1); // Will set the Z rot +0.1 every millisecond
return 1;
}
Reply
#4

Correct me if im wrong, Im sure MoveObject() has angle parameters
Reply
#5

Quote:
Originally Posted by Farly
Correct me if im wrong, Im sure MoveObject() has angle parameters
I guess not, only X, Y and Z.
Correct me if I'm wrong also :P
Reply
#6

I want the object to rotate ANIMATED. I want to make a barrier (like by railroad overpasses) wich changes its rotation animated. Is this possible?
Reply
#7

You could use valuables and a timer to do this.
Reply
#8

Someone's already posted on how you can do this. Read up about 5 posts.
Reply
#9

Polar made a command that does thatin the useful functions or useful commands topic. Search for "MoveRot".
Reply
#10

Quote:
Originally Posted by Giacomand
You could do something like this:

pawn Code:
forward rotation(); // The call back Timer.

public OnGameModeInit()

{
SetTimer("rotation", 100, 1); // The timer which will go off every millisecond.
object = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ); // The object (Fill in the spaces)

}

public rotation() // The callback

{
SetObjectRot(object, 0, 0, +0.1); // Will set the Z rot +0.1 every millisecond
return 1;
}
And how can i stop the timer, when the object is in right position?
Reply
#11

Quote:
Originally Posted by yugokoral
And how can i stop the timer, when the object is in right position?
pawn Код:
forward rotation(); // The call back Timer.
new rottimer; //Timer

public OnGameModeInit()
{
   rottimer = SetTimer("rotation", 100, 1); // The timer which will go off every millisecond.
   object = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ); // The object (Fill in the spaces)
   return 1;
}

public rotation() // The callback
{
   new Float:rotx, Float:roty, Float:rotz; //Floats
   SetObjectRot(object, 0, 0, +0.1); // Will set the Z rot +0.1 every millisecond
   GetObjectRot(object, rotx, roty, rotz)// Checks the pos
   if(rotz == 100.0) KillTimer(rottimer); //Checks if the z rot is 100.0 and kills the timer if it is.
   return 1;
}
Reply
#12

I Make this script:

pawn Код:
#include <a_samp>

new zapornice;
new rottimer;

public OnGameModeInit()
{
   rottimer = SetTimer("OnPlayerCommandText", 100, 1); // The timer which will go off every millisecond.
   zapornice = CreateObject(968,-1572.203613,658.795593,6.918911,0.000000,0.000000,90.000000);//zapornica odprta
   return 1;
}


public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/skok", true)==0)
    {
    new Float:rotx, Float:roty, Float:rotz; //Floats
    SetObjectRot(zapornice, 0, +0.1, 90.0); // Will set the Z rot +0.1 every millisecond
    GetObjectRot(zapornice, rotx, roty, rotz)// Checks the pos
    if(roty == 90.0) KillTimer(rottimer); //Checks if the z rot is 100.0 and kills the timer if it is.
    return 1;
  }
  return 0;
}

And i will get errors:
Код:
C:\Documents and Settings\Anћe Miklavčič\Desktop\sa mp server\filterscripts\zapornice.pwn(28) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Anћe Miklavčič\Desktop\sa mp server\filterscripts\zapornice.pwn(28) : warning 215: expression has no effect
C:\Documents and Settings\Anћe Miklavčič\Desktop\sa mp server\filterscripts\zapornice.pwn(28) : warning 215: expression has no effect
C:\Documents and Settings\Anћe Miklavčič\Desktop\sa mp server\filterscripts\zapornice.pwn(28) : error 001: expected token: ";", but found ")"
C:\Documents and Settings\Anћe Miklavčič\Desktop\sa mp server\filterscripts\zapornice.pwn(28) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Anћe Miklavčič\Desktop\sa mp server\filterscripts\zapornice.pwn(28) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#13

Quote:
Originally Posted by yugokoral
...
Try:
pawn Код:
#include <a_samp>

forward rotation();

new rottimer;

new zapornice;

new bool:rotate;

public OnGameModeInit()
{
  zapornice = CreateObject(968, -1572.203613, 658.795593, 6.918911, 0.000000, 0.000000, 90.000000);
  return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
  if(!strcmp(cmdtext, "/skok", true))
  {
     if(rotate == true) return 1;
     rottimer = SetTimer("rotation", 100, 1);
     rotate = true;
     return 1;
  }
  return 0;
}

public rotation()
{
  if(rotate == false) return 1;
  //
  new Float:rotx, Float:roty, Float:rotz;
  GetObjectRot(zapornice, rotx, roty, rotz);
  SetObjectRot(zapornice, rotx, roty+0.1, rotz);
  //
  if(roty == 90.0)
  {
     KillTimer(rottimer);
     rotate = false;
  }
  return 1;
}
Reply
#14

Ok now it works but i tryed to make this:

pawn Код:
#include <a_samp>


new rottimer;
new zapornice;

public OnGameModeInit()
{
   zapornice = CreateObject(968, -1572.203613, 658.795593, 6.918911, 0.000000, 90.000000, 90.000000);
   rottimer = SetTimer("CheckGate", 10, 1);
   SetTimer("CheckGate", 10, 1);
     return 1;
}

   
new OpenGate[MAX_PLAYERS];


forward CheckGate();
public CheckGate()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      if(PlayerToPoint(10.0, i, -1572.1993,663.0866,7.1875) && OpenGate[i] == 0)
      {
        new Float:rotx, Float:roty, Float:rotz;
        GetObjectRot(zapornice, rotx, roty, rotz);
        SetObjectRot(zapornice, rotx, roty-0.1, rotz);

        if(roty == 0.0)
        {
          KillTimer(rottimer);
        }
        OpenGate[i] = 1;
      }
      else if(!PlayerToPoint(10.0, i, -1572.1993,663.0866,7.1875) && OpenGate[i] == 1)
      {
        OpenGate[i] = 0;
        new Float:rotx, Float:roty, Float:rotz;
        GetObjectRot(zapornice, rotx, roty, rotz);
        SetObjectRot(zapornice, rotx, roty+0.1, rotz);

        if(roty == 90.0)
        {
          KillTimer(rottimer);
        }
      }
    }
  }
}


forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  new Float:oldposx, Float:oldposy, Float:oldposz;
  new Float:tempposx, Float:tempposy, Float:tempposz;
  GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  tempposx = (oldposx -x);
  tempposy = (oldposy -y);
  tempposz = (oldposz -z);
  if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  {
    return 1;
  }
  return 0;
}
THIS DOESNT WORD!
Reply
#15

Quote:
Originally Posted by yugokoral
...
pawn Код:
#include <a_samp>

forward CheckGate();
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);

new OpenGate[MAX_PLAYERS];

new zapornice;

public OnGameModeInit()
{
  zapornice = CreateObject(968, -1572.203613, 658.795593, 6.918911, 0.000000, 90.000000, 90.000000);
  SetTimer("CheckGate", 10, 1);
   return 1;
}

public CheckGate()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      if(PlayerToPoint(10.0, i, -1572.1993,663.0866,7.1875) && OpenGate[i] == 0)
      {
        new Float:rotx, Float:roty, Float:rotz;
        GetObjectRot(zapornice, rotx, roty, rotz);
        if(roty != 0.0) SetObjectRot(zapornice, rotx, roty-0.1, rotz);
        else OpenGate[i] = 1;
      }
      else if(!PlayerToPoint(10.0, i, -1572.1993,663.0866,7.1875) && OpenGate[i] == 1)
      {
        new Float:rotx, Float:roty, Float:rotz;
        GetObjectRot(zapornice, rotx, roty, rotz);
        if(roty != 90.0) SetObjectRot(zapornice, rotx, roty+0.1, rotz);
        else OpenGate[i] = 0;
      }
    }
  }
  return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  new Float:oldposx, Float:oldposy, Float:oldposz;
  new Float:tempposx, Float:tempposy, Float:tempposz;
  GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  tempposx = (oldposx -x);
  tempposy = (oldposy -y);
  tempposz = (oldposz -z);
  if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  {
    return 1;
  }
  return 0;
}
You set the timer 2 times, try this.
Reply
#16

There is one problem. If i go to the point, the object start rotate (open), and if i go avay, object won't closed. If i go to point one time the object start rotating in one way, and won't stop!!
Reply
#17

Well, try this.

pawn Код:
#include <a_samp>

forward CheckGate();
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);

new zapornice;

public OnGameModeInit()
{
  zapornice = CreateObject(968, -1572.203613, 658.795593, 6.918911, 0.000000, 90.000000, 90.000000);
  SetTimer("CheckGate", 10, 1);
  return 1;
}

public CheckGate()
{
  new Float:rotx, Float:roty, Float:rotz;
  GetObjectRot(zapornice, rotx, roty, rotz);
  for(new i = 0; i < MAX_PLAYERS; i++) // Check if anyone is near to the gate.
  {
    if(IsPlayerConnected(i))
    {
      if(PlayerToPoint(10.0, i, -1572.1993,663.0866,7.1875))
      {
        if(roty != 0.0) SetObjectRot(zapornice, rotx, roty-0.1, rotz); // Someone is near to the gate, start opening
        return 1;
      }
    }
  }
  if(roty != 90.0) SetObjectRot(zapornice, rotx, roty+0.1, rotz); //There was no one near to the gate, start closing
  return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  new Float:oldposx, Float:oldposy, Float:oldposz;
  new Float:tempposx, Float:tempposy, Float:tempposz;
  GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  tempposx = (oldposx -x);
  tempposy = (oldposy -y);
  tempposz = (oldposz -z);
  if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  {
    return 1;
  }
  return 0;
}
Reply
#18

Now, the first problem fixed. Not fixed problem is: If the gate opening, than the gate won't stop at 0.0 angle.

Thank you, my script is much better!

Reply
#19

WTF? It should stop. Try this:
pawn Код:
#include <a_samp>

forward CheckGate();
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);

new zapornice;

public OnGameModeInit()
{
  zapornice = CreateObject(968, -1572.203613, 658.795593, 6.918911, 0.000000, 90.000000, 90.000000);
  SetTimer("CheckGate", 10, 1);
  return 1;
}

public CheckGate()
{
  new Float:rotx, Float:roty, Float:rotz;
  GetObjectRot(zapornice, rotx, roty, rotz);
  for(new i = 0; i < MAX_PLAYERS; i++) // Check if anyone is near to the gate.
  {
    if(IsPlayerConnected(i))
    {
      if(PlayerToPoint(10.0, i, -1572.1993,663.0866,7.1875))
      {
        if(roty > 0.0) SetObjectRot(zapornice, rotx, roty-0.1, rotz); // Someone is near to the gate, start opening
        return 1;
      }
    }
  }
  if(roty < 90.0) SetObjectRot(zapornice, rotx, roty+0.1, rotz); //There was no one near to the gate, start closing
  return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  new Float:oldposx, Float:oldposy, Float:oldposz;
  new Float:tempposx, Float:tempposy, Float:tempposz;
  GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  tempposx = (oldposx -x);
  tempposy = (oldposy -y);
  tempposz = (oldposz -z);
  if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  {
    return 1;
  }
  return 0;
}
Reply
#20

Thanks a lot, thank you. Now working very well!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)