Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: MatheuS on Dec 13, 2014, 06:41 AM

Title: [MAP] Automatic gate
Post by: MatheuS on Dec 13, 2014, 06:41 AM
made some changes to now open the gate by pressing the "M" button to not cause errors and lags

Script

function onServerStart()
{
gate <- array( GetMaxPlayers(), null );
        gateStatus = true;
gate = CreateObject( 310, 1, -276.618, -495.992, 10.2778, 255 );
}
function onScriptLoad()
{
gateStatus <- array( GetMaxPlayers(), null );
        M <- BindKey(true, 0x4D,0,0);
}

function onKeyDown( player, bind )
{
if( bind == M )
{
          if ( InPoly( player.Pos.x, player.Pos.y, -276.475, -501.47,-268.81, -501.221,-268.959, -489.333,-276.775, -490.022 ) )
          {
          Gate1( player );
          }
        }
}

Functions

function Gate1( player )
{
    if ( InPoly( player.Pos.x, player.Pos.y, -276.475, -501.47,-268.81, -501.221,-268.959, -489.333,-276.775, -490.022 ) && gateStatus == true )
    {
        gate.MoveTo(Vector( -268.576, -495.99, 10.2778), 2800 );
        gateStatus = false;
        }
        else
        {
        if ( gateStatus == false )
        {
            gate.MoveTo(Vector(-276.618, -495.992, 10.2778), 2800 );
            gateStatus = true;
        }
}
}

Pictures

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FPVK7piw.jpg&hash=b0aeb485a7253225db5ceb4d313471f708a313b6)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FVTzVm5y.jpg&hash=717badd632698fa9cb17e258d0f40be06e141fb1)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2F2tYptLq.jpg&hash=e3304781b507ab2683b5f4d0cf4e99fc132fd6e2)
Title: Re: [MAP] Automatic gate
Post by: . on Dec 13, 2014, 07:17 AM
This will lag the sh!t out of a full server :D Imagine 50 players moving which can almost cause 10 onPlayerMove() calls per second for each player. Therefore 50 * ~10 = ~500 Gate1() calls per second. I know it's not much but think of it when you start adding more of those gates and other things like that where you depend on the onPlayerMove() function. There wont be any room left for the rest of the code.

Suggestion:

Create a general action key-bind and when the action key-bind is pressed then test in which area the player is currently located and trigger the effect withing that area (if any). This allows for multiple automatic gates and other things on the server without lagging the sh!it out of it.
Title: Re: [MAP] Automatic gate
Post by: Thijn on Dec 14, 2014, 11:04 AM
Two inpoly calls when you clearly only need 1 makes it even worse.

Do not use this, or watch your server die.
Title: Re: [MAP] Automatic gate
Post by: soulshaker on Dec 14, 2014, 11:54 AM
I have already a automatic gate in my server but guess m not using onPlayerMove
Title: Re: [MAP] Automatic gate
Post by: MatheuS on Dec 14, 2014, 03:20 PM
Quote from: Thijn on Dec 14, 2014, 11:04 AMTwo inpoly calls when you clearly only need 1 makes it even worse.

Do not use this, or watch your server die.
Update

Inpoly and onplayermove removed!
Title: Re: [MAP] Automatic gate
Post by: Nothing on Dec 26, 2014, 01:40 PM
Nice friend.
Thanks for sharing
Title: Re: [MAP] Automatic gate
Post by: PsyChO_KiLLeR on Feb 27, 2015, 03:26 PM
getting error here
if( bind == M )
Title: Re: [MAP] Automatic gate
Post by: . on Feb 27, 2015, 03:32 PM
Quote from: Squirrel Master on Feb 27, 2015, 03:26 PMgetting error here
if( bind == M )

Man this is the third time you do this sh!t. Can you at least tell us the error.
Title: Re: [MAP] Automatic gate
Post by: PsyChO_KiLLeR on Feb 27, 2015, 06:42 PM
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi61.tinypic.com%2Favl8xj.png&hash=6db01192c6f57eaaf70570014a9cebc74686246b)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi59.tinypic.com%2Ffedngm.png&hash=c54af440aa607ab61b6a0c2a59a4053c1d838a74)



Check it now
Title: Re: [MAP] Automatic gate
Post by: MacTavish on Feb 27, 2015, 06:46 PM
Similar problem change bind == M To key == M Then see what happens


And dont use pawnox that tool is for other language better use Notepad++
Title: Re: [MAP] Automatic gate
Post by: . on Feb 27, 2015, 06:47 PM
Your argument is named differently. Since this isn't the original code then I'm afraid it's not the author's fault.
Title: Re: [MAP] Automatic gate
Post by: PsyChO_KiLLeR on Feb 27, 2015, 07:08 PM
oh yeah
Thanks
Title: Re: [MAP] Automatic gate
Post by: EK.IceFlake on Feb 28, 2015, 05:15 AM
Quote from: Squirrel Master on Feb 27, 2015, 07:08 PMoh yeah
Thanks

I wonder from whereever you are a squirrel master, let alone a copying master. You dont know what bind means and what you are supposed to change it to by looking at how the code works. I suggest you, try making one script completely of your own and when it is totally completed, then show us what doesnt work, but not before completing it. We'll be glad to help, you'll be glad to learn.
Title: Re: [MAP] Automatic gate
Post by: Decent_946 on May 12, 2015, 11:38 AM
well i am having this problem!!

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FQ1iUiBn.jpg&hash=b62589952f8da990fe02e671c4119ca8532b327f)
Title: Re: [MAP] Automatic gate
Post by: EK.IceFlake on May 12, 2015, 12:30 PM
Quote from: DeCeNt_BoY on May 12, 2015, 11:38 AMwell i am having this problem!!

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FQ1iUiBn.jpg&hash=b62589952f8da990fe02e671c4119ca8532b327f)
onServerStart is executed before onScriptLoad so that variable would not be initialized. I suggest you to take "gateStatus <- ..." to onServerStart and above the line that error is occurring.
P.S. Nice editor! If its like Atom, pressing CTRL + [Arrow up] will move a line.
Title: Re: [MAP] Automatic gate
Post by: Decent_946 on May 12, 2015, 01:23 PM
Quote from: NE.CrystalBlue on May 12, 2015, 12:30 PMonServerStart is executed before onScriptLoad so that variable would not be initialized. I suggest you to take "gateStatus <- ..." to onServerStart and above the line that error is occurring.
well i did that, again same error occurs.. just number of line changed.. :/
Quote from: NE.CrystalBlue on May 12, 2015, 12:30 PMP.S. Nice editor! If its like Atom, pressing CTRL + [Arrow up] will move a line
thankx!! and the key CTRL + SHIFT + [ARROW UP]     Worked for me!! ;)
Title: Re: [MAP] Automatic gate
Post by: . on May 12, 2015, 04:40 PM
@DeCeNt_BoY This is off-topic but press Control+Shift+P inside Sublime Text and then type SSD (case insensitive) and then hit enter. Trust me, it'll be an improvement on syntax highlighting ;)

Quote from: NE.CrystalBlue on May 12, 2015, 12:30 PMP.S. Nice editor! If its like Atom, pressing CTRL + [Arrow up] will move a line.

Same thing works in Notepad++ too ;)
Title: Re: [MAP] Automatic gate
Post by: EK.IceFlake on May 13, 2015, 02:14 PM
Quote from: DeCeNt_BoY on May 12, 2015, 01:23 PM
Quote from: NE.CrystalBlue on May 12, 2015, 12:30 PMonServerStart is executed before onScriptLoad so that variable would not be initialized. I suggest you to take "gateStatus <- ..." to onServerStart and above the line that error is occurring.
well i did that, again same error occurs.. just number of line changed.. :/
Well... Did you put that dude above* that line?
Title: Re: [MAP] Automatic gate
Post by: Decent_946 on May 13, 2015, 02:31 PM
yeah!!!
Title: Re: [MAP] Automatic gate
Post by: MacTavish on May 14, 2015, 04:21 AM
Simply put everthing in onScriptLoad()

function onScriptLoad()
{
 gateStatus <- array( GetMaxPlayers(), null );
        M <- BindKey(true, 0x4D,0,0);

 gate <- array( GetMaxPlayers(), null );
        gateStatus = true;
 gate = CreateObject( 310, 1, -276.618, -495.992, 10.2778, 255 );
}
Title: Re: [MAP] Automatic gate
Post by: UncleRus on Oct 07, 2022, 01:58 PM
in console bind not find how to do fix it