[MAP] Automatic gate

Started by MatheuS, Dec 13, 2014, 06:41 AM

Previous topic - Next topic

MatheuS

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



if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

.

#1
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.
.

Thijn

Two inpoly calls when you clearly only need 1 makes it even worse.

Do not use this, or watch your server die.

soulshaker

I have already a automatic gate in my server but guess m not using onPlayerMove

MatheuS

#4
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!
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

Nothing

Nice friend.
Thanks for sharing

PsyChO_KiLLeR

getting error here
if( bind == M )

.

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

PsyChO_KiLLeR


MacTavish

#9
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++

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

Your argument is named differently. Since this isn't the original code then I'm afraid it's not the author's fault.
.

PsyChO_KiLLeR


EK.IceFlake

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.

Decent_946

well i am having this problem!!


EK.IceFlake

Quote from: DeCeNt_BoY on May 12, 2015, 11:38 AMwell i am having this problem!!


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.