Little coding questions - For general minor queries 5

Quote:
Originally Posted by [HLF]Southclaw
View Post
Store structured data, not strings - if you're just using it in the code.

If you want to store the most recent 32 damage events, simply make an array that's 32 cells of your structure and a "pointer" variable that stores a particular cell in that array. Each time a damage event gets logged, you increment that pointer value and when it hits 32 you set it to 0. This is pretty close to a circular-queue or ring-list. You don't need to re-order the data at all because your pointer always marks the end of the list.

PHP Code:
enum E_EVENT {
    
data structure...
}
new
    
ringList[32][E_EVENT],
    
ringPtr,
    
ringTotal;
// insersion
if(ringPtr >= 32)
    
ringPrt 0;
ringList[ringPtr] = event;
ringTotal++;
// access most recent
ringList[ringPtr]
// access least recent
new first 0;
if(
ringTotal >= 32) {
    new 
first ringPtr 1// the next cell is the first because the array wraps around on itself
    
if(first >= 32// and if the cell is off the end, just wrap around to 0
        
first 1;
}
ringList[first
I also had that idea in mind, to show the data in ascending order he would require to run 2 loops (where the pointer is to the end, and from 0 to the pointer [excluding the pointer obviously] - he would just have to check if the data after the pointer is not undefined [first loop]).

I was going to suggest this method (not even kidding), but I initially thought of suggesting something simpler - reordering (not that performance friendly for large arrays) or a large string.

The large string would not require any reformatting, just deleting the first part and inserting a new entry at the end. I'm not sure if strdel and strins' execution time is determined by the total cells of a string like format, but for 32 damage logs, there won't be much of a problem.

What I would advise doing if you'd like to go with the large string method, is bench-marking strdel and strins on small strings and large strings. If their performance isn't strictly tied to the amount of cells rather to what you are inserting, then you'd be fine (though I would not recommend that you use this method if you're going to save the data to a database).
Reply

TOPIC 1
Quote:
Originally Posted by Logic_
View Post
Can somebody tell me why the dynamic 3d text labels are attached to wrong players?
TOPIC 2
Does anybody know why Sublime text doesn't read the new natives from includes?

P.S: The page is 420, Go high and reply...
Reply

Quote:
Originally Posted by Dayrion
View Post
Hooking a callback too long (OnPlayerEditDynamicObject) result that doesn't work because the name is truncated? How can I bypass this problem? Use ALS method? Macro?
PHP Code:
#define OPEDO(%0, %1, %2, %3, %4, %5, %6, %7, %8, %9) OnPlayerEditDynamicObject(%0, %1, %2, %3, %4, %5, %6, %7, %8, %9)
hook OPEDO(playeridobjectidresponseFloat:xFloat:yFloat:zFloat:rxFloat:rYFloat:rZ
Reply

Quote:
Originally Posted by Dayrion
View Post
Hooking a callback too long (OnPlayerEditDynamicObject) result that doesn't work because the name is truncated? How can I bypass this problem? Use ALS method? Macro?
PHP Code:
#define OPEDO(%0, %1, %2, %3, %4, %5, %6, %7, %8, %9) OnPlayerEditDynamicObject(%0, %1, %2, %3, %4, %5, %6, %7, %8, %9)
hook OPEDO(playeridobjectidresponseFloat:xFloat:yFloat:zFloat:rxFloat:rYFloat:rZ
Problem solved.
You had to remplace some letters in your callback. ****** made a table for this:
PHP Code:
static stock
    YSI_g_sReplacements
[][E_HOOK_NAME_REPLACEMENT_DATA] =
        {
            {
"CP",  "Checkpoint"210},
            
// For "SIF".
            
{"Cnt""Container",  39},
            {
"Inv""Inventory",  39},
            {
"Dyn""Dynamic",    37},
            {
"TD",  "TextDraw",   28},
            {
"Upd""Update",     36},
            {
"Obj""Object",     36},
            {
"Cmd""Command",    37}
        }; 
My callback became : OnPlayerEditDynObject
Reply

Hi, have you give me a clue how to calculate amount of bullet's like HUD on GTA?

Thanks.
Reply

The size (on bytes/bits) of a boolean variable is really minor than integers variables?
Reply

Quote:
Originally Posted by Manorango
View Post
The size (on bytes/bits) of a boolean variable is really minor than integers variables?
No, it'll be just as large as a normal integer in the memory.
Reply

if anyone needs help with anything samp related feel free to message me

skype unclemurdathekilla
Reply

I have found in a script this
PHP Code:
for(new i_vehicles_Data; ++i)
    
v[vehicleid][vehicles_Data:i] = 0
What is this "_:"?
I figured out that the code wipe all the data stored in v[vehicleid] enum and _: is something like strlen/sizeof for vehicled_Data enum, but it has a name or other uses? are there any other symbols related to this one?
Reply

_: will "de-tag" an expression. I'm assuming 'vehicles_Data' is an enumerated array, in which case it would be implicitly tagged with the enumerator's symbol. This code is the same as:

PHP Code:
for(new vehicles_Data:ivehicles_Data; ++i
    
v[vehicleid][i] = 0
Tags are just helpers for developers, they don't change anything about the underlying variables (in other words: pawn is untyped, tags are not types)
Reply

What method could you use to check if a player is desynced?
Reply

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
What method could you use to check if a player is desynced?
Probably not entirely accurate but every time I've seen a proper desynced player, their packet loss % returned by this function was above 15%.

https://sampwiki.blast.hk/wiki/NetStats_PacketLossPercent
Reply

How can I format coloured strings?

PHP код:
public OnPlayerText(playerid,text[])
{
    new 
s[144];
    
format(s,144,"{%x}%s{FFFFFF}: %s",u[playerid][pcolor],name[playerid],text);
    
SendClientMessageToAll(-1,s);
    return 
0;

This will show the color instead of coloring the name.
Reply

Quote:
Originally Posted by GaByM
View Post
How can I format coloured strings?

PHP Code:
public OnPlayerText(playerid,text[])
{
    new 
s[144];
    
format(s,144,"{%x}%s{FFFFFF}: %s",u[playerid][pcolor],name[playerid],text);
    
SendClientMessageToAll(-1,s);
    return 
0;

This will show the color instead of coloring the name.
I think you should make it in the {RRGGBB} format


PHP Code:
public OnPlayerText(playerid,text[])
{
    new 
s[144];
    
format(s,144,"{%06X}%s{FFFFFF}: %s",u[playerid][pcolor],name[playerid],text);
    
SendClientMessageToAll(-1,s);
    return 
0;

I don't know if upper/lowercase matters, probably not but if I'm correct then %X (uppercase X) should produce a 000000 to FFFFFF. if your u[playerid][pcolor] variable has alpha like 0x112233AA then you should make that line into:

PHP Code:
    format(s,144,"{%06X}%s{FFFFFF}: %s",u[playerid][pcolor] >> 0xFFFFFF,name[playerid],text); 
Correct me if I'm wrong but I tried this in C before posting haha: http://ideone.com/GeDKb2 (which isn't PAWN but the behaviour shouldn't be that much different for these things).
Reply

hey guys..i don't know if it's the right section but i guess so...
i am trying to code a round system like in counter strike with timer and players spectating untill whole team dies...
can anyone please give me an example of how to start or how it should be done?
thanks in advance!
Reply

Quote:
Originally Posted by MrCesar
Посмотреть сообщение
hey guys..i don't know if it's the right section but i guess so...
i am trying to code a round system like in counter strike with timer and players spectating untill whole team dies...
can anyone please give me an example of how to start or how it should be done?
thanks in advance!
Have a variable that starts at 0.
Make the timer last 2 minutes and everytime the timer finishes make it add 1 to the variable each time. Then, make it check if the variable is at 30, if it's at 30 then make it reset.
Reply

Hi there,

I've been trying to make a range ban command where it automatically removes the last few digits from the IP and ban it, but I've been stuck at how can I remove the last few digits. I've designed a code from what I've got in my brain.

Current code:
PHP код:
    GetPlayerIp(player1ipsizeof(ip));
    
strdel(ipstrlen(ip)-2strlen(ip));
    
format(ip25"%s**"ip);
    
format(ip25"banip %s"ip);
    
SendRconCommand(ip); 
New code design:
PHP код:
    new period;
    
GetPlayerIp(player1ipsizeof ip);
    for(new 
i15i++)
    {
        if(
strfind(ip"."true)) period += 1;
    }
    if(
period >= 3)
    {
        
// ??
    

P.S: I've been away from SA-MP a little bit.
Reply

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Hi there,

I've been trying to make a range ban command where it automatically removes the last few digits from the IP and ban it, but I've been stuck at how can I remove the last few digits. I've designed a code from what I've got in my brain.

Current code:
PHP код:
    GetPlayerIp(player1ipsizeof(ip));
    
strdel(ipstrlen(ip)-2strlen(ip));
    
format(ip25"%s**"ip);
    
format(ip25"banip %s"ip);
    
SendRconCommand(ip); 
New code design:
PHP код:
    new period;
    
GetPlayerIp(player1ipsizeof ip);
    for(new 
i15i++)
    {
        if(
strfind(ip"."true)) period += 1;
    }
    if(
period >= 3)
    {
        
// ??
    

P.S: I've been away from SA-MP a little bit.
PHP код:
       
    GetPlayerIp
(player1ipsizeof ip)    
    new 
len strlen(ip),i,count;
    for(
i=len;count!=2;--i)
    {
        if(
ip[i] == '.') ++count;
    }
    
strdel(ip,++i,len); 
Reply

Small mistake. Didn't mean to post this.
Reply

Quote:
Originally Posted by oSAINTo
Посмотреть сообщение
Have a variable that starts at 0.
Make the timer last 2 minutes and everytime the timer finishes make it add 1 to the variable each time. Then, make it check if the variable is at 30, if it's at 30 then make it reset.
wut?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)