Player vs NPC's VW, rep+
#1

Okay, so basically I have no idea how to set the npc's virtual world the same as the player's one.
Код:
public OnPlayerSpawn(playerid)
{
    new worldid = playerid+1;
		if(!IsPlayerNPC(playerid))
		{
                      SetPlayerVirtualWorld(playerid, worldid);

//then
	if(IsPlayerNPC(playerid))
	{
		SetPlayerVirtualWorld(playerid, worldid);
In this case NPC's vw will be its playerid+1, but I need to set it to the spawned player's one.
Any idea?
Reply
#2

By "// then" you mean another callback in the code?
If so save a global variable with that information.
Reply
#3

nah it is still the same callback, but you know the thing is - when I spawn with the ID 4, then my virtual world is supposed to be 5. NPC has the ID 5 for example, then its virtual world will be set at number 6 - but I need it to be the same as player's one. This is so messed up.
Reply
#4

Quote:
Originally Posted by cdoubleoper
Посмотреть сообщение
Okay, so basically I have no idea how to set the npc's virtual world the same as the player's one.
Код:
public OnPlayerSpawn(playerid)
{
    new worldid = playerid+1;
		if(!IsPlayerNPC(playerid))
		{
                      SetPlayerVirtualWorld(playerid, worldid);

//then
	if(IsPlayerNPC(playerid))
	{
		SetPlayerVirtualWorld(playerid, worldid);
In this case NPC's vw will be its playerid+1, but I need to set it to the spawned player's one.
Any idea?
For the first player only ? If yes, something like this ?
PHP код:
public OnPlayerSpawn(playerid)
{
    new 
worldid playerid+1;
        if(!
IsPlayerNPC(playerid))
        {
                      
SetPlayerVirtualWorld(playeridworldid);
//then
    
if(IsPlayerNPC(playerid) && playerid 1)
    {
        
SetPlayerVirtualWorld(playeridworldid); 
Reply
#5

Does the NPC connect & spawn necessarily after each playerm? If so you can just decrease the ID.

Otherwise save a player's VW in a variable and once looking for the playerid of the NPC then put it according to the stored virtual world (in like, pVirtualWorld[MAX_PLAYERS]).
Reply
#6

PHP код:
if(IsPlayerNPC(playerid))

SetPlayerVirtualWorld(playeridplayerid);

Like that? I don't know how you spawn NPCs but I'm assuming when 1 player connects you connect a NPC for them, right?
if not you should make an array keeping a list of which NPC is in which player's world, when a player connects assign one of the NPCs to the player.
Reply
#7

Quote:
Originally Posted by GuyB790
Посмотреть сообщение
Does the NPC connect & spawn necessarily after each playerm? If so you can just decrease the ID.

Otherwise save a player's VW in a variable and once looking for the playerid of the NPC then put it according to the stored virtual world (in like, pVirtualWorld[MAX_PLAYERS]).
Okay. I got 3 NPCs and each has divided worldid (first one -1, the second one -2, third -3).
Seems like it is working with 2 players, but I'm kind of afraid how it is going to react while many players are spawning at the same time.
Reply
#8

Quote:
Originally Posted by cdoubleoper
Посмотреть сообщение
Okay. I got 3 NPCs and each has divided worldid (first one -1, the second one -2, third -3).
Seems like it is working with 2 players, but I'm kind of afraid how it is going to react while many players are spawning at the same time.
If you're planning to have an NPC for each player's virtual world you should read this:
https://sampforum.blast.hk/showthread.php?tid=102196 .
It's about the idea of the same NPC for multiple VWs (tl;dr - it's impossible as far as I understood)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)