Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
Hey guys.
I'm moving like 4 objects and i'm stopping the player from moving until it's finished. How would i get around that?
Here's my current code(btw this filterscript will be released when done):
pawn Код:
SendClientMessage(playerid, COLOR_GREEN, "Locking position");
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
GetXYInDirectionOfPosition(angle, x, y, 5);
plantone = CreateObject(3409, x, y, z-3, 0, 0, 0);
MoveObject(plantone, x, y, z-2, 0.1);
planttwo = CreateObject(3409, x, y, z-2, 0, 0, 0);
MoveObject(planttwo, x, y, z-1, 0.1);
plantthree = CreateObject(3409, x, y, z-1, 0, 0, 0);
MoveObject(plantthree, x, y, z, 0.1);
plantfour = CreateObject(3409, x, y, z,0, 0, 0);
MoveObject(plantfour, x, y, z+1, 0.1);
Re: Enabling player to move after MoveObject -
member - 29.05.2009
you want to stop the player from moving, or you want them to move? Whatever way, you'll need TogglePlayerControllable to do either.
https://sampwiki.blast.hk/wiki/TogglePlayerControllable
Re: Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
Yeah if you read my code, you'dve seen that i do use TogglePlayerControllable to stop them from moving while the objects are moving, but after they're done moving, i want the player to be able to move again.
Re: Enabling player to move after MoveObject -
member - 29.05.2009
Quote:
Originally Posted by dylanNIRVANA
Yeah if you read my code, you'dve seen that i do use TogglePlayerControllable to stop them from moving while the objects are moving, but after they're done moving, i want the player to be able to move again.
|
I have had a look at the code you gave and from that i can't see a TogglePlayerControllable in there, maybe you do have it, but from what you gave it isn't there.
![Smiley](images/smilies/smile.png)
If you had a look at the wiki, to make them 'unfreeze' you do:
pawn Код:
TogglePlayerControllable(playerid,1);
so put that somewhere
after the objects have moved.
Re: Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
Sorry, i forgot to add it in. It's before the first line on the #1 post.
I've already tried that, but it moves em all and locks + unlocks like instantly. It doesn't wait for the objects to stop moving.
Re: Enabling player to move after MoveObject -
member - 29.05.2009
make a timer for the player.
pawn Код:
forward UnfreezPlayer(playerid);
SetTimerEx("UnfreezPlayer", 5000, false, "d", playerid); // put this AFTER your objects have moved
//put this anywhere outside callbacks, publics etc
public UnfreezPlayer(playerid)
{
TogglePlayerControllable(playerid,1);
SendClientMessage(playerid, 0x99FF00AA, "***You have been unfrozen :D");
}
Re: Enabling player to move after MoveObject -
yom - 29.05.2009
Why not just do it under OnObjectMoved?
Re: Enabling player to move after MoveObject -
member - 29.05.2009
Quote:
Originally Posted by 0rb
Why not just do it under OnObjectMoved?
|
wow, never knew such a callback exists, much easier. Learning something every day.
Re: Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
Quote:
Originally Posted by 0rb
Why not just do it under OnObjectMoved?
|
Well, if i was to put it under that, then when the first plant moves, the player would be controllable. I want it after all the plants have moved.
Quote:
Originally Posted by [B2K
Hustler ]
make a timer for the player.
pawn Код:
forward UnfreezPlayer(playerid);
SetTimerEx("UnfreezPlayer", 5000, false, "d", playerid); // put this AFTER your objects have moved
//put this anywhere outside callbacks, publics etc public UnfreezPlayer(playerid) { TogglePlayerControllable(playerid,1); SendClientMessage(playerid, 0x99FF00AA, "***You have been unfrozen :D"); }
|
I did this, works ok i guess. I just thought there'd be another way.
Re: Enabling player to move after MoveObject -
member - 29.05.2009
then check if your final object (plantfour) has moved then unfreeze him.
pawn Код:
public OnObjectMoved(objectid)
{
if(objectid == plantfour)
{
TogglePlayerControllable(playerid,1);
SendClientMessage(playerid, 0x99FF00AA, "***You have been unfrozen :D");
}
return 1;
}
or just use the timer?
Re: Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
Quote:
Originally Posted by [B2K
Hustler ]
then check if your final object (plantfour) has moved then unfreeze him.
pawn Код:
public OnObjectMoved(objectid) { if(objectid == plantfour) { TogglePlayerControllable(playerid,1); SendClientMessage(playerid, 0x99FF00AA, "***You have been unfrozen :D"); } return 1; }
or just use the timer?
|
There is no playerid there..
Re: Enabling player to move after MoveObject -
member - 29.05.2009
then just use a timer.
Re: Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
I feel alot better using the callback, is there any way to get playerid into there?
Re: Enabling player to move after MoveObject -
member - 29.05.2009
as far as i know, you can't. Maybe someone else can find a solution.
I've also come up with this:
pawn Код:
new bool:PlayerMovedObject[MAX_PLAYERS] = false;
public OnObjectMoved(objectid)
{
if(objectid == plantfour)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && PlayerMovedObject[i])
{
TogglePlayerControllable(playerid,1);
SendClientMessage(playerid, 0x99FF00AA, "***You have been unfrozen :D");
PlayerMovedObject[i] = false;
}
}
}
return 1;
}
When the player moves the object set their variable to:
pawn Код:
PlayerMovedObject[playerid] = true;
Obviously this is not reliable as when someone moves an object and while that object is moving someone else does this, they will both get unfrozen. Not as reliable as the timer.
Re: Enabling player to move after MoveObject -
ZxPwn420 - 29.05.2009
Quote:
Originally Posted by [B2K
Hustler ]
as far as i know, you can't. Maybe someone else can find a solution.
I've also come up with this:
pawn Код:
new bool:PlayerMovedObject[MAX_PLAYERS] = false;
public OnObjectMoved(objectid) { if(objectid == plantfour) { for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i) && PlayerMovedObject[i]) { TogglePlayerControllable(playerid,1); SendClientMessage(playerid, 0x99FF00AA, "***You have been unfrozen :D"); PlayerMovedObject[i] = false; } } } return 1; }
When the player moves the object set their variable to:
pawn Код:
PlayerMovedObject[playerid] = true;
Obviously this is not reliable as when someone moves an object and while that object is moving someone else does this, they will both get unfrozen. Not as reliable as the timer.
|
You still can't use that code because playerid isn't in the callback.
Re: Enabling player to move after MoveObject -
member - 29.05.2009
oops, my bad. Here it is:
pawn Код:
new bool:PlayerMovedObject[MAX_PLAYERS] = false;
public OnObjectMoved(objectid)
{
if(objectid == plantfour)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && PlayerMovedObject[i])
{
TogglePlayerControllable(i,1);
SendClientMessage(i, 0x99FF00AA, "***You have been unfrozen :D");
PlayerMovedObject[i] = false;
}
}
}
return 1;
}
When the player moves the object set their variable to:
pawn Код:
PlayerMovedObject[playerid] = true;
but i still wuoldn't recommend that compared to the timer.