Player Exclusive Regions?
Moderator: Moderators
- General_Nate
- Lieutenant General

- Posts: 689
- Joined: Sun Jun 28, 2009 4:01 pm
- Projects :: None because BFII is not working
- xbox live or psn: No gamertag set
- Location: 127.0.0.1
Re: Player Exclusive Regions?
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?
Oh and I put it in Post load, should it be somewhere else?
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: Player Exclusive Regions?
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?
My go at it:
'Course, I haven't tried it out. I don't really feel like making a Genaral Nate account just to test it. 
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?
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
)- General_Nate
- Lieutenant General

- Posts: 689
- Joined: Sun Jun 28, 2009 4:01 pm
- Projects :: None because BFII is not working
- xbox live or psn: No gamertag set
- Location: 127.0.0.1
Re: Player Exclusive Regions?
^Ok, I took the above code and added this:
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...
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...
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: Player Exclusive Regions?
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?
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?
- General_Nate
- Lieutenant General

- Posts: 689
- Joined: Sun Jun 28, 2009 4:01 pm
- Projects :: None because BFII is not working
- xbox live or psn: No gamertag set
- Location: 127.0.0.1
Re: Player Exclusive Regions?
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:
Weeeeee!
Ok, and here is what's in my log:
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?
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"
)
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>
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.
- xbox live or psn: No gamertag set
- Location: QLD, Australia
- Contact:
Re: Player Exclusive Regions?
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!
mwahahahahahahaha :maulsaber:
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Player Exclusive Regions?
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:The host lobby stayed up because the lua code died due to the error and thus couldn't close it.
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-
vaknor
- Recruit Womprat Killer
- Posts: 6
- Joined: Thu Jan 07, 2010 4:02 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: QLD, Australia
- Contact:
Re: Player Exclusive Regions?
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.
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: Player Exclusive Regions?
I'm pretty sure the DMI people wouldn't want any unauthorized murder.
- General_Nate
- Lieutenant General

- Posts: 689
- Joined: Sun Jun 28, 2009 4:01 pm
- Projects :: None because BFII is not working
- xbox live or psn: No gamertag set
- Location: 127.0.0.1
Re: Player Exclusive Regions?
K, so here is everything I don't understand:
Thank you Zerted for posting! I hope I can get my lot out before Rep releases it.[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?![]()
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:The host lobby stayed up because the lua code died due to the error and thus couldn't close it.Code: Select all
local unit = GetCharacterUnit(players[i].indexstr) if unit then MoveEntityToNode(unit,"gn_node3") end
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Player Exclusive Regions?
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
Change for i=1,g_ntable.getn(players) do to for i=1,table.getn(players) do
Yes.So I have to put this code to teleport the character: "MoveEntityToNode(players.indexstr,"gn_node3")"?
- General_Nate
- Lieutenant General

- Posts: 689
- Joined: Sun Jun 28, 2009 4:01 pm
- Projects :: None because BFII is not working
- xbox live or psn: No gamertag set
- Location: 127.0.0.1
Re: Player Exclusive Regions?
Alright!
So here is my new revised code:
And the Error log that came with it:
It makes it to 2, so I don't think it likes that For loop.
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"
)I just walk through the region without anything happening.Error Log wrote:You made it to 1
You made it to 2
It makes it to 2, so I don't think it likes that For loop.
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Player Exclusive Regions?
Change your prints to ShowMessageText and test it in MP.
- General_Nate
- Lieutenant General

- Posts: 689
- Joined: Sun Jun 28, 2009 4:01 pm
- Projects :: None because BFII is not working
- xbox live or psn: No gamertag set
- Location: 127.0.0.1
Re: Player Exclusive Regions?
YES!![RDH]Zerted wrote:Change your prints to ShowMessageText and test it in MP.
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...
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!
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: Player Exclusive Regions?
Heh. What's the point of it in SP?General_Nate wrote:It works! But only in MP.
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Player Exclusive Regions?
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.
