FPS Textdraw Problem + rep But FAST!!! -
Toxik - 10.05.2015
Hey Guys i need help with that stuff
+ Rep who help me
pawn Код:
new Text:FPS[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
FPS[playerid] = TextDrawCreate(240.0, 580.0, "Your FPS: Loading");
TextDrawShowForPlayer(playerid, FPS[playerid]);
return 1;
}
public OnPlayerUpdate(playerid)
{
new string[128]
format(string, sizeof(string), "Your FPS: %d", GetPlayerFPS(playerid));
TextDrawSetString(FPS[playerid], string);
return 1;
}
Error's
pawn Код:
C:\Users\CraTzy\Desktop\LVDM\gamemodes\LVDM.pwn(5327) : error 001: expected token: ";", but found "-identifier-"
C:\Users\CraTzy\Desktop\LVDM\gamemodes\LVDM.pwn(5327) : error 017: undefined symbol "GetPlayerFPS"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Errors.
Re: FPS Textdraw Problem + rep But FAST!!! -
Deathlane - 10.05.2015
You need to define GetPlayerFPS first
Re: FPS Textdraw Problem + rep But FAST!!! -
[KHK]Khalid - 10.05.2015
GetPlayerFPS isn't a native.
https://sampforum.blast.hk/showthread.php?tid=172085
Re: FPS Textdraw Problem + rep But FAST!!! -
Toxik - 10.05.2015
Khalid .. what is explain me that link ?
Re: FPS Textdraw Problem + rep But FAST!!! -
X337 - 10.05.2015
Add this code on your script:
Код:
stock GetPlayerFPS(playerid)
{
SetPVarInt(playerid, "DrunkL", GetPlayerDrunkLevel(playerid));
if(GetPVarInt(playerid, "DrunkL") < 100) SetPlayerDrunkLevel(playerid, 2000);
else{
if(GetPVarInt(playerid, "LDrunkL") != GetPVarInt(playerid, "DrunkL"))
{
SetPVarInt(playerid, "FPS", (GetPVarInt(playerid, "LDrunkL") - GetPVarInt(playerid, "DrunkL")));
SetPVarInt(playerid, "LDrunkL", GetPVarInt(playerid, "DrunkL"));
if((GetPVarInt(playerid, "FPS") > 0) && (GetPVarInt(playerid, "FPS") < 256))
{
return GetPVarInt(playerid, "FPS") - 1;
}
}
}
return 0;
}
Re: FPS Textdraw Problem + rep But FAST!!! -
[KHK]Khalid - 10.05.2015
It explains how you can get FPS using a little trick with drunk level. Your working code should probably be like this when you read & understand the tutorial:
pawn Код:
new
Text:FPS[MAX_PLAYERS],
pDrunkLevelLast[MAX_PLAYERS],
pFPS[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
FPS[playerid] = TextDrawCreate(240.0, 580.0, "Your FPS: Loading");
TextDrawShowForPlayer(playerid, FPS[playerid]);
return 1;
}
public OnPlayerUpdate(playerid)
{
// Getting FPS as explained in the tutorial and storing it in pFPS[] variable
new drunknew;
drunknew = GetPlayerDrunkLevel(playerid);
if (drunknew < 100) { // go back up, keep cycling.
SetPlayerDrunkLevel(playerid, 2000);
} else {
if (pDrunkLevelLast[playerid] != drunknew) {
new wfps = pDrunkLevelLast[playerid] - drunknew;
if ((wfps > 0) && (wfps < 200))
pFPS[playerid] = wfps;
pDrunkLevelLast[playerid] = drunknew;
}
}
// Done with fps!
// Update FPS textdraws
new string[128]
format(string, sizeof(string), "Your FPS: %d", pFPS[playerid]);
TextDrawSetString(FPS[playerid], string);
return 1;
}
However, and to be honest with you, your code is inefficient in many ways.
1# Why
global-textdraws when
player-textdraws could simply fit? I mean, yeah it's just a way around the limit, but you can save a slot for a textdraw that really needs to be 'global'.
2# Updating the textdraw over OnPlayerUpdate is honestly not necessary and not efficient at all. Do you realize that [url=https://sampwiki.blast.hk/wiki/OnPlayerUpdate] is called VERY frequently per second? Does your textdraw update need to be that much frequent? If you ask me, no, I'd just make an one-second timer to handle update.
3#
pawn Код:
new string[128]
format(string, sizeof(string), "Your FPS: %d", GetPlayerFPS(playerid));
I bet you weren't sober when you picked a size for this string. 128? Why? "Your FPS: 200" - the longest this string can get - is 13 characters length, and if you add the NULL character to those, you get 14. Hence, a memory friendly code should probably look like this:
pawn Код:
new string[14]
format(string, sizeof(string), "Your FPS: %d", pFPS[playerid]);