Visitors
#1

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

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 
MAX_VISITORS_STORE-10a--)
     {
         
Visitors[a] = Visitors[a-1];
     }

     
Visitors[0] = Rstring;

Reply
#3

Thanks man, but can you explain what you did?
Reply
#4

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

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.

pawn Код:
a = 4,  while a > 0;
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
Reply
#6

Thanks alot guys, that's really helpful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)