Aller au contenu

Photo

Questions about CreateInstancedAreaFromSource


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
RPGBL777

RPGBL777
  • Members
  • 13 messages
Hi guys,

I've played around with createareainstancefromsource, while it does create area instances, I still cant make it worked according to what I need. So my first question is : are all the objects inside the area are also instanced ?

Here is what I want to do : When player 1 enter the game, go to area1. When player 2 enter the game when player 1 is inside the game, go to instance of area 1. By doing so I want player 1 and player 2 wont meet each other.

So I've got the area instanced but cant allocate the player to the area I want. Here is my code (I put it in onPCLoad) :

void main(){
    string room1status;
    string room2status;
    object oPC;
    string sAreaname;
    int i;
    int iNumberPlayers=0;
    
    room1status=GetGlobalString("groom1status");
    room2status=GetGlobalString("groom2status");
    iNumberPlayers=GetGlobalInt("giNumberPlayers");
    object areaid=GetObjectByTag("NW_WAYPOINTspooks",0);
    string getareatagfirst=GetTag(areaid);
    oPC=GetFirstPC();    

    if(room1status=="nobody"||room1status=="") {
//if there is nobody just use the first NW_WAYPOINTspooks
        SetGlobalString("groom1status","somebody");    
    } else {
//when there is somebody, create instance of the area and then access the NW_WAYPOINTspooks in the instanced area
        object areaid=GetObjectByTag("Area2",0);
        string getareatagfirst=GetTag(areaid);
        CreateInstancedAreaFromSource(areaid);    
        areaid=GetObjectByTag("NW_WAYPOINTspooks",1);
        getareatagfirst=GetTag(areaid);
        SetGlobalString("groom2status","somebody");    
    }
    
      location lLoc = GetLocation(areaid);
    AssignCommand ( oPC, JumpToLocation (lLoc));
}

Any help please? I need to run a simultanuous single player game (single player games that run under one server so basically each player can NOT see each other) and this createinstancearea is probably the last solution to do so because other ways I've tried all of them require impossible hardware resources. :?

Modifié par RPGBL777, 09 novembre 2010 - 08:46 .


#2
Olblach

Olblach
  • Members
  • 175 messages
OK I guess I rather give you the code than try to explain:

The trick is to use object variable on Area and PC.



void SendPC(object oPC, object oDest, int party)
{
	if (party)
	{
		JumpPartyToArea(oPC, oDest) ;
	}
	else
	{
		AssignCommand(oPC, JumpToObject(oDest)) ;	
	}
}

void SendPartyToInstanceOf(object oPC, string wptag, int party=FALSE)
{
	object oTag = GetWaypointByTag(wptag) ;
	object oArea = GetArea(oTag) ;
	
	object oMemo = GetLocalObject(oPC, wptag + "_instance") ; 
	if (GetIsObjectValid(oMemo))
	{
		SendPC(oPC, oMemo, party) ;
		return ;
	}
	if (GetLocalObject(oArea, "AREA_ORIG") == OBJECT_INVALID)
	{
		SetLocalObject(oArea, "AREA_ORIG", oArea) ;
	}
	else
	{
		oArea = GetLocalObject(oArea, "AREA_ORIG") ;
	}
	// oArea is the original area
	object oNewArea = CreateInstancedAreaFromSource(oArea) ;
	if (GetIsObjectValid(oNewArea))
	{
		SetLocalObject(oNewArea, "AREA_ORIG", oArea) ;
	}
	else
	{
		PrintString("oNewArea:" + wptag +" is invalid!") ;
	}
	int count = 0 ;
	int found = FALSE ;
	object oNew = GetObjectByTag(wptag, count) ;
	while (!found && GetIsObjectValid(oNew))
	{
		if (GetArea(oNew) == oNewArea)
		{
			found = TRUE ;
		}
		else
		{
			count++ ;
			oNew = GetObjectByTag(wptag, count) ;
		}
	}
	if (found)
	{
		SetLocalObject(oPC, wptag + "_instance", oNew) ;
		SendPC(oPC, oNew, party) ;
	}
}


#3
RPGBL777

RPGBL777
  • Members
  • 13 messages
Thanks...I had a look at it and I will try it later. Btw during my testing of this CreateInstancedAreaFromSource I found the player still can see each other although they are "sent" to instances of the original area (unless of course if I make a huge mistake in my codes)