SA-MP Forums Archive
Need some help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need some help (/showthread.php?tid=96989)



Need some help - Sayaron - 12.09.2009

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);
    }
}



Re: Need some help - Sayaron - 12.09.2009

Sorry for bumping this, but I really need help with this


Re: Need some help - Correlli - 12.09.2009

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


Re: Need some help - Sayaron - 12.09.2009

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


Re: Need some help - Correlli - 12.09.2009

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


Re: Need some help - Sayaron - 12.09.2009

Thanks, I will try if this works


Re: Need some help - MadeMan - 12.09.2009

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;
    }
}



Re: Need some help - Sayaron - 12.09.2009

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?


Re: Need some help - Correlli - 12.09.2009

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


Re: Need some help - Sayaron - 12.09.2009

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


Re: Need some help - Correlli - 12.09.2009

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


Re: Need some help - Sayaron - 12.09.2009

Thanx alot, it works now


Re: Need some help - Correlli - 12.09.2009

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;
}



Re: [SOLVED]Need some help - Sayaron - 12.09.2009

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??


Re: [SOLVED]Need some help - Correlli - 12.09.2009

Have you used MadeMan's code?


Re: Need some help - Sayaron - 12.09.2009

Yeh, I tried. But got the same result


Re: Need some help - Correlli - 12.09.2009

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.


Re: Need some help - Sayaron - 12.09.2009

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


Re: Need some help - Correlli - 12.09.2009

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


Re: Need some help - Sayaron - 12.09.2009

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