Saints Row: The Third Referencing open world objects with lua

[V] IdolNinja

Volition Staff
One of the things that has troubled us with Sandbox+ is the ability to reference open world objects in lua to do things with/to. For example, a mission has many objects (npcs, vehicles, etc) predefined so you can reference them by name in lua functions. Not so much in the open world though. The only way we can actually perform actions on, say, a car is to physically get in it and then we can use something like:
Code:
                -- REPAIR CURRENT VEHICLE
                if character_is_in_vehicle(LOCAL_PLAYER) then
                          vehicle_repair( get_char_vehicle_name(LOCAL_PLAYER) )
                end

Is there any way to identify current open world objects in a similar fashion so we can manipulate them? For example, let's say I want to lock on to a specific ped (or even the nearest ped or group) and have them catch fire.
 
Isn't there anything like get_target(Local_Player) ?
Which would, hopefully, react with whatever the player has under their crosshair...
 
Is there any way to identify current open world objects in a similar fashion so we can manipulate them? For example, let's say I want to lock on to a specific ped (or even the nearest ped or group) and have them catch fire.
In general, manipulating non-scripted objects from scripts is not possible. :(

Almost all of the Lua script actions required a scripted object to act on. There are a few script actions that will try to derive the intended object from a named scripted object or player. Many of the vehicle_* functions will accept a player or script NPC in place of a scripted vehicle , and there may be a few other functions that will infer an intended object from another scripted object. I know we are preparing a large dump that will include all the documentation for SR3 Lua script actions , so hang tight for specifics.

Isn't there anything like get_target(Local_Player) ?
Which would, hopefully, react with whatever the player has under their crosshair...
I'm not aware of any such script action in SR2/SR3. The current object targeted by the player is stored in code, but I'm not sure it would do much good to expose to script since almost all of the script actions only work on scripted objects.


While this may all seem counter intuitive, a lot of the reasoning behind only allowing scripting to manipulate scripted object stems from being an open world game. Non-scripted objects are generally treated as optional/disposable by our spawning code, which means there are no guarantees that a vehicle or NPC that exists in the world this frame will still be around on the next frame. As such, making scripts that interact with such objects can lead to unintentional issues and intermittent bugs, and has been generally avoided. If an object is important enough to be scripted, it should be created by script, or handled by a special case.

[EDIT] Fixed incorrect information about getting vehicle from NPC
 
That makes sense. Thanks Matt. Hopefully one day we'll be able to create our own scripted objects on the fly and then perform whatever actions we want on them.
 
Back
Top