SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 28/02/2018, 10:21 AM   #1
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 143
Reputation: 20
Default Profiler result's -Optimization mode

I want to optimize my gamemode and I need some help.I'm put profiler plugin on my server from 01:00 to 11:23 today,so i'm get results.

So there are picture who don't want to download:
https://i.imgur.com/dYcv4Fd.png

So if you can tell me what i need to opimize,because i'm not sure what i need to look on this profiler results.For example i don't understand this:

Quote:
operator>=(Float:,Float 1515576 6.83%
operator>(Float:,Float 1281151 3.33%

Is this much?
Quote:
floatcmp 13220491 3.75%
I use floatcmp just in one line in my mode.For afk check

Short code:

Code:
function AFKCheck(playerid)
{
	GetPlayerPos(playerid, PlayerCurrentPos[playerid][0], PlayerCurrentPos[playerid][1], PlayerCurrentPos[playerid][2]);
	if(!floatcmp(PlayerCurrentPos[playerid][0], PlayerLastPos[playerid][LastX]) && !floatcmp(PlayerCurrentPos[playerid][1], PlayerLastPos[playerid][LastY]))
	{
		PovecajPVarInt(playerid, "PlayerAFK", 1);
	}
	else
	{
		SetPVarInt(playerid, "PlayerAFK", 0);
   		AFK[playerid] = false;
	}
	PlayerLastPos[playerid][LastX] = PlayerCurrentPos[playerid][0];
	PlayerLastPos[playerid][LastY] = PlayerCurrentPos[playerid][1];
	PlayerLastPos[playerid][LastZ] = PlayerCurrentPos[playerid][2];

	if(GetPVarInt(playerid, "PlayerAFK") >= 20)
	{
          //kick(afk 20 minute)
        }
       return 1;
}

Quote:
GetSpeed 790181 8.17%
This function I use in OnPlayerUpdate( if(GetSpeed > 299) kick

Code:
GetSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
    GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
    else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 178.8617875;
    return floatround(ST[3]);
}
I'm upload full .html file in attachmens.Thank you
Attached Files
File Type: rar v58.rar (15.3 KB, 13 views)
GospodinX is offline   Reply With Quote
Old 28/02/2018, 01:13 PM   #2
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 143
Reputation: 20
Default Re: Profiler result's -Optimization mode

First I need to say that my English is not very good,so i hope you will understand me.

1. I had some problems when i had 250+ players(for example my IC Chat is became global chat and also it was start lagg little) ->This is RP server so..I don't use Global Chat) So i'm sure that i need some optimization.Also I need to say that i don't have often a large number of players,so i don't have chance now to turn on profiler with 250+ players(I had it on celebration two years of server so there was many visitors and friends which are not our active players.)

This profiler is turn on midnight(In my time) so we don't have many players at that time .I will post tonight results also.

2.Maybe you are not see,but i'm post full .html file in attachment's.


3.I will look on OnPlayerUpdate,i have GetSpeed check,AntiChaet for Weapons and some check which I can transfer on second timer,it will be better,i think.

FC_OnPlayerUpdate is from include "fuckcleo.inc"
https://pastebin.com/AVrySvAH

So I'm not sure about it.

Thank you very much on answer!
GospodinX is offline   Reply With Quote
Old 08/06/2018, 06:36 PM   #3
AmigaBlizzard
Huge Clucker
 
Join Date: Jul 2012
Posts: 320
Reputation: 60
Default Re: Profiler result's -Optimization mode

I can get why you want to kick cheaters fast, but using OnPlayerUpdate is overkill.
This callback is called at least 30 times per second FOR EVERY PLAYER.
If you have 250 players online, you're executing OnPlayerUpdate 7500 times or more every second.

It won't hurt your server when you just transfer all that code to a 1-second timer.
Then that code runs 250 times per second, which is more than enough.

Optimization starts with clearing OnPlayerUpdate.
I never used that callback and I never will, because I can see no reason for any code that needs to run 30 times per second.

If someone cheats with a speed hack, kicking him within 30ms or 1 second won't make any difference, the cheater will be kicked before he can do more damage anyways.
He won't do that much extra damage in 1 second.
AmigaBlizzard is offline   Reply With Quote
Old 08/06/2018, 09:25 PM   #4
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,514
Reputation: 305
Default Re: Profiler result's -Optimization mode

Quote:
Originally Posted by AmigaBlizzard View Post
I can get why you want to kick cheaters fast, but using OnPlayerUpdate is overkill.
This callback is called at least 30 times per second FOR EVERY PLAYER.
If you have 250 players online, you're executing OnPlayerUpdate 7500 times or more every second.

It won't hurt your server when you just transfer all that code to a 1-second timer.
Then that code runs 250 times per second, which is more than enough.
Using OnPlayerUpdate as a timer is not an overkill but, a very big mistake.
I've kept my anti cheat timer to call every 1.5~2 seconds.

So for say, my timer will call 2 times in 3 seconds instead of 3. It may not make a very big difference, so why put unnecessary load?

Quote:
Originally Posted by AmigaBlizzard View Post
Optimization starts with clearing OnPlayerUpdate.
I never used that callback and I never will, because I can see no reason for any code that needs to run 30 times per second.
The only reason why anyone will use it is when they're making an Anti AFK system, since OnPlayerUpdate is not called when they are paused.

---

@OP: You can also use GetServerTickRate when you've lots of players in the daytime and let us know of the result.

PHP Code:
CMD:tickrate(playerid)
{
    new 
str[25];
    
format(strsizeof str"Server tickrate: %d."GetServerTickRate());
    
SendClientMessage(playeridCOLOR_GREYstr);
    return 
1;

Logic_ is offline   Reply With Quote
Old 21/10/2018, 03:34 PM   #5
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 143
Reputation: 20
Default Re: Profiler result's -Optimization mode

Hi guys,

I need help with optimization one my function which is very bad.This function need to count number of seconds of started event.(It shows for all players in game how much is passed seconds from the starting event)

When I start event:
Code:
        EventCount = GetTickCount();
	UpdateEvent();
	eventtimer = SetTimer("UpdateEvent",990,true);
Code:
forward UpdateEvent();
public UpdateEvent()
{
	new rTime[3];
	new string[10];
  	new TimeStamp,TotalEventTime;
  	TimeStamp = GetTickCount();
  	TotalEventTime = TimeStamp - EventCount;
  	ConvertTime(var, TotalRaceTime, rTime[0], rTime[1], rTime[2]);
  	format(string, sizeof string, "%02d:%02d",rTime[0], rTime[1]);
  	TextDrawSetString(TDEvent, string);
}
ConvertTime(used in UpdateEvent)
Code:
#define ConvertTime(%0,%1,%2,%3,%4) \
	new \
	    Float: %0 = floatdiv(%1, 60000) \
	;\
	%2 = floatround(%0, floatround_tozero); \
	%3 = floatround(floatmul(%0 - %2, 60), floatround_tozero); \
	%4 = floatround(floatmul(floatmul(%0 - %2, 60) - %3, 1000), floatround_tozero)

Profiler result for this function:

This is 4. worst function in my mode,so I want to optimize this.Maybe someone have better idea for counting number of seconds?Thanks
GospodinX is offline   Reply With Quote
Old 21/10/2018, 07:02 PM   #6
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 143
Reputation: 20
Default Re: Profiler result's -Optimization mode

Ohh.
This is one-second timer,so If I convert number of calls into hours i will get: 1175 hours .
1175 hours to days = 48 days(but my mode is started only 2 days with profiler)
It's not possible. So I have mistake in mode(I have stoptimer,but maybe some time it doesn't stop.) I will test it.

2)
Quote:
except stop using arrays for normal variables, but that's a general rule everywhere
You think that I should use:
Code:
new rTime1,rTime2,rTime3 ;
instead
Code:
new rTime[3];
GospodinX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Profiler StrikerZ Scripting Help 6 08/01/2017 03:16 PM
[Profiler result] Gamemode is generating lags Amads Scripting Help 4 14/08/2016 02:21 PM
RAM profiler Tamer Discussion 8 06/10/2015 07:23 PM
[HELP] Profiler monster010 Scripting Help 3 26/06/2014 09:41 PM
[Include] profiler.inc - plugin-less profiler Zeex_ Includes 6 04/02/2012 06:16 AM


All times are GMT. The time now is 10:30 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.