Visitors -
RowdyrideR - 19.04.2015
Hello guys...
I have been working on this thing for a long time now but still i can't do it...
What i'm trying to do is to get the last 10 players visited a house, So on i made it but all houses have one list.
So what im asking for is if someone can tell me how to make it each house has its own list.
Code:
Top:
Код:
#define MAX_VISITORS_STORE (10)
new Rstring[128],Visitors[MAX_VISITORS_STORE][128];
When someone visits
Код:
CallLocalFunction("StoreVisitor", "d",playerid);
LastVisitedHouse[playerid] = id;
Saving data
Код:
forward StoreVisitor(playerid);
public StoreVisitor(playerid)
{
new year,month,day,hour,minute,second,RName[MAX_PLAYER_NAME];
GetPlayerName(playerid,RName,MAX_PLAYER_NAME);
getdate(year,month,day);
gettime(hour,minute,second);
for(new i = 0; i < MAX_VISITORS_STORE-1; i++)
Visitors[i] = Visitors[i+1];
format(Rstring,sizeof(Rstring),"- [%d/%d/%d] [%d:%d] %s",day,month,year,hour,minute,RName);
Visitors[MAX_VISITORS_STORE-1] = Rstring;
}
When i show the visitors
Код:
new count;
if(listitem == 0)
{
for(new i = 0; i < MAX_VISITORS_STORE; i++;)
{
if(strlen(Visitors[i]) > 0)
{
SendClientMessage(playerid,-1,Visitors[i]);
count++;
}
}
if(count == 0)
SendClientMessage(playerid,green,"No one have visited you!");
}
Thanks...
Re: Visitors -
Fel486 - 19.04.2015
PHP код:
forward StoreVisitor(playerid);
public StoreVisitor(playerid)
{
new year,month,day,hour,minute,second,RName[MAX_PLAYER_NAME];
GetPlayerName(playerid,RName,MAX_PLAYER_NAME);
getdate(year,month,day);
gettime(hour,minute,second);
format(Rstring,sizeof(Rstring),"- [%d/%d/%d] [%d:%d] %s",day,month,year,hour,minute,RName);
for(new a = MAX_VISITORS_STORE-1; a > 0; a--)
{
Visitors[a] = Visitors[a-1];
}
Visitors[0] = Rstring;
}
Re: Visitors -
RowdyrideR - 19.04.2015
Thanks man, but can you explain what you did?
Re: Visitors -
mamorunl - 19.04.2015
Basically, he inverted the loop. If you copy your stuff over with an incrementing loop you get this:
Код:
i[0] = 1;
i[1] = 5;
i[2] = 3;
i[1] = i[0]; // i[1] = 1;
i[2] = i[1]; // i[2] = 1;
... this keeps going ...
Doing it the other way around overwrites the current value with the previous one and clears the first one to put your own id in.
Re: Visitors -
Fel486 - 19.04.2015
It's like a Stack.
Basically you just remove the last element of the Stack, it's top.
Example with 5 numbers:
pawn Код:
1, 2, 3, 4, 5 // Last Element is 5, he's on the top
On the process, it starts from capacity - 1, because it starts on 0 and goes until 4.
and now:
pawn Код:
Element[4] = Element[3] // a = 4
Element[3] = Element[2] // a = 3
Element[2] = Element[1] // a = 2
Element[1] = Element[0] // a = 1
// ... So now, Element[0] is free for adding a new Visitor, the last one that visited the house
Re: Visitors -
RowdyrideR - 19.04.2015
Thanks alot guys, that's really helpful.