Interior Virtual World -
Mattos - 23.11.2011
Topic in
Portuguease
Hello everybody, today I came up with the idea to "fix" a bug that occurs in the SAMP, because the game was originally designed for single player and not multiplayer, with an Include.
The SAMP has several interiors, and there are several entries in the map that provide access to these interiors.
The problem is that several entries in the map at different locations provide access to the same interior. So if a player enters a Binco store of LS and another player enters a Binco store from LV, for example, they will see eachother inside, which is not realistic.
So the include takes the position coordinates of the player (PosX, and Posy PosZ) and define, through a calculation, a virtual world.
Thus it is as if each entry, with the yellow pickup, led the player to a specific virtual world, thus making the game much more real. This ends the need for excluding these original entries of the game and create new entries with a new pickup.
Example of use
NOTE: The number of the VirtualWorld is defined by "InteriorVW(playerid)"
pawn Код:
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
if (newinteriorid == 0)
{
SetPlayerVirtualWorld(playerid, 0); // Will make the player go back to the 0 VW when the new interior id is 0
}
else
{
SetPlayerVirtualWorld(playerid,InteriorVW(playerid)); // Will set a certain virtual world, based on the player position when he starts entering the interior.
}
}
Many of you may wonder why I do not simply created new entries or set a random virtual world when the player enter the interior. Because the idea is just use the original entries of the game and make the players see eachother inside, if the had entered at the same location.
Testing Functionality
Use the code below to test the functionality of the Include:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]) // Code from SAMP Wiki
{
if(strcmp(cmdtext, "/world", true) == 0)
{
new string[32];
format(string, sizeof(string), "Your virtual world: %d", GetPlayerVirtualWorld(playerid));
SendClientMessage(playerid,0xFFFFFFFF,string);
return 1;
}
return 0;
}
Include Download
Solidfiles
Pastebin
Author
Mateus Costa de Mattos
Credits
rjjj
Gustavo_Araujo
NOTE: Do not remove the credits. Feel free to edit the Include.
Re: Interior Virtual World -
System64 - 24.11.2011
what a fuck?
isn't it faster and better to use DisableInteriorEnterExits?
Re: Interior Virtual World -
Mattos - 24.11.2011
No because then you will have to create new pickups for each entrance in the map... with this code you dont have to create nothing, and disable nothing... Those original yellow pickups become functional, because for each entrace there will be a specific virtual world. This code is for the whole map... think, there might be something like 300 entrances in the whole map, than disable those original pickup and create new pikups that teleportate you for an interior is not faster than that include...
Remember... The idea is to fix the bug of players see eachother inside of an interior when entering in different positions at the map....
Sorry my english...
Re: Interior Virtual World -
System64 - 24.11.2011
oh, my bad
great job than!
Re: Interior Virtual World -
Mattos - 24.11.2011
Quote:
Originally Posted by System64
oh, my bad great job than!
|
Thank you!
Quote:
Originally Posted by ******
The entry point based grouping is a very nice idea, but there are better ways of doing it (kudos for finding a solution though). Because you call "floatround" that entire "restfloat" function and subtraction is pointless (also, I'm not sure what happens when "PosX + PosY + PosZ" is negative):
pawn Код:
stock InteriorVW(playerid) { new Float:PosX, Float:PosY, Float:PosZ; GetPlayerPos(playerid, PosX, PosY, PosZ); return floatround(floatabs(PosX + PosY + PosZ), floatround_round) & 0xFFFF0; }
I used binary operations instead of division and mod because they're far more efficient. You chose 10 and 65999 as you essentially arbitrary numbers, the code above is equivalent to yours with 16 and 65536 instead. I've optimised away A LOT of the code but it SHOULD give about the same result. It would be interesting to see some tests - I can imagine two instances where it won't work:
1) If there's an entry point at -100,-100,-10 and another one at 100,100,10 then they will result in the same interiour VW (your code and mine).
2) If there's an entry point at 105,100,10 and someone clips it at 104.9,100,10, while another person clips it at 105.1,100,10, they will end up in different VWs despite having just been right next to each other.
|
Well xD let me try to explain what my code does...
First it get the player position, and sum PosX to PosY to PosZ... Then the restfloat gets the rest of a division... so for example if the sum of those three floats is 2056.25663, the rest of the division of 2056.25663 and 1 will be: 0.25663... then the next function does 2056.25663 - 0.25663 = 2056.0
Then the next funcition tranform this float into an intenger = 2056
Well i could simply set this intenger as the player VW... But the player could be something like 1 ms diferent as before... than the VW would be 2055 or 2057... And that happened with me when i was testing... Than a thougth: if I get this intenger (2056) and divide for 10 (something like a point ratio) i would get 205.6 (witch cannot be a VW) so i used the operator %65999 witch remove the 0.6... so 205... then I *10 again... and the numer i get is 2050 witch is the VW id... So we got a ratio of 10 ms for the player enter at the same position as before...
And how about if the number is negative... well i did this:
pawn Код:
if (PosSum < 0)
{
PosSumInt = floatround((0-PosSum), floatround_round);
}
for exemple... if the sum is -1963.13620 the number will become 1963.13620
And thats it =D
I dont know how about your code because there is no ratio... so a player could enter in a VW diferent... something like 1 ID of diference...
Re: Interior Virtual World -
wups - 24.11.2011
This is useful, but I don't like the technique. Maybe I want to use virtual worlds else where? You should check the distances of all entrances(there's an include with all of them) and store the virtual worlds in a sequence of numbers.
Ex 1,2,3,...
Also would be nice if you could choose a starting point.
Ex 1000,1001,...
Re: Interior Virtual World -
Mattos - 24.11.2011
****** i understand what you mean... I will change it for the next version... But how about the negative number, think the probability of exists a entrance that led you to the same interior at "1963" is definitly 0% because there is not, i am sure...
Well wups, thats not the idea, to go to every entrance and... The ideia is make it genaral for i dont have to go on every entrace and get theis distance, even if already exist a Include with all added...
Well and how about start at a point... You can do that simply: SetPlayerVirtualWorld(playerid, InteriorVW(playerid) + 1000);
Ah ****** i am not wite sure about what you said about the operator and the division... I will make some tests here...
Thank all you guys...
Re: Interior Virtual World -
Psymetrix - 02.12.2011
I think this would be a better way of doing it.
pawn Код:
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
if (newinteriorid == 0)
{
SetPlayerVirtualWorld(playerid, 0); // Will make the player go back to the 0 VW when the new interior id is 0
}
else
{
SetPlayerVirtualWorld(playerid, (5000 + playerid)); // Will set a certain virtual world, based on the player position when he starts entering the interior.
}
}
Re: Interior Virtual World -
KoczkaHUN - 02.12.2011
@Pysmetrix:
Then player's won't see each other.
Re: Interior Virtual World -
Mattos - 09.12.2011
This is not defenetle better
Cuz... I wanna player see eachother inside an interior... You didnt get the include objetive...