What can lag a script ?

Started by KrlozZ..., Apr 13, 2017, 04:52 AM

Previous topic - Next topic

KrlozZ...

Hey guys, i have a server on cloudwards host, since like 3 weeks ago my server started lagging so hard, when it have 3+ players, i really don't know why, I have talked with the host to know if it was the host, we have joined in a cloudwards server with many custom stuff, and we did not lagged, we have changed the port of my server, but it still lagging, i should like you guys tell me what can lag a script, if there is any things which gave lag to the script. its the unique way which i think, it can be the script.

KAKAN

For newbies, its mostly timers and onPlayerMove.
oh no

KrlozZ...

Quote from: KAKAN on Apr 13, 2017, 04:59 AMFor newbies, its mostly timers and onPlayerMove.

well it's my onplayermove

function onPlayerMove( player, lastX, lastY, lastZ, newX, newY, newZ )
{
 if( !player.Vehicle )
 {
    local speed = g_PlayerFallAccum[player.ID];

    speed += lastZ > newZ ? lastZ - newZ : 0.0;

    if (speed > 1.0) onPlayerFall(player, speed);
   
    g_PlayerFallAccum[player.ID] = speed;
 }
}

It's from the parchute system by seby, but i had lag before put that system on my script.

the timers on the commands are for this commands: "gotoloc,goto,heal,armour,fix,cd,acd."

others timers are from seby parchute system, 2 timers on the script load for announces and autosave, one in onplayerjoin, other in onplayerrequestspawn.

that's all my timers, if do think any of them causing the lag, can you tell me, and i will give you it, so you will can see it carefully and tell me what's wrong with it.

PunkNoodle

Quote from: KrlozZ... on Apr 13, 2017, 05:45 AMthat's all my timers, if do think any of them causing the lag, can you tell me, and i will give you it, so you will can see it carefully and tell me what's wrong with it.
No offence mate, but before you assign your work to someone else shouldn't you at least try to mess with it yourself?
You know what you could do? Try running your server without scripts, or with default script if you prefer, and see if it's still lagging. If yes it might be the host, if not the scripts are to blame. As a second try you could try commenting out the parts of your script that you suspect might be the cause, and then readd them one by one until you find the culprit, that will also help you learning a bit more and the satisfaction of solving your own problem ;)

To comment out add /* before and */ after the code, in that way the compiler will skip that code (correct me if I'm wrong with terminology). Example:

/*
function onPlayerMove( player, lastX, lastY, lastZ, newX, newY, newZ )
{
    if( !player.Vehicle )
    {
        local speed = g_PlayerFallAccum[player.ID];
        speed += lastZ > newZ ? lastZ - newZ : 0.0;

        if (speed > 1.0) onPlayerFall(player, speed);
        g_PlayerFallAccum[player.ID] = speed;
    }
}
*/

The function onPlayerMove won't be called as if it didn't exist.

KrlozZ...

Quote from: PunkNoodle on Apr 13, 2017, 06:31 AM
Quote from: KrlozZ... on Apr 13, 2017, 05:45 AMthat's all my timers, if do think any of them causing the lag, can you tell me, and i will give you it, so you will can see it carefully and tell me what's wrong with it.
No offence mate, but before you assign your work to someone else shouldn't you at least try to mess with it yourself?
You know what you could do? Try running your server without scripts, or with default script if you prefer, and see if it's still lagging. If yes it might be the host, if not the scripts are to blame. As a second try you could try commenting out the parts of your script that you suspect might be the cause, and then readd them one by one until you find the culprit, that will also help you learning a bit more and the satisfaction of solving your own problem ;)

To comment out add /* before and */ after the code, in that way the compiler will skip that code (correct me if I'm wrong with terminology). Example:

/*
function onPlayerMove( player, lastX, lastY, lastZ, newX, newY, newZ )
{
    if( !player.Vehicle )
    {
        local speed = g_PlayerFallAccum[player.ID];
        speed += lastZ > newZ ? lastZ - newZ : 0.0;

        if (speed > 1.0) onPlayerFall(player, speed);
        g_PlayerFallAccum[player.ID] = speed;
    }
}
*/

The function onPlayerMove won't be called as if it didn't exist.

mm you are right, im srry for leave all the work for others, im doing it because i really don't know what's wrong and what can be the cause,it started since 2-3 weeks ago, and i have noticed, but thought it will be solved with the time, i have did many changes in 3 weeks, im trying to remove some things which i added 3 weeks ago, each one, i have listed them, so its easy for me, i have not tried upload my old script on the host, but i will, my principal question was about what can lag a script, so i thought it can help me to found the problem, once more im srry for tired to leave it to others, and ok, i will put that "*/" before a code.

btw i know it's not the onplayermove, i have removed that parchute system to test if it was the cause of the lag, and it was not, so i have added it again.

i will keep finding the problem of it, just want some clue about what can cause lag.

EK.IceFlake

This is where this kind of output helps:
[USR] Registering player variables...
[USR] OK [took 23 us]
[SCS] Executed script: Q:\etsx\CPlayer.nut
[DBG] Attempting to execute the delayed scripts
[SCS] Executed script: Q:\etsx\main.nut
[DBG] Completed execution of stage (0) scripts. Pending scripts 0
[USR] Connecting to SQLite...
[USR] OK [took 341 us]
[USR] Creating SQLite tables...
[USR] OK [took 587 us]
[USR] Setting server options...
[USR] OK [took 27 us]
[USR] Overwriting SqBroadcast.Message...
[USR] OK [took 24 us]
[USR] Overwriting SqPlayer.Message...
[USR] OK [took 23 us]
function Exec(msg, func)
{
    print(msg + "...");
    local timer = SqTimer();
    func();
    print("OK [took " + timer.Elapsed.Microseconds + " us]");
}