Jump to content

[solved]Checking if a player is in a certain room. ??


quadrinka4

Recommended Posts

Hello, I am trying to make a mod that allows a player to perform an action if the player is in a certain room definition (ex: church, grocery, livingroom, etc). 

 

I've got my idea from Hydrocraft and its' code :

 

if not player:isOutside() then
player:Say("There are no flora indoors.");

 

My question is, is there a method that I can use to check if the player is in a certain room? maybe player:isRoom(grocery)  type of thing?

 

Thanks in advance.

Edited by quadrinka4
Link to comment
Share on other sites

1 hour ago, blindcoder said:

You can do:

 


local room = getPlayer():getCurrentSquare():getRoom();
local roomName = room:getName();

This will get you all the first-level names of the SuburbsDistribution array ("conveniencestore", "burgerkitchen", "grocery", etc).

 

Thank you so much ^^ so if i want to test if my player is in grocery room, putting

if not roomName: ("grocery") then
player:Say("You are in wrong room.");

 

this cause error, I am new to the Lua so i guess i am still on the learning phase by looking at other's codes....

Could someone fix what I did wrong?

Edited by quadrinka4
Link to comment
Share on other sites

22 minutes ago, blindcoder said:

That's not valid in any programming language I know of...

Try this:


 


if roomName =~ "grocery" then
player:Say("You are in the wrong room.");
end

=~ here means "is not equal"

 

So i introduced above code in Hydrocraft and  I still get error.... 

 

 

function HCFloraGather(items, result, player)
local room = getPlayer():getCurrentSquare():getRoom();
local roomName = room:getName();

if roomName =~ "grocery" then
player:Say("There are no flora indoors.");
end

Capture.JPG

 

 

 

Sorry for being such a pain. But I am learning alot form you about LUA right now. Thank you

Edited by quadrinka4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...