Player Exclusive Regions?

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

User avatar
General_Nate
Lieutenant General
Lieutenant General
Posts: 689
Joined: Sun Jun 28, 2009 4:01 pm
Projects :: None because BFII is not working
Games I'm Playing :: Minecraft
xbox live or psn: No gamertag set
Location: 127.0.0.1

Re: Player Exclusive Regions?

Post by General_Nate »

Hm, I added that Table above, and it still pops up with the Host Lobby, and it teleports me even if my name is "Genaral Nate".

Oh and I put it in Post load, should it be somewhere else?
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Player Exclusive Regions?

Post by Fiodis »

No need, I think, to add the table to the LUA script - that's what the function's supposed to do. Also, the docs say that the function jumps into the player list (host lobby) to get the name info, so that's gonna happen.

Yeah, ScriptPostLoad is fine.

Now, for all my snobbish behavior in this thread, I haven't actually worked with this function too much myself, so let's see me take some of my own medicine, eh? :wink:

My go at it:

Code: Select all

ActivateRegion("g_n_only")
OnEnterRegion(
	function(regIn, character)
	if uf_processPlayers then
	if not players then return end
		local i
		for i=1,table.getn(players) do
			if players[i].namestr ~= "Genaral Nate" then
			print("OnEnterRegion():",name)
			MoveEntityToNode(character,"gn_node3")
			end
		end
	end
	end
	)
'Course, I haven't tried it out. I don't really feel like making a Genaral Nate account just to test it. :P
User avatar
General_Nate
Lieutenant General
Lieutenant General
Posts: 689
Joined: Sun Jun 28, 2009 4:01 pm
Projects :: None because BFII is not working
Games I'm Playing :: Minecraft
xbox live or psn: No gamertag set
Location: 127.0.0.1

Re: Player Exclusive Regions?

Post by General_Nate »

^Ok, I took the above code and added this:
ActivateRegion("g_n_only")
OnEnterRegion(
function(regIn, character)
if uf_processPlayers then
if not players then return end
local i
for i=1,table.getn(players) do
if players.namestr ~= "Genaral Nate" then
print("OnEnterRegion():",name)
MoveEntityToNode(character,"gn_node3")
end
end
end
end,
"g_n_only"

)


To it.

Without it, everything in post load doesn't work. With the above line I added, the other code works, but if someone other than "Genaral Nate" walks into it, they don't teleport.

I think we are getting closer...
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Player Exclusive Regions?

Post by Fiodis »

Right, you know MP Admin commands? When you want to boot someone, you type in /admin /boot #. The # is their number in the player list, also called their character index. uf_processPlayers() grabs character indeces and the names attached to them.

Now, here's what I think. The line i=1 specifies the first character index. If this name is not equal to "Genaral Nate" then it teleports them. But it doesn't do anything with the other indeces. When you, Genaral Nate, are the host, then you're always number 1. The function always sees that your name matches "Genaral Nate" and doesn't teleport you. Maybe if you did something along the lines of i>=1 (i greater than or equal to one), it might work, or some variation thereof. I'm not too sure how that works, though.

One way to test this without changing the code would be to have someone else host it online (hence, they would be number one, and the code would check them) and see if they get teleported.

Also, it can't hurt to toss various Print lines in there, just for debugging.

Do you have an XFire?
User avatar
General_Nate
Lieutenant General
Lieutenant General
Posts: 689
Joined: Sun Jun 28, 2009 4:01 pm
Projects :: None because BFII is not working
Games I'm Playing :: Minecraft
xbox live or psn: No gamertag set
Location: 127.0.0.1

Re: Player Exclusive Regions?

Post by General_Nate »

Hm, ok, that makes since.

And no I don't have an X-fire.

Should we get on MP?

EDIT:
Um, guys, I really need help. Does anyone know what code to use?

EDIT2:
Ok, after MUCH trial and error, I got it down to this:

Code: Select all

g_ntable = {
		{ indexstr = "1", namestr = "Alpha"},
		{ indexstr = "3", namestr = "Bravo"},
		{ indexstr = "2", namestr = "Player 1"},
		{ indexstr = "4", namestr = "LastJoinedPlayer"},
	}


local hideoutteleport = function( players )
	--can't do anything if the player data table is missing
	if not players then return end
	print("You made it to 2")

	--for each player ingame,
	local i
	for i=1,g_ntable.getn(players) do
		print("You made it to 3")
		if players[i].namestr == "Genaral Nate" then
			 print("You made it to 4! YAY!")
        		 MoveEntityToNode(character,"gn_node3")
		end
	end
end

ActivateRegion("g_n_only")
OnEnterRegion(
   function(regIn, character)
	uf_processPlayers(hideoutteleport)
	print("You made it to 1")
   end,
"g_n_only"
)
Weeeeee!

Ok, and here is what's in my log:

Code: Select all

You made it to 1
You made it to 2

Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to call field `getn' (a nil value)
stack traceback:
	(none): in function `__TempProcessPlayersFunction__'
	(none): in function <(none):716>
What I want now is, if the person is not Genaral Nate, leave him be, but if it is, teleport him to a secret location.

It should be said that if I'm Genaral Nate, I don't teleport, but the Host lobby pops up and stays up.

Hmmm, ok, now I'm so close I can TASTE IT.

Does anyone know how to fix this?
vaknor
Recruit Womprat Killer
Posts: 6
Joined: Thu Jan 07, 2010 4:02 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: QLD, Australia
Contact:

Re: Player Exclusive Regions?

Post by vaknor »

what you need is some way of testing whether it found your name, and if it did than you simply add, if id=genaral nate then activate portal secrethangarportal, i havent got a clue about the functions cos ive never used lua but yeah, something approximate to that, you just have to make it find your id amongst the list of other people. Good luck! :funny2: mwahahahahahahaha :maulsaber:
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Player Exclusive Regions?

Post by [RDH]Zerted »

Sorry, I've been meaning to post in this thread....

You don't need g_ntable. The exampleTable table is just an example of the data that uf_processPlayers() gives you. (It actually gives you much more info than that, but I didn't notice the extra info when I first wrote the tutorial.) To get the size of a table you do: table.getn( <your table variable name here> ). You had g_ntable.getn which caused the nil error since your g_ntable didn't have a getn field. Change that code bit to: table.getn(players)

The next error you get will be MoveEntityToNode failing because character is nil. At the moment, I don't remember if you can teleport characters or if you have to teleport their unit (I think its this one).

To teleport the character change your character to players.indexstr in the hideoutteleport function.
To teleport the unit do:

Code: Select all

local unit = GetCharacterUnit(players[i].indexstr)
if unit then
    MoveEntityToNode(unit,"gn_node3")
end
The host lobby stayed up because the lua code died due to the error and thus couldn't close it.
vaknor
Recruit Womprat Killer
Posts: 6
Joined: Thu Jan 07, 2010 4:02 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: QLD, Australia
Contact:

Re: Player Exclusive Regions?

Post by vaknor »

I had awesome idea, if it is you it teleports you to the hangar, if it isnt it teleports them into the air on the other side of the city, where they fall and die.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Player Exclusive Regions?

Post by Fiodis »

I'm pretty sure the DMI people wouldn't want any unauthorized murder.
User avatar
General_Nate
Lieutenant General
Lieutenant General
Posts: 689
Joined: Sun Jun 28, 2009 4:01 pm
Projects :: None because BFII is not working
Games I'm Playing :: Minecraft
xbox live or psn: No gamertag set
Location: 127.0.0.1

Re: Player Exclusive Regions?

Post by General_Nate »

:bowdown: :bowdown: :bowdown: Yes! This thread isn't dead after all!

K, so here is everything I don't understand:
[RDH]Zerted wrote:Sorry, I've been meaning to post in this thread....

You don't need g_ntable. The exampleTable table is just an example of the data that uf_processPlayers() gives you. (It actually gives you much more info than that, but I didn't notice the extra info when I first wrote the tutorial.) To get the size of a table you do: table.getn( <your table variable name here> ).<-- Wait, where do I put that? And why does the size of the table help me? You had g_ntable.getn which caused the nil error since your g_ntable didn't have a getn field. Change that code bit to: table.getn(players)Um, I'm not getting something here. What code bit? :oops:

The next error you get will be MoveEntityToNode failing because character is nil. At the moment, I don't remember if you can teleport characters or if you have to teleport their unit (I think its this one).

To teleport the character change your character to players.indexstr in the hideoutteleport function.<-- So I have to put this code to teleport the character: "MoveEntityToNode(players.indexstr,"gn_node3")"?
To teleport the unit do:

Code: Select all

local unit = GetCharacterUnit(players[i].indexstr)
if unit then
    MoveEntityToNode(unit,"gn_node3")
end
The host lobby stayed up because the lua code died due to the error and thus couldn't close it.
Thank you Zerted for posting! I hope I can get my lot out before Rep releases it.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Player Exclusive Regions?

Post by [RDH]Zerted »

The size of the table helps you because you have to loop through all the players to check their names. You have to know how many players there are in-order to do that.

Change for i=1,g_ntable.getn(players) do to for i=1,table.getn(players) do
So I have to put this code to teleport the character: "MoveEntityToNode(players.indexstr,"gn_node3")"?
Yes.
User avatar
General_Nate
Lieutenant General
Lieutenant General
Posts: 689
Joined: Sun Jun 28, 2009 4:01 pm
Projects :: None because BFII is not working
Games I'm Playing :: Minecraft
xbox live or psn: No gamertag set
Location: 127.0.0.1

Re: Player Exclusive Regions?

Post by General_Nate »

Alright!

So here is my new revised code:

Code: Select all

local hideoutteleport = function( players )
   --can't do anything if the player data table is missing
   if not players then return end
   print("You made it to 2")

   --for each player ingame,
   local i
   for i=1,table.getn(players) do
      print("You made it to 3")
      if players[i].namestr == "Genaral Nate" then
          print("You made it to 4! YAY!")
               MoveEntityToNode(players[i].indexstr,"gn_node3")
      end
   end
end

ActivateRegion("g_n_only")
OnEnterRegion(
   function(regIn, character)
   uf_processPlayers(hideoutteleport)
   print("You made it to 1")
   end,
"g_n_only"
)
And the Error log that came with it:
Error Log wrote:You made it to 1
You made it to 2
I just walk through the region without anything happening.

It makes it to 2, so I don't think it likes that For loop.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Player Exclusive Regions?

Post by [RDH]Zerted »

Change your prints to ShowMessageText and test it in MP.
User avatar
General_Nate
Lieutenant General
Lieutenant General
Posts: 689
Joined: Sun Jun 28, 2009 4:01 pm
Projects :: None because BFII is not working
Games I'm Playing :: Minecraft
xbox live or psn: No gamertag set
Location: 127.0.0.1

Re: Player Exclusive Regions?

Post by General_Nate »

[RDH]Zerted wrote:Change your prints to ShowMessageText and test it in MP.
YES!!

It works! But only in MP. Wow, if only I knew it only worked in MP before, I could have given my lot to Rep by now... :cry:

But who cares? It works now, and I'm very happy! I can move on to something else!

Thank you to all who contributed to this problem, namely Zerted, and Fiodis, you guys ROCK.

After more than 2 months, I can officially dub this thread: <Solved>!

Cheers! :D
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Player Exclusive Regions?

Post by Fiodis »

General_Nate wrote:It works! But only in MP.
Heh. What's the point of it in SP? :wink:
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Player Exclusive Regions?

Post by [RDH]Zerted »

You can get it working in SP too if you want. Just check to see if in SP and if so, directly use the correct ScriptCB function to get the player's name.
Post Reply