How to check if player is wearing an object possibly by attribute or flag?
TheVulture
10 Nov 2023, 11:04I'm trying to make a function to see if the player is wearing some kind of restraints. Like, if they're in handcuffs, it would be IsWristsRestrained = true.
I'd like to have the function checking what the player is wearing to see if any worn object has the attribute, in this example, wristrestraint = true or similar (easy to make one of the default attributes for wearables a boolean like that). Or, if I must, set up a script to assign the same flag to objects on game start, though that's a little more annoying.
But I can't seem to figure out how to have the game check worn objects for that attribute/flag. The closest I can get is checking every carried object, but that makes things difficult if they're just carrying a pair of handcuffs and aren't actually restrained. Any ideas how I can set this up?
mrangel
10 Nov 2023, 13:18I think there might be built-in functions I've forgotten about that could help you; but if not, I'd create a function something like this.
Function name: CheckWornAttribute
Parameters: attr
Type: Boolean
Script:
foreach (obj, GetAllChildObjects (game.pov)) {
if (GetBoolean (obj, attr) and GetBoolean (obj, "worn") and GetBoolean (obj, "visible")) {
return (true)
}
}
return (false)
Then you could do something like:
if (CheckWornAttribute ("wristrestraint")) {
// Do whatever it is
}
Ip Man
10 Nov 2023, 20:53This is beautiful Mr. Angel. Can this be modified to check the integer values of that found attribute and return the total of them?
Say if each object had a magicbonus, is there a modification that can not only find the magicbonus attribute, but tally up the sum of all the values? +1, +2, -1 ?
mrangel
11 Nov 2023, 22:20This is beautiful Mr. Angel. Can this be modified to check the integer values of that found attribute and return the total of them?
Off the top of my head…
<function name="SumAttributeOfWornObjects" parameters="attr" type="int32">
total = 0;
foreach (obj, GetAllChildObjects (game.pov)) {
if (HasInt (obj, attr) and GetBoolean (obj, "worn") and GetBoolean (obj, "visible")) {
total = total + GetInt (obj, attr)
}
}
return (total)
</function>
TheVulture
13 Nov 2023, 05:16Mr Angel, your function worked perfectly. I can't thank you enough for your help, this will streamline so much of the process!