SA-MP Forums Archive
[Plugin] MultiThread - 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: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] MultiThread (/showthread.php?tid=264178)

Pages: 1 2 3 4


Re: MultiThread - AirKite - 28.05.2014

Hmm... How about use thread for calculates? Example:
pawn Код:
new tickid;
new Float:PlayerVelocity[MAX_PLAYERS][3];
new PlayerSpeed[MAX_PLAYERS];

public OnGameModeInit() {
    tickid = CreateThread("CalculateSpeed");
}

public OnGameModeExit() {
    DestroyThread(tickid);
}

public CalculateSpeed(threadid) {
    for(new i; i < MAX_PLAYERS; i++) {
        PlayerSpeed[i] = floatround(floatsqroot(floatabs(floatpower(PlayerVelocity[i][0] + PlayerVelocity[i][1] + PlayerVelocity[i][2],2))) * 100)
    }
    SleepThread(100);
}

public OnPlayerUpdate(playerid) {
    GetVehicleVelocity(GetPlayerVehicleID(playerid), PlayerVelocity[playerid][0], PlayerVelocity[playerid][1], PlayerVelocity[playerid][2]);
    // Here send to player (PlayerSpeed[playerid])
}
UPD: Server anyway crashes