ZylonBane on 21/10/2017 at 15:38
I have to say, once you get the hang of the script service API, Squirrel scripting is addictive. Tasks that I used to puzzle hours over trying accomplish, usually by lashing together existing scripts with NVRelayTrap, can now simply be done directly. Want to fling the player in a specific direction then bring him to a dead stop, flash the screen a certain color, or execute a series of actions at precisely timed intervals? Just code it up!
On the one hand, it's amazingly empowering. On the other hand, it's so empowering it almost feels like cheating. Like going from cursive handwriting to using a word processor. I can feel hard-won skills already starting to atrophy... but I can't turn back.
It's kind of sad there isn't more activity in this thread. I'd assumed DromEd'ers would be all over Squirrel.
Nameless Voice on 30/10/2017 at 01:00
It's like scripting in general, the old ways of flowerpots falling down chutes and hitting banners are gone, along with the spinning emittertraps shooting a stream of arrows at carefully arranged circles of paintings.
Yandros on 30/10/2017 at 12:36
I am planning to deep dive into it now that the 800 lb gorilla is off my back. With my programming background I think it won't be that hard to pick up, just the learning curve.
Yandros on 30/10/2017 at 16:02
Sorry Mr. Pedant, I meant the steepness and length of the curve shouldn't be too bad given my background. :p
LarryG on 30/10/2017 at 17:14
That doesn't seem either naively confident or discouragingly realistic. Just where do you think you are on the curve right now, hmm? :laff:
ZylonBane on 3/12/2017 at 01:38
This is a script for randomizing the positions of objects on level start. Works with both free-standing and contained objects. I'm not aware of any way to "floor" objects using the script services, so it's best to either only shuffle identically sized objects, or start everything in midair and give them physics so they fall into place.
Instead of shuffling a group of objects, you could also use it to randomize the position of a single object by placing markers at every possible location. Or a mix of both. For additional randomization groups you just place another instance of the script on another object, etc.
Use by placing the script on any object and linking to all the objects to be shuffled. This was written for SS2 so it looks for SwitchLink flavor links. For Thief I suppose you'd change it to ControlDevice.
Code:
class scpShuffle extends SqRootScript {
function OnSim() {
local t, m, lnk, obj;
local order = [];
local objRef = [];
local objPos = [];
local objFac = [];
local objDest = [];
local i = 0;
// cache pos/loc/container of every linked object
foreach (lnk in Link.GetAll("SwitchLink", self, 0)) {
order.push(i++);
obj = sLink(lnk).dest;
objRef.push(obj);
objPos.push(Object.Position(obj));
objFac.push(Object.Facing(obj));
objDest.push(sLink(Link.GetOne("~Contains", obj)).dest);
}
// do the Fisher-Yates Shuffle
m = order.len();
while (m) {
i = floor(Data.RandFlt0to1() * m--);
t = order[m];
order[m] = order
;
order = t;
}
// process objects
for (i = 0; i < order.len(); i++) {
t = order;
if (t != i) {
obj = objRef;
Object.Teleport(obj, objPos[t], objFac[t])
lnk = Link.GetOne("~Contains", obj);
if (lnk) {
Link.Destroy(lnk);
}
if (objDest[t]) {
Link.Create("~Contains", obj, objDest[t]);
Property.SetSimple(obj, "HasRefs", FALSE);
}
else {
Property.SetSimple(obj, "HasRefs", TRUE);
}
}
}
}
}Here's a demonstration with the script being triggered by a button instead of sim start.
[video=youtube;wEtsB4XaxiA]https://www.youtube.com/watch?v=wEtsB4XaxiA[/video]
Yandros on 3/12/2017 at 02:30
Nice work, thanks! If I ever get around to making that Clue FM, I could use that to randomize the locations of the suspects and murder weapons.
Yandros on 3/12/2017 at 23:57
Warning:
If you release a mission which utilizes squirrel script, I highly recommend you include squirrel.osm in your ZIP in the root, along with other script modules. The reason is that GoG.com's Thief2 installer puts it into the /doc folder instead for some reason, which doesn't make much sense to me. Some of their users had issues with DCE because of this, and they have asked me to include it in the next update of DCE, so I would recommend you all do the same. I did suggest they modify their installer to put it in the root, or in wherever the script_module_path is pointing to in their darkinst.cfg file, but I don't know if they will do that.
Daraan on 4/12/2017 at 13:39
Quote Posted by ZylonBane
This is a script for randomizing the positions of objects on level start. Works with both free-standing and contained objects. I'm not aware of any way to "floor" objects using the script services, so it's best to either only shuffle identically sized objects, or start everything in midair and give them physics so they fall into place.
Giving them physics seams like the best method, but might not work in every situation.
The idea to flooring and how I assume it's similar done in the native Editor Function is via PortalRaycast(Object.Position(),vector(0,0,-1),returnVec), which gives back the floor position below the object.
Lil' problem is how to get the RedBoundingBox values?
Workarround is would be OBB.Z/2 or Radius or via a OBB dummy with the same model, which really gives back the RedBox size.
But still the question remains: Is there are direct methoe to access the RedBoundingBox values?