Problem with MoveObject -
GabsReDeal - 08.09.2013
So I started scripting for a door to move whenever a player gets next to it, no errors or anything, it's just whenever I go close to them, nothing happens... And one more thing, if you could tell me how to do it for a single player it would highly be appreciated. Thanks a lot.
news
Код:
new g1;
new g2;
new g3;
forwards
Код:
forward point(playerid);
forward close();
public OnGameModeInit()
Код:
public OnGameModeInit()
{
g1 = CreateObject(3037, 935.74127, 2403.97021, 12.20237, 0.00000, 0.00000, -90.00000);
g2 = CreateObject(3037, 958.76367, 2403.97021, 12.18013, 0.00000, 0.00000, -90.00000);
g3 = CreateObject(3037, 981.90692, 2403.97021, 12.24170, 0.00000, 0.00000, -90.00000);
}
public point(playerid)
Код:
public point(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, 935.7413, 2403.9702, 12.2024))
{
MoveObject(g1,935.7413, 2403.9702, 15.6253, 2.50);
}
else
{
MoveObject(g1,935.7413, 2403.9702, 12.2024, 2.50);
}
if(IsPlayerInRangeOfPoint(playerid, 7.0, 958.7637, 2403.9702, 12.1801))
{
MoveObject(g2,958.7637, 2403.9702, 15.6253, 2.50);
}
else
{
MoveObject(g2,958.7637, 2403.9702, 12.1801, 2.50);
}
if(IsPlayerInRangeOfPoint(playerid, 7.0, 981.9069, 2403.9702, 12.2417))
{
MoveObject(g3,981.9069, 2403.9702, 15.6253, 2.50);
}
else
{
MoveObject(g3,981.9069, 2403.9702, 12.2417,2.50);
}
return 1;
}
public close()
Код:
public close()
{
MoveObject(g1,935.7413,2403.9702,12.2024,5.00);
MoveObject(g2,958.7637,2403.9702,12.1801,5.00);
MoveObject(g3,1002.1666,2399.7578,12.2417,5.00);
return 1;
}
Any help would be highly appreciated.
Re: Problem with MoveObject -
morha12 - 08.09.2013
Try This in open:
pawn Код:
public point(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, 935.7413, 2403.9702, 12.2024))
{
MoveObject(g1,2.50,935.7413, 2403.9702, 15.6253);
}
else
{
MoveObject(g1,2.50,935.7413, 2403.9702, 12.2024);
}
if(IsPlayerInRangeOfPoint(playerid, 7.0, 958.7637, 2403.9702, 12.1801))
{
MoveObject(g2,2.50,958.7637, 2403.9702, 15.6253);
}
else
{
MoveObject(g2,2.50,958.7637, 2403.9702, 12.1801);
}
if(IsPlayerInRangeOfPoint(playerid, 7.0, 981.9069, 2403.9702, 12.2417))
{
MoveObject(g3,2.50,981.9069, 2403.9702, 15.6253);
}
else
{
MoveObject(g3,2.50,981.9069, 2403.9702, 12.2417);
}
return 1;
}
and that on close:
pawn Код:
public close()
{
MoveObject(g1,5.0,935.7413,2403.9702,12.2024);
MoveObject(g2,5.0,958.7637,2403.9702,12.1801);
MoveObject(g3,5.0,1002.1666,2399.7578,12.2417);
return 1;
}
Re: Problem with MoveObject -
playbox12 - 08.09.2013
Where are you calling public point? You have to call it for it to run that code, you could put it under a command or under a certain action, like pressing a button. If you want it to go automatically you can run it under a timer. Though there are more accurate and faster ways, for example Incognito's streamer plugin has areas that call a callback when a specific player enters a specific area.
Re: Problem with MoveObject -
GabsReDeal - 16.09.2013
Quote:
Originally Posted by morha12
Try This in open:
pawn Код:
public point(playerid) { if(IsPlayerInRangeOfPoint(playerid, 7.0, 935.7413, 2403.9702, 12.2024)) { MoveObject(g1,2.50,935.7413, 2403.9702, 15.6253); } else { MoveObject(g1,2.50,935.7413, 2403.9702, 12.2024); } if(IsPlayerInRangeOfPoint(playerid, 7.0, 958.7637, 2403.9702, 12.1801)) { MoveObject(g2,2.50,958.7637, 2403.9702, 15.6253); } else { MoveObject(g2,2.50,958.7637, 2403.9702, 12.1801); } if(IsPlayerInRangeOfPoint(playerid, 7.0, 981.9069, 2403.9702, 12.2417)) { MoveObject(g3,2.50,981.9069, 2403.9702, 15.6253); } else { MoveObject(g3,2.50,981.9069, 2403.9702, 12.2417); } return 1; }
and that on close:
pawn Код:
public close() { MoveObject(g1,5.0,935.7413,2403.9702,12.2024); MoveObject(g2,5.0,958.7637,2403.9702,12.1801); MoveObject(g3,5.0,1002.1666,2399.7578,12.2417); return 1; }
|
Thanks for your help, but it still doesn't work
Re: Problem with MoveObject -
GabsReDeal - 16.09.2013
Quote:
Originally Posted by playbox12
Where are you calling public point? You have to call it for it to run that code, you could put it under a command or under a certain action, like pressing a button. If you want it to go automatically you can run it under a timer. Though there are more accurate and faster ways, for example Incognito's streamer plugin has areas that call a callback when a specific player enters a specific area.
|
I'm sorry but I didn't really understand that... thanks for commenting though... if you could just explain a little bit in basic xP
Re: Problem with MoveObject -
Threshold - 16.09.2013
He is talking about the callback from Incognito's Streamer Plugin,
OnPlayerEnterDynamicArea.
This is a very effective way of detecting a player entering, and another related callback used for detecting exiting, an area. I've written up this simple code (which can be more efficient, but I haven't gone to extreme lengths to keep the simplicity of it) for this case:
pawn Код:
#include <streamer>
new gatearea1;
new gatearea2;
new gatearea3;
//Gates are closed, so set 'Open' to false
new bool:gate1open = false;
new bool:gate2open = false;
new bool:gate3open = false;
public OnGameModeInit()
{
//Creating the areas
gatearea1 = CreateDynamicSphere(935.7413, 2403.9702, 12.2024, 7);
gatearea2 = CreateDynamicSphere(958.7637, 2403.9702, 12.1801, 7);
gatearea3 = CreateDynamicSphere(981.9069, 2403.9702, 12.2417, 7);
return 1;
}
public OnPlayerEnterDynamicArea(playerid, areaid)
{
if(areaid == gatearea1)
{
if(gate1open == false)
{
MoveObject(g1,2.50,935.7413, 2403.9702, 15.6253);
gate1open = true; //Gate 1 is now open, so true
}
}
if(areaid == gatearea2)
{
if(gate2open == false)
{
MoveObject(g2,2.50,958.7637, 2403.9702, 15.6253);
gate2open = true;
}
}
if(areaid == gatearea3)
{
if(gate3open == false)
{
MoveObject(g3,2.50,981.9069, 2403.9702, 15.6253);
gate3open = true;
}
}
return 1;
}
public OnPlayerLeaveDynamicArea(playerid, areaid)
{
if(areaid == gatearea1)
{
if(gate1open == true)
{
if(!PlayersInGateArea(playerid, 1))
{
MoveObject(g1,2.50,935.7413, 2403.9702, 12.2024);
gate1open = false;
}
}
}
if(areaid == gatearea2)
{
if(gate2open == true)
{
if(!PlayersInGateArea(playerid, 2))
{
MoveObject(g2,2.50,958.7637, 2403.9702, 12.1801);
gate2open = false;
}
}
}
if(areaid == gatearea3)
{
if(gate3open == true)
{
if(!PlayersInGateArea(playerid, 3))
{
MoveObject(g3,2.50,981.9069, 2403.9702, 12.2417);
gate3open = false;
}
}
}
return 1;
}
stock PlayersInGateArea(playerid, gatearea)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(i == playerid) continue;
switch(gatearea)
{
case 1: if(IsPlayerInDynamicArea(i, gatearea1)) return 1;
case 2: if(IsPlayerInDynamicArea(i, gatearea2)) return 1;
case 3: if(IsPlayerInDynamicArea(i, gatearea3)) return 1;
}
}
return 0;
}
You will need to download the Streamer plugin and include it in your script.
Download/View Thread Here:
https://sampforum.blast.hk/showthread.php?tid=102865
Re: Problem with MoveObject -
GabsReDeal - 21.09.2013
Quote:
Originally Posted by BenzoAMG
He is talking about the callback from Incognito's Streamer Plugin, OnPlayerEnterDynamicArea.
This is a very effective way of detecting a player entering, and another related callback used for detecting exiting, an area. I've written up this simple code (which can be more efficient, but I haven't gone to extreme lengths to keep the simplicity of it) for this case:
pawn Код:
#include <streamer>
new gatearea1; new gatearea2; new gatearea3;
//Gates are closed, so set 'Open' to false new bool:gate1open = false; new bool:gate2open = false; new bool:gate3open = false;
public OnGameModeInit() { //Creating the areas gatearea1 = CreateDynamicSphere(935.7413, 2403.9702, 12.2024, 7); gatearea2 = CreateDynamicSphere(958.7637, 2403.9702, 12.1801, 7); gatearea3 = CreateDynamicSphere(981.9069, 2403.9702, 12.2417, 7);
return 1; }
public OnPlayerEnterDynamicArea(playerid, areaid) { if(areaid == gatearea1) { if(gate1open == false) { MoveObject(g1,2.50,935.7413, 2403.9702, 15.6253); gate1open = true; //Gate 1 is now open, so true } }
if(areaid == gatearea2) { if(gate2open == false) { MoveObject(g2,2.50,958.7637, 2403.9702, 15.6253); gate2open = true; } }
if(areaid == gatearea3) { if(gate3open == false) { MoveObject(g3,2.50,981.9069, 2403.9702, 15.6253); gate3open = true; } } return 1; }
public OnPlayerLeaveDynamicArea(playerid, areaid) { if(areaid == gatearea1) { if(gate1open == true) { if(!PlayersInGateArea(playerid, 1)) { MoveObject(g1,2.50,935.7413, 2403.9702, 12.2024); gate1open = false; } }
if(areaid == gatearea2) { if(gate2open == true) { if(!PlayersInGateArea(playerid, 2)) { MoveObject(g2,2.50,958.7637, 2403.9702, 12.1801); gate2open = false; } } }
if(areaid == gatearea3) { if(gate3open == true) { if(!PlayersInGateArea(playerid, 3)) { MoveObject(g3,2.50,981.9069, 2403.9702, 12.2417); gate3open = false; } } } } return 1; }
stock PlayersInGateArea(playerid, gatearea) { for(new i = 0; i < MAX_PLAYERS; i++) { if(!IsPlayerConnected(i)) continue; if(i == playerid) continue; switch(gatearea) { case 1: if(IsPlayerInDynamicArea(i, gatearea1)) return 1; case 2: if(IsPlayerInDynamicArea(i, gatearea2)) return 1; case 3: if(IsPlayerInDynamicArea(i, gatearea3)) return 1; } } return 0; }
You will need to download the Streamer plugin and include it in your script.
Download/View Thread Here: https://sampforum.blast.hk/showthread.php?tid=102865
|
This Actually Worked, thanks alot. The only problem is that "g1" closes after you leave the areas, but the others don't. I'm trying to fix it at the moment.