Need some help
#1

I need some help with my auto gates. It works perfectly when 1 from the faction is online, but if there is more 1 one from this faction online, the gate will only work for the first member that logged in. I hope you understand what Im meaning as Im not so good at explaining things
pawn Код:
public TowServiceGate1(playerid)
{
    if(PlayerToPoint(5.0,playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1)
    {
        b_MoveObject(Entrance1, 1937.729, 2137.095, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708, 2158.011, 11.531, 2);
    }
    else if(!PlayerToPoint(5.0, playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1)
    {
        b_MoveObject(Entrance1, 1937.729, 2144.566, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708 ,2152.508 ,11.531, 2);
    }
}
Reply
#2

Sorry for bumping this, but I really need help with this
Reply
#3

The code seems ok, how do you call the function (with the timer or how? if yes, remember to use SetTimerEx and not SetTimer)?
Reply
#4

Quote:
Originally Posted by Don Correlli
The code seems ok, how do you call the function (with the timer or how? if yes, remember to use SetTimerEx and not SetTimer)?
Oh, I use SetTimer. But it works when only 1 from the faction is on, but not when 2 or more is on
Reply
#5

Use SetTimerEx, the variant can pass parameters to the function (playerid parameter in your case).
Reply
#6

Thanks, I will try if this works
Reply
#7

Add a variable that checks if gate is already opened/closed.

pawn Код:
new GateOpen;

public TowServiceGate1(playerid)
{
    if(PlayerToPoint(5.0,playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1 && GateOpen == 0)
    {
        b_MoveObject(Entrance1, 1937.729, 2137.095, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708, 2158.011, 11.531, 2);
        GateOpen = 1;
    }
    else if(!PlayerToPoint(5.0, playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1 && GateOpen == 1)
    {
        b_MoveObject(Entrance1, 1937.729, 2144.566, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708 ,2152.508 ,11.531, 2);
        GateOpen = 0;
    }
}
Reply
#8

Quote:
Originally Posted by MadeMan
Add a variable that checks if gate is already opened/closed.

pawn Код:
new GateOpen;

public TowServiceGate1(playerid)
{
    if(PlayerToPoint(5.0,playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1 && GateOpen == 0)
    {
        b_MoveObject(Entrance1, 1937.729, 2137.095, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708, 2158.011, 11.531, 2);
        GateOpen = 1;
    }
    else if(!PlayerToPoint(5.0, playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1 && GateOpen == 1)
    {
        b_MoveObject(Entrance1, 1937.729, 2144.566, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708 ,2152.508 ,11.531, 2);
        GateOpen = 0;
    }
}
Thats not really needed and it doesn't help much..

Quote:
Originally Posted by Don Correlli
Use SetTimerEx, the variant can pass parameters to the function (playerid parameter in your case).
Sorry, but Im not good at SetTimerEx. Could you help me with it or try explaining how to do it?
Reply
#9

Quote:
Originally Posted by [LRP
Sayaron ]
Quote:
Originally Posted by Don Correlli
Use SetTimerEx, the variant can pass parameters to the function (playerid parameter in your case).
Sorry, but Im not good at SetTimerEx. Could you help me with it or try explaining how to do it?
Here's an example:
pawn Код:
SetTimerEx("MyFunction", 1000, 1, "i", playerid);
pawn Код:
public MyFunction(playerid)
{
  // code.
  return 1;
}
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#10

I still dont get this with SetTimerEx, I aslo tried to learn it from wiki. But its so hard..

I tried to put the timer under
pawn Код:
public OnGameModeInit()
but then I got this error:
Код:
C:\Documents and Settings\Christian\Skrivebord\LRPCLAN\gamemodes\LRP.pwn(1782) : error 017: undefined symbol "playerid"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
I hope I dont annoy you or something with this
Reply
#11

OnGameModeInit doesn't have playerid parameter so you can't have it there, put it somewhere else, like at OnPlayerConnect.
Reply
#12

Thanx alot, it works now
Reply
#13

You're welcome.

Just another suggestion: Use KillTimer function to kill the timer when player disconnects (at OnPlayerDisconnect).

Example:
pawn Код:
new myTimer[MAX_PLAYERS];
pawn Код:
public MyFunction(playerid)
{
  // code.
  return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
  myTimer[playerid] = SetTimerEx("MyFunction", 1000, 1, "i", playerid);
  return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
  KillTimer(myTimer[playerid]);
  return 1;
}
Reply
#14

Um.. The gate is now opening for everyone in the faction, but... Its opening and closing it self when we stay near it. And it opens and closes very quick. Know why this is happening??
Reply
#15

Have you used MadeMan's code?
Reply
#16

Yeh, I tried. But got the same result
Reply
#17

Quote:
Originally Posted by [LRP
Sayaron ]
Yeh, I tried. But got the same result
Well, i didn't wanted you to use it because it would do the same.

Please post your edited code.
Reply
#18

pawn Код:
public TowServiceGate1(playerid)
{
    if(PlayerToPoint(5.0,playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1)
    {
        b_MoveObject(Entrance1, 1937.729, 2137.095, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708, 2158.011, 11.531, 2);
    }
    else if(!PlayerToPoint(5.0, playerid, 1937.4944,2148.5791,10.8203) && PlayerInfo[playerid][pFaction] == 1)
    {
        b_MoveObject(Entrance1, 1937.729, 2144.566, 11.531, 2);
        b_MoveObject(Entrance2, 1937.708 ,2152.508 ,11.531, 2);
    }
}
pawn Код:
new Tow1Timer[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
  Tow1Timer[playerid] = SetTimerEx("TowServiceGate1", 1000, 1, "i", playerid);
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
  KillTimer(Tow1Timer[playerid]);
Think thats all
Reply
#19

Well, i would use MovePlayerObject function, so it will move only for a certain playerid.
Reply
#20

Quote:
Originally Posted by Don Correlli
Well, i would use MovePlayerObject function, so it will move only for a certain playerid.
okay, I will try that

EDIT: Didn't work at all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)