SAMP virtual world adding 1 by 1
#1

Hey, see like 1 player registers he spawns at virtual world 1.. next time anytime he logs in he must spawn there only. For the next player when registers he must be spawned in virtual world 2. and it must be saved in the logs ( Scriptfiles ). I am using YSI system for saving. Can you give me a idea of how to do it?
Reply
#2

-------Remove it lel----
Reply
#3

I am asking for an example lol.. I don't know how to do it.
Reply
#4

Just save the location of the player into the .ini files system. You will need to add another var in the player's array to hold the value of its position. Once they disconnect, write the ini file with the current position and other stats.
Reply
#5

Dude i know the point you said, but how can i set the players virtual world? Like mine is 1. The next player registers must have the virtual world 2. The next player must have virtual world 3. so on.
Reply
#6

Код:
for(new i = 1; i < 2,147,483,647; i++)
{
      if(!VirtualWorldTaken[i])
      {
	  VirtualWorldTaken[i] = 1;
          SetPlayerVirutalWorld(playerid, i);
^ That would be an example to check if the VW is taken or not, if it is - then it will check the next and set it for the player.

You can make your code around that.
Reply
#7

I understand what you are saying but (VirtualWorldTaken) is a function that is not globalized and i dont think that VirtualWorldTaken is any function.
Reply
#8

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
I understand what you are saying but (VirtualWorldTaken) is a function that is not globalized and i dont think that VirtualWorldTaken is any function.
Yea so you'll have to create it yourself.

Код:
new VirtualWorldTaken[MAX_VIRTUALWORLDS];
Top of the script -

Код:
#define MAX_VIRTUALWORLDS [amount]
I am not gonna write the whole code, its pretty simple. You should get the idea by now.

You'll loop through MAX_VIRTUALWORLDS instead of the limit above.

That was just an example by the way, it's not a variable until you create it.
Reply
#9

Ok i got it if i have any other query i will let you know. Thanks.
Reply
#10

I don't know where you're heading with this (it seems pretty pointless to isolate players in a multiplayer game), but remember that 'playerid' is also a unique property. If you set a player's virtual world to 'playerid' then no other player can connect to that world until the current player disconnects and another player assumes the playerid.
Reply
#11

There is no point in having an array with size 2 billion just to see which virtual world is taken.
An array of that size will occupy 8GB of RAM for this alone (2 billion indices in the array, each 4 bytes long as each index can hold a 32-bit integer value).
Also your amx-file will be that size.
Pretty overkill if you ask me.
I wonder how you're gonna save that array so it's contents are identical after a server-restart.
You would end up with a file of several GB's in size as well, just to hold a 1 or a 0 in each index of that array.

And looping through that array to find the next unused virtual world is also not needed.


If it always goes up by 1 everytime a player registers, just have one variable hold the highest used virtual world and save that in a file.

Next time a player registers, increase the variable by 1, use that value as virtual world for that player (also save it in his account-file) and save your highest-virtual-world-file again with this new value.
Also no need for a big loop that would run through 100000 indices to find the next unused virtual world (in case you have 100000 registered players).

Also load this file when your server starts, so it doesn't always start from 0 again and you're set.

Note that all players won't see eachother and can't interact with eachother, except for using chat.
They can't shoot eachother, drive together, ...
I don't see any use for this, except for when you're trying to re-create single-player in a multiplayer environment.
Reply
#12

You will know it soon. Anyway I have that much sense I used only 2k.. And better give an example through codes? Its better you know. Thank you.
Reply
#13

Vince I dont want that I want like if its taken by x player then it must belong to him forever. That virtual world must not be taken by anyone else.
Reply
#14

So, may i continue with what codes where said in this topic or are they wrong? If they are wrong then can someone show me correct example?
Reply
#15

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
So, may i continue with what codes where said in this topic or are they wrong? If they are wrong then can someone show me correct example?
It's not wrong but its less efficient, only use about 1000 or 2000 virtual worlds within your MAX if you'll go with my way. The way Amiga told you to do it is alot more efficient and memory saving tho.
Reply
#16

Yup it worked. Even i want to ask a last little doubt. If i create an OBJECT to only 1 player. How can i save it and load it on the next login only for him as he creates the object to himself.
Reply
#17

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Yup it worked. Even i want to ask a last little doubt. If i create an OBJECT to only 1 player. How can i save it and load it on the next login only for him as he creates the object to himself.
Get the player's virtual world and set that object's virtual world to the same one.
Reply
#18

Dude there's an error. The saving starts from virtual world 1999 and then next 2000 and then again 1999. Why so? the lines i added were.
#define MAX_VIRTUALWORLDS 2001
new VirtualWorldTaken[MAX_VIRTUALWORLDS];

Код:
        for(new i = 1; i < MAX_VIRTUALWORLDS; i++)
			{
      			if(!VirtualWorldTaken[i])
	      		{
		  			VirtualWorldTaken[i] = 1;
	          		SetPlayerVirtualWorld(playerid, i);
					pInfo[playerid][pVirtualWorld] = i;
				}
			}
INI_WriteInt(File,"VirtualWorld",pInfo[playerid][pVirtualWorld]);
//On PlayerLogin
SetPlayerVirtualWorld(playerid,pInfo[playerid][pVirtualWorld]);
Reply
#19

BUMB i repeat the problem. The saving of virtual world starts from 1999, and continues to 2000. and then always 2000. Anyone can fixit?
Reply
#20

BUMP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)