Re: Little coding questions - For general minor queries 5 -
Dayrion - 04.12.2017
Quote:
Originally Posted by [HLF]Southclaw
Depends what the actual code is. If it's just a bit of math and a function call or two, that's nothing in the grand scheme of things and would not make any significant change to performance if used in OPU.
|
Currently, it's a timer. I don't know if it can make any significant change.
PHP код:
ptask UpdateVehicleHealth[250](playerid)
{
if(!IsPlayerInAnyVehicle(playerid))
return 1;
new vehicleid = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicleid, CarInfo[vehicleid][cHealth]);
GetVehicleDamageStatus(vehicleid, CarInfo[vehicleid][cPanels], CarInfo[vehicleid][cDoors], CarInfo[vehicleid][cLights], CarInfo[vehicleid][cTires]);
return 1;
}
Re: Little coding questions - For general minor queries 5 -
GaByM - 11.12.2017
Hello, I'm converting my gamemode from SQLite to MySQL and I was wondering: should I convert everything? or should i keep some tables on sqlite?
Re: Little coding questions - For general minor queries 5 -
Abagail - 11.12.2017
Quote:
Originally Posted by GaByM
Hello, I'm converting my gamemode from SQLite to MySQL and I was wondering: should I convert everything? or should i keep some tables on sqlite?
|
Keep everything under the same system unless there's a specific need for it not to be.
Re: Little coding questions - For general minor queries 5 -
xMoBi - 15.12.2017
anyway to optimise this
PHP код:
if(ServerInfo[AntiSwear] == 1 && PlayerInfo[playerid][Level] < MAX_ADMIN_LEVEL)
{
new pos;
for(new s; s < ForbiddenWordCount; s++)
{
while((pos = strfind(text,ForbiddenWords[s],true)) != -1)
{
for(new i = pos, j = pos + strlen(ForbiddenWords[s]); i < j; i++) text[i] = '*';
}
}
+ rep for helper
Re: Little coding questions - For general minor queries 5 -
GaByM - 16.12.2017
Should I expect memory leaks if I don't use cache_unset_active() after a threaded 'SELECT' query?
PHP код:
main()
{
new MySQL:d = mysql_connect("localhost", "gabi", "gabi", "test");
mysql_tquery(d, "SELECT * FROM alog;", "ff");
return 1;
}
forward ff();
public ff()
{
//cache_get_value_name..
//cache_get_value_name_int...etc
return 1;//Results deleted??
}
Re: Little coding questions - For general minor queries 5 -
Misiur - 16.12.2017
No, cache is cleared automatically after your callback function is finished.
Re: Little coding questions - For general minor queries 5 -
rfr - 16.12.2017
Quote:
Originally Posted by GaByM
Should I expect memory leaks if I don't use cache_unset_active() after a threaded 'SELECT' query?
PHP код:
main()
{
new MySQL:d = mysql_connect("localhost", "gabi", "gabi", "test");
mysql_tquery(d, "SELECT * FROM alog;", "ff");
return 1;
}
forward ff();
public ff()
{
//cache_get_value_name..
//cache_get_value_name_int...etc
return 1;//Results deleted??
}
|
return 1;//Results deleted??
yes its cleared. you wont get memory leaks
Re: Little coding questions - For general minor queries 5 -
GaByM - 17.12.2017
PHP код:
#include <a_samp>
main()
{
new k[4];
printf("%i", k[0]);
printf("%i", k[0]++);
printf("%i", k[0]);
printf("%i", ++k[0]);
printf("%i", k[0]);
}
Whaaat?
Re: Little coding questions - For general minor queries 5 -
Nero_3D - 17.12.2017
Quote:
Originally Posted by GaByM
PHP код:
#include <a_samp>
main()
{
new k[4];
printf("%i", k[0]);
printf("%i", k[0]++);
printf("%i", k[0]);
printf("%i", ++k[0]);
printf("%i", k[0]);
}
Whaaat?
|
Probably a bug in the compiler, it seems to push the value instead of the addresses if you use ++ or --
So you probably should avoid using ++ or -- with variadic functions (e.g: printf, format), normal functions should work fine
If you want you can post a bug report in the compiler project ->
https://github.com/Zeex/pawn
Re: Little coding questions - For general minor queries 5 -
Misiur - 17.12.2017
pawn Код:
#include <a_samp>
main()
{
new k[4];
printf("%d", ++k[0]);
}
pawn Код:
code 0 ; 0
;program exit point
halt 0
proc ; main
; line 4
break ; c
; line 5
break ; 10
;$lcl k fffffff0
stack fffffff0
zero.pri
addr.alt fffffff0
fill 10
; line 6
break ; 30
addr.pri fffffff0
inc.i
load.i
push.pri
;$par
zero.pri
push.pri
;$par
push.c 8
sysreq.c 0 ; printf
stack c
;$exp
stack 10
zero.pri
retn
data 0 ; 0
dump 25 64 0
stksize 100000
Huh, I'm almost certain I have used that construct without any problems in the past (or I didn't test and there are bugs floating around...).
Re: Little coding questions - For general minor queries 5 -
GaByM - 24.12.2017
Is it a bad idea to save players's data just on disconnect/payday?
Re: Little coding questions - For general minor queries 5 -
Sew_Sumi - 24.12.2017
Quote:
Originally Posted by GaByM
Is it a bad idea to save players's data just on disconnect/payday?
|
It should be every 5 minutes or so. With a forced save via commands that will shut down the server, or via an admin command that can simply be used to save manually.
As long as you don't overload timers, it's a good idea to save as much as you can. (Just prioritize what you are saving in these sweeps too. Level, cash, position... Good things to save. Bad things to save all the time, are things like IP (As it only needs to be noted once per session as it won't change) or passwords, and any variables that don't actually change as much.)
Re: Little coding questions - For general minor queries 5 -
Lucases - 24.12.2017
Quote:
Originally Posted by GaByM
Is it a bad idea to save players's data just on disconnect/payday?
|
It's not a bad idea, but there might be server crashes or some cases where OnPlayerDisconnect doesn't get called so your players can lose their last session stats.
I prefer saving after each paycheck
Re: Little coding questions - For general minor queries 5 -
Dignity - 24.12.2017
You should save player data once it's changed, rather than large queries that save everything all together.
Re: Little coding questions - For general minor queries 5 -
[HLF]Southclaw - 24.12.2017
Quote:
Originally Posted by Lucases
some cases where OnPlayerDisconnect doesn't get called
|
I'm interested, I'd like to know examples of these cases.
Quote:
Originally Posted by Dignity
You should save player data once it's changed, rather than large queries that save everything all together.
|
Yes, this is the best solution. Unless it's a metric that changes very often, save it only when it changes. And remember you don't need to save every metric at the same time, just save the bits that change.
Re: Little coding questions - For general minor queries 5 -
NealPeteros - 25.12.2017
SAMP 0.3.8 supports custom vehicle models, right?
Re: Little coding questions - For general minor queries 5 -
BulletRaja - 25.12.2017
Quote:
Originally Posted by NealPeteros
SAMP 0.3.8 supports custom vehicle models, right?
|
No 0.3.8 not supports custom vehicles
Re: Little coding questions - For general minor queries 5 -
BulletRaja - 25.12.2017
how can i make put player in boot i need help
Re: Little coding questions - For general minor queries 5 -
GaByM - 26.12.2017
What can happen if I use a function to return a string? I heard is is bad practice, but idk when, how and what could happen
Re: Little coding questions - For general minor queries 5 -
Logic_ - 26.12.2017
Quote:
Originally Posted by GaByM
What can happen if I use a function to return a string? I heard is is bad practice, but idk when, how and what could happen
|
Actually its better to use a function to return any kind of data, it can be from a array, the function itself or the database because it's better to read the code and cleaner. And about the practice matters, it's a good practice because of readability but not optimization.
I now consider readability and optimization both important together whenever possible but when it's not, I go for readability (matters though)...
So look in my COD script I've a array with rank names and their scores, I use a function called return
PHP Code:
GetRankName(rankid) {
new rankname[MAX_RANK_NAME_LEN];
format(rankname, sizeof rankname, gRanks[rankid][E_RANK_NAME]);
return rankname;
} // Written in the web browser, neglect the indentation
which just makes this code
PHP Code:
gRanks[rankid][E_RANK_NAME]
more easier to read and write.