Little coding questions - For general minor queries 5

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(vehicleidCarInfo[vehicleid][cHealth]);
    
GetVehicleDamageStatus(vehicleidCarInfo[vehicleid][cPanels], CarInfo[vehicleid][cDoors], CarInfo[vehicleid][cLights], CarInfo[vehicleid][cTires]);
    return 
1;

Reply

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?
Reply

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.
Reply

anyway to optimise this

PHP код:
    if(ServerInfo[AntiSwear] == && PlayerInfo[playerid][Level] < MAX_ADMIN_LEVEL)
    {
        new 
pos;
        for(new 
sForbiddenWordCounts++)
        {
            while((
pos strfind(text,ForbiddenWords[s],true)) != -1)
            {
                for(new 
pospos strlen(ForbiddenWords[s]); ji++) text[i] = '*';
        }
    } 
+ rep for helper
Reply

Should I expect memory leaks if I don't use cache_unset_active() after a threaded 'SELECT' query?

PHP код:
main()
{
    new 
MySQL: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??

Reply

No, cache is cleared automatically after your callback function is finished.
Reply

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: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
Reply

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]);

Quote:

0
37
1
6881280
2

Whaaat?
Reply

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
Reply

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...).
Reply

Is it a bad idea to save players's data just on disconnect/payday?
Reply

Quote:
Originally Posted by GaByM
View Post
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.)
Reply

Quote:
Originally Posted by GaByM
View Post
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
Reply

You should save player data once it's changed, rather than large queries that save everything all together.
Reply

Quote:
Originally Posted by Lucases
View Post
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
View Post
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.
Reply

SAMP 0.3.8 supports custom vehicle models, right?
Reply

Quote:
Originally Posted by NealPeteros
View Post
SAMP 0.3.8 supports custom vehicle models, right?
No 0.3.8 not supports custom vehicles
Reply

how can i make put player in boot i need help
Reply

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
Reply

Quote:
Originally Posted by GaByM
View Post
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(ranknamesizeof ranknamegRanks[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.
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)