In a mod's lua scripts, is it possible to do any of the following?..
1) Get a list of prisoners in a room, or using an object
2) Determine is a prisoner (in the list above) is carrying contraband
3) Determine the type of contraband being carried
Any answers, help or pointers appreciated.
In a mod's lua scripts, is it possible to....
Moderator: NBJeff
-
- level1
- Posts: 14
- Joined: Wed Sep 03, 2014 6:39 pm
- blipadouzi
- level4
- Posts: 567
- Joined: Fri Sep 06, 2013 5:35 pm
- Location: Canada
- Contact:
Re: In a mod's lua scripts, is it possible to....
Here's a list of all the LUA functions you can do at the moment
http://devwiki.introversion.co.uk/pa/index.php/Lua
http://devwiki.introversion.co.uk/pa/index.php/Lua
Re: In a mod's lua scripts, is it possible to....
blipadouzi wrote:Here's a list of all the LUA functions you can do at the moment
http://devwiki.introversion.co.uk/pa/index.php/Lua
Those are the commands for scenarios, I believe this is the list for scripts: (found in main.dat/lua_function_list.txt)
Code: Select all
Function List
____________________________________________
Object.GetProperty( [ObjectName,] PropertyName )
Gets a property on an object's DataRegistry. If no object name is given, it defaults to the current object.
If the property can not be found in the DataRegistry, and no ObjectName is given, then look for the property in the
object's ScriptState blackboard.
ObjectName: Optional. Defaults to the object that the script is running on.
PropertyName: Required. Name of the property to set.
Returns: The value of the property on the named object, or nil
____________________________________________
Object.SetProperty( [ObjectName,] PropertyName, Value )
Sets a property in an object's DataRegistry. If no object name is given, it defaults to the current object.
If the named property can not be found in the DataRegistry, and no ObjectName is given, then set the property in the
object's ScriptState blackboard.
ObjectName: Optional. Defaults to the object that the script is running on.
PropertyName: Required. Name of the property to set.
Value: Required. The value to set to the named property.
Returns: N/A
____________________________________________
Object.Spawn( ObjectTypeName, X, Y )
Spawns an object of type ObjectTypeName at position X,Y
ObjectTypeName: Required. The name of an Object listed in materials.txt.
X: Required. The x-position of the spawned object.
Y: Required. The y-position of the spawned object.
Returns: The identifier name of the object spawned, or nil if no object is spawned.
____________________________________________
Object.Delete( ObjectName )
Deletes a named object
ObjectName: Required. The name of an Object to be deleted.
Returns: N/A
____________________________________________
Object.ApplyVelocity( ObjectName, X, Y [, Rotate] )
Applies an animation velocity to the named WorldObject
ObjectName: Required. The name of an Object.
X: Required. The x-velocity of the object.
Y: Required. The y-velocity of the object.
Rotate: Optional. Should the velocity cause some mild rotation?
Returns: N/A
____________________________________________
Object.GetMaterial( X, Y )
Gets the material name for the cell X,Y
X: Required. The x-location of the cell.
Y: Required. The y-location of the cell.
Returns: The name of the material at cell X,Y.
____________________________________________
Object.GetNearbyObjects( TypeName, SearchDistance )
Gets a table of all entities of type TypeName that are within SearchDistance of the calling object
TypeName: Required. The type of entity to search for.
SearchDistance: Required. The distance from this scripted object to search within.
Returns: A table of object names and their distance to the calling object.
N.B. Both name and distance values will be returned as strings.
____________________________________________
Object.NavigateTo( ObjectName, X, Y )
Navigates ObjectName to the point (X,Y). The object must be an Entity. If no object name is given,
it defaults to the current object.
ObjectName: Optional. Must be an entity. Defaults to the object that the script is running on.
X: Required. The x-location of the cell.
Y: Required. The y-location of the cell.
Returns: N/A
____________________________________________
Object.ClearRouting( ObjectName )
Clears any routing that the object called ObjectName has. The object must be an Entity. If no object
name is given, it defaults to the current object.
ObjectName: Optional. Must be an entity. Defaults to the object that the script is running on.
Returns: N/A
____________________________________________
Game.Time()
Returns the current game time in seconds. Useful for timing events and checks.
Returns: A string of the current game time.
____________________________________________
Game.DebugOut( Message )
Prints a debug message to the script debugger window. Opens the window if it is not yet opened.
N.B. As this functions opens a debug window, you should only use this function for testing purposes
and remove any calls before publishing your mod.
Message: A string to print to the debug window.
Returns: N/A
____________________________________________
-
- level1
- Posts: 14
- Joined: Wed Sep 03, 2014 6:39 pm
Re: In a mod's lua scripts, is it possible to....
Thanks guys. Great information.
I was hoping there may be a Room.GetOccupants(), so you can get a collection of all occupants, iterate through them each of the Occupant and call of Occupant == "Prisoner", then see if the prisoner has contraband, then look for a specific type of contraband.
Or maybe I can do something like... MyRoom.txt
But I'd need to know what properties are available on a "Room" object and a "Prisoner" object. I assume there must be a "Contraband" collection on the prisoner object or the guards could not "find" it when searching them.
Game.DebugOut( Message ) may be useful though. Does this work in the versions we have, or just in the Introversion developer versions?
I was hoping there may be a Room.GetOccupants(), so you can get a collection of all occupants, iterate through them each of the Occupant and call of Occupant == "Prisoner", then see if the prisoner has contraband, then look for a specific type of contraband.
Or maybe I can do something like... MyRoom.txt
Code: Select all
function Update ( timePassed)
-- Get local variable references
local occupants = Object.GetProperty("Occupants")
--- Iterate through all occupants
for i, occupant in ipairs(occupants ) do
-- Check if occupant is a prisoner
if occupant == "Prisoner" then
-- occupant is a prisoner, so now check if the prisoner has any contraband
if occupant.GetProperty("HasContraband") then
-- get a local reference to the prisoners contraband list
local contrabandList = occupant.GetProperty("Contraband")
-- iterate through all contraband the prisoner has looking for contraband of type "X"
for j, contraband in ipairs(contrabandList ) do
if contraband == "X" then
-- Do something amazing
end
end
end
end
end
end
But I'd need to know what properties are available on a "Room" object and a "Prisoner" object. I assume there must be a "Contraband" collection on the prisoner object or the guards could not "find" it when searching them.
Game.DebugOut( Message ) may be useful though. Does this work in the versions we have, or just in the Introversion developer versions?
Re: In a mod's lua scripts, is it possible to....
Isn't this the most up to date collection of object properties we have?
http://devwiki.introversion.co.uk/pa/in ... operties_5
edit: Nvm, there's more than that which can be set with Game.SetFlag for the objects.
Is it possible to check for room uid or even just type at a given position? Then I assume you could use the getNearbyObjects and filter out those not in the room?
http://devwiki.introversion.co.uk/pa/in ... operties_5
edit: Nvm, there's more than that which can be set with Game.SetFlag for the objects.
Is it possible to check for room uid or even just type at a given position? Then I assume you could use the getNearbyObjects and filter out those not in the room?
-
- level1
- Posts: 14
- Joined: Wed Sep 03, 2014 6:39 pm
Re: In a mod's lua scripts, is it possible to....
mazetar wrote:Is it possible to check for room uid or even just type at a given position? Then I assume you could use the getNearbyObjects and filter out those not in the room?
Yes, I guess I could go down that route. Thank you.
Who is online
Users browsing this forum: No registered users and 5 guests