Little coding questions - For general minor queries 5

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
The limit isn't from MySQL but rather from pawn. My script usually dies (process stops working) if I use an array over 2048 size which isn't that odd. Anyhow, if you really want to create a big array, go with 2048 as size for the string.

Why they need to have 126? They don't really have to, it's just that most people setup strings like that, although they usually use 128 instead of 126 . Only thing that it tells is how long your string will be, and with string I mean char array.

Remember the one-dimensional row? Well strings are one-dimensional character arrays in pawn.
Код:
new string[5] = "Hello";

string[0] == 'H'
string[1] == 'e'
string[2] == 'l'
string[3] == 'l'
string[4] == 'o'
It's basically a table (or well a row) with cell values, just like any other array. Bottom line is that you should only assign the length of an array, of which you think you will use. So if you are just going to create a simple UPDATE with one value changing (example below) then it shouldn't be a too long array, mostly I use 128 for those.
Код:
new query[128];
format(query, sizeof(query), "UPDATE some_table SET some_column_name = %i", some_integer);
However if I want to update the WHOLE table on one row, I would need a bigger array, perhaps even run 2 MySQL queries depending on how many columns you want to update. Usually the biggest table you will have in terms of columns is your main account holder, you know pInfo[playerid][pAge] or whatever you use for instance, those will usually be the biggest ones so it's probably wise to go with the highest value if you're not sure how big it is, even dividing it into two queries as I suggested above.

The point of assigning smaller sized arrays is that, you wouldn't want to fill your room with lots of space but not filling it with items right? Same thing with arrays, you don't want to create more "spots" (indexes) than it has to be, sure it's still nice to have some space left over in the room, same in the array just to be sure.

EDIT: Sorry I started typing when there was no response.

EDIT2: Just read the above response, the limit is not 125 lmao.
He set his string length to 126, so his limit is 125 characters.

However if he needs more he could set it to something larger.

And the query example you gave could have the string length set to something lower.

Код:
new query[64];
format(query, sizeof(query), "UPDATE some_table SET some_column_name = %i", some_integer);
That is due to the string length being 44, accounting for the null terminator but not accounting for the actual integer size.
Reply

Quote:
Originally Posted by Spmn
Посмотреть сообщение
You forgot about null terminator.
Yes you are right my bad!

Quote:
Originally Posted by princejeet1510
Посмотреть сообщение
So an array for sure has to have one null character...?
Yes. Very often we don't really do array[exact-size] = "some string" but instead we do like Jeroen52 posted above with empty brackets [], that will leave up to the compiler (I'm not sure if compiler?) to set a size on it so you do not have to worry about it. Usually you don't need to set an exact size on a char array because you "guess" its length the same way you do in your MySQL tables, you set for instance a varchar(128) because you don't know if the input will be 50 long or 100 long, etc.

Edit: Jeroen52 that wasn't a question, regarding the UPDATE I made, but thank you anyways lmao. The size of an UPDATE query depends on how long your column and table name is as well for instance.
Reply

Lmao...
I appreciate you all....
Really I still can't imagine that this answer is when I asked the easiest way...xD
Never mind ,I got it.....now I think I should start doing more practice on them and then see the results....
Reply

Well....Here I'm once again....
To ask one of the another things.....I got in my mind while I was about to sleep....xD
So it was that is there any way to save a player logs....I mean right now if a player use any command or do whatever it prints on "SERVER CONSOLE" so is there anyway possible to make those log appear in either a MySQL table or either something which would create a file or so which will save every log of that particular player??
Reply

Yes, create a file/ open the file on the player connect, and close the file on disconnect, write everytime player does something :P
Reply

Quote:
Originally Posted by princejeet1510
Посмотреть сообщение
Well....Here I'm once again....
To ask one of the another things.....I got in my mind while I was about to sleep....xD
So it was that is there any way to save a player logs....I mean right now if a player use any command or do whatever it prints on "SERVER CONSOLE" so is there anyway possible to make those log appear in either a MySQL table or either something which would create a file or so which will save every log of that particular player??
Personally, I save logs in a .log or .txt file.
Like this:
PHP код:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    
WriteLogs("AllTchat.txt"cmdtextplayerid); // saving every command like "/ufckingcuntasshole"
    
if(!successErrorMsg(playerid_"The command '%s' doesn't exist."cmdtext);
    else if(
success)
        
WriteLogs("AllCommands.txt"cmdtextplayerid); // if the command is right, I save it in an another file
    
return 1;

+
PHP код:
public OnPlayerText(playeridtext[])
{
    
WriteLogs("AllTchat.txt"textplayerid);
... 
By the way, WriteLogs is a custom function:
PHP код:
WriteLogs(file[70], const reason[], playerid INVALID_PLAYER_ID)
{
    static     
day,
            
month,
            
hour,
            
minute,
            
seconde,
            
year;
    new        
stringW[190];
    if(
strfind(file".txt"false0) == -1)
        
format(filesizeof(file), "%s.txt"file);
    new 
File:pos=fopen(fileio_append);
    if(!
pos)
    {
        
printf("[Server] Write Logs Error | Reason : pos=fopen Error | File : '%s' | Reason: '%s'"filereason);
        
SendMessageToAdmins(RED"[Server] "SAUMON_U" An error occurred in the logs. Please check them!");
        
SendMessageToAdmins(RED"[Server] "SAUMON_U"File : '%s' | Include : '%s'"filereason);
        return 
1;
    } 
    
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    if(!
strcmp(file"AllCommands.txt"))
        
format(stringW,sizeof(stringW),"\r\n[%i] [%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"CmdID++, daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    else if(!
strcmp(file"AllTchat.txt"))
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s (Player #%i) » '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"p_NameOff{playerid}, reason);
    else
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    
fwrite(pos,stringW);
    
fclose(pos);
    return 
1;

Reply

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Personally, I save logs in a .log or .txt file.
Like this:
PHP код:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    
WriteLogs("AllTchat.txt"cmdtextplayerid); // saving every command like "/ufckingcuntasshole"
    
if(!successErrorMsg(playerid_"The command '%s' doesn't exist."cmdtext);
    else if(
success)
        
WriteLogs("AllCommands.txt"cmdtextplayerid); // if the command is right, I save it in an another file
    
return 1;

+
PHP код:
public OnPlayerText(playeridtext[])
{
    
WriteLogs("AllTchat.txt"textplayerid);
... 
By the way, WriteLogs is a custom function:
PHP код:
WriteLogs(file[70], const reason[], playerid INVALID_PLAYER_ID)
{
    static     
day,
            
month,
            
hour,
            
minute,
            
seconde,
            
year;
    new        
stringW[190];
    if(
strfind(file".txt"false0) == -1)
        
format(filesizeof(file), "%s.txt"file);
    new 
File:pos=fopen(fileio_append);
    if(!
pos)
    {
        
printf("[Server] Write Logs Error | Reason : pos=fopen Error | File : '%s' | Reason: '%s'"filereason);
        
SendMessageToAdmins(RED"[Server] "SAUMON_U" An error occurred in the logs. Please check them!");
        
SendMessageToAdmins(RED"[Server] "SAUMON_U"File : '%s' | Include : '%s'"filereason);
        return 
1;
    } 
    
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    if(!
strcmp(file"AllCommands.txt"))
        
format(stringW,sizeof(stringW),"\r\n[%i] [%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"CmdID++, daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    else if(!
strcmp(file"AllTchat.txt"))
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s (Player #%i) » '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"p_NameOff{playerid}, reason);
    else
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    
fwrite(pos,stringW);
    
fclose(pos);
    return 
1;

Love you man.....Thanks I got the idea....Now....One more thing....Do it worth making the log system save in a table in MySQL or would be better as .txt or .log file?
Reply

Quote:
Originally Posted by princejeet1510
Посмотреть сообщение
Love you man.....Thanks I got the idea....Now....One more thing....Do it worth making the log system save in a table in MySQL or would be better as .txt or .log file?
If you are gonna use it externally, like showing it in the site or something yeah.
If you are always gonna check it manually (opening the file and reading it thru) then no.
Reply

Did anyone else ever encountered something like this... https://sampforum.blast.hk/showthread.php?tid=628077 for fuck sake I've been on all nigh looking at this script tring to understand what is wrong, bracket by bracket, dot by dot, letter by letter, EVERYTHING looks okay, I don't know what is causing this..
Reply

You are directly using the ID you get from the game as the array index, What makes you think that the i you set is the same as CreateVehicle?

Here's 3 options for you;

1- You need to load the data into a dummy array, then create the vehicle and use that as the index to insert the data into if you want to be able to use the GetPlayerVehicleID as the index.
2- Or you should change that creating part to
Quote:
pvehicle[i] = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPos_x], VehicleInfo[i][vPos_y], VehicleInfo[i][vPos_z], VehicleInfo[i][vRot], VehicleInfo[i][vColor1], VehicleInfo[i][vColor2], VehicleInfo[i][vRespawnDelay]);

and then loop pvehicle to find the index.
3- or an alternative way would be creating a global array to link them then do
PHP код:
new vehCreateVehicle(...)
vArrayIndex[veh]=i
now you can use vArrayIndex[GetPlayerVehicleID(playerid)] as your index for the array.
Reply

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
Nothing I just think that you should reconsider using timestamps instead hence it is timezone independent. And you can always retrieve date time and year from it.
Just to clarify and to avoid confusion, it is the Unix Timestamp.
As of writing this message, the Unix Timestamp is 1487031097.
Reply

Any way to kill a timer without knowing its "index number" (not sure if it's the right words). Basically something like in other languages you have "this", I was just wondering if it was somehow possible to kill a timer within the timer itself without saving it anywhere. It sounds silly but just a question.
Reply

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Any way to kill a timer without knowing its "index number" (not sure if it's the right words). Basically something like in other languages you have "this", I was just wondering if it was somehow possible to kill a timer within the timer itself without saving it anywhere. It sounds silly but just a question.
Well the function to kill a timer itself, 'KillTimer' requires the timer ID regardless, so without knowing the timer ID, you can't kill it specifically.
Reply

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Any way to kill a timer without knowing its "index number" (not sure if it's the right words). Basically something like in other languages you have "this", I was just wondering if it was somehow possible to kill a timer within the timer itself without saving it anywhere. It sounds silly but just a question.
You could just make the repeat to false it will kill the timer, right? It somehow stop the timer and the killtimer function basically stops the timer.

but if you meant to really erase the timer from memory, just like killtimer does. Then it's an almost impossible feat, but doable

Basically when a timer is created the server had created it's index for it, I don't have a clue whether it is by random or an auto increment value from 0 to infinity

which is why an indexed timer can be killed.

That without index thing, is oh boy a almost impossible feat, but doable.

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Well the function to kill a timer itself, 'KillTimer' requires the timer ID regardless, so without knowing the timer ID, you can't kill it specifically.
or he could just basically not let the timer repeat itself after a certain interval same thing as killing it.

or am I just off the topic coz I've made sure to back read. or have I not backread enough?
Reply

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
he could just basically not let the timer repeat itself after a certain interval same thing as killing it
That would just be considered letting the timer complete its purpose. That isn't killing the timer. If you were to set a timer that didn't repeat, you would still need the timer ID if you were to kill it before it was executed. Letting the timer be executed and not be repeated wouldn't be considered killing the timer and requires no interaction anyway.

Timer IDs start from 1 and continually increment, but timer IDs are never reused, so each timer that is ever set has its own unique id.
Reply

Quote:
Originally Posted by Threshold
Посмотреть сообщение
That would just be considered letting the timer complete its purpose. That isn't killing the timer. If you were to set a timer that didn't repeat, you would still need the timer ID if you were to kill it before it was executed. Letting the timer be executed and not be repeated wouldn't be considered killing the timer and requires no interaction anyway.

Timer IDs start from 1 and continually increment, but timer IDs are never reused, so each timer that is ever set has its own unique id.
Just one big question?

Isn't OnPlayerUpdate and some local callbacks being called by timers? OnPlayerUpdate is updating 30 times in 1 second right? So it means that a timer in it has an interval of 33.33ms? which means it's a timer handled callback?

Which also means that OnPlayerUpdate can be killed if you guessed the index? or basically write Killtimer(1); if you removed all other timer integrated callbacks? Just wondering
Reply

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
Just one big question?

Isn't OnPlayerUpdate and some local callbacks being called by timers? OnPlayerUpdate is updating 30 times in 1 second right? So it means that a timer in it has an interval of 33.33ms? which means it's a timer handled callback?

Which also means that OnPlayerUpdate can be killed if you guessed the index? or basically write Killtimer(1); if you removed all other timer integrated callbacks? Just wondering
No i don't think so,
Isn't the average call time of this OnPlayerUpdate is around what the server.cfg was set for onfoot_rate, incar_rate, and weapon_rate? For example if onfoot_rate is set to 500ms, any on foot player actions (such as walking and animation) will trigger this callback around 500ms too.

Those are external calls (between server and client), i don't think it's called with SetTimer().
There is also the pawn default function timer(),delay(),settimer() which is not included in the sa-mp.
Reply

Quote:
Originally Posted by RoboN1X
Посмотреть сообщение
No i don't think so,
Isn't the average call time of this OnPlayerUpdate is around what the server.cfg was set for onfoot_rate, incar_rate, and weapon_rate? For example if onfoot_rate is set to 500ms, any on foot player actions (such as walking and animation) will trigger this callback around 500ms too.

Those are external calls (between server and client), i don't think it's called with SetTimer().
There is also the pawn default function timer(),delay(),settimer() which is not included in the sa-mp.
Is it not calling different callbacks?

Like public OnFootPlayerUpdate?

I think I read someone saying that all those are combined on OnPlayerUpdate() which is called by different functions. That's why it's called 30 times per second...

That's what I wanted to know the timer thing so the OnPlayerUpdate is server created timer and then which means settimer is indexed on a different scale...

Back to the opened topic by @Hansrutger is it possible to kill a timer without it being indexed by the gamemode?

The answer would be a probability am I right. A probability of whether you guessed the timer's index without creating a variable to index it.. Or is it still impossible even threading the needle?
Reply

Thank you guys for response. It seems that I was just ignorant to not know "OnVehicleSpawn" existed for when the vehicle is respawned which was a big miss from me. I guess the problem will be solved from here on.

The core issue was that everytime a CreateVehicle had a respawn time they would make a timer be stuck forever looping on and on and a KillTimer would not solve it even if you went through all vehicle id's and killed their timers.

The idea of setting false on looping and just reapply SetTimer inside the forwarded timer function could work I suppose but that requires the timer's indexes to be reusable and from what I understood from people that wrote above and on previous page is that the indexing works a bit like MySQL's auto increment? If the index just becomes inactive and is reusable then that's really nice. Either way thank you guys for the response!
Reply

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
Just one big question?

Isn't OnPlayerUpdate and some local callbacks being called by timers? OnPlayerUpdate is updating 30 times in 1 second right? So it means that a timer in it has an interval of 33.33ms? which means it's a timer handled callback?

Which also means that OnPlayerUpdate can be killed if you guessed the index? or basically write Killtimer(1); if you removed all other timer integrated callbacks? Just wondering
No, it's not a "timer", default callbacks are based on "triggers" or events as people like to call them, in this case, trigger is, guess what, PlayerUpdate.

It is not possible to kill a timer without knowing it's index, you can kill a timer by guessing it, but you can't be sure it's the timer you want.



Also here's an interesting fact, if you set add one timer every millisecond it'd take about 2 weeks for you to hit the limit (credits to Vince :3)
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)