Birdskull Posted February 25, 2019 Share Posted February 25, 2019 (edited) I'm at a complete loss for how to achieve this one. Without tying the trait to an item, I want the character I'm currently working on to teleport randomly once their sanity drops super low. I've been futzing around with the telelocator staff's code, but I don't know how to apply the action directly onto a character... Is this even possible, and if it is does anyone know what the best way to go about this might be? Thanks in advance. Edited April 27, 2019 by Birdskull Link to comment Share on other sites More sharing options...
Ultroman Posted February 25, 2019 Share Posted February 25, 2019 (edited) Take a look at the mod RPG Items (not my version). It has an armor proc which teleports the player randomly within a certain radius, if that's what you want. I think he even checks if the placement is valid (not in the sea or blocked or something like that). For reacting to when the sanity drops low, listen for the "sanitydelta" event on the player, and react when it goes below a certain percentage or flat number, by starting a periodic task which teleports the player randomly. When the "sanitydelta" event reports that the sanity is above the threshold again, you stop the task. Here's how you can work with periodic tasks: local function DoTeleportation(inst) -- Teleportation code end local function StartTeleporting(inst) if inst.TeleportTask then return end -- Call the given function, DoTeleportation, every 8 seconds. -- The 0 indicates the initial delay, and in this case you'd probably want it to do -- a teleportation immediately, and so we give it an initial delay of 0. inst.TeleportTask = inst:DoPeriodicTask(8, function(inst) DoTeleportation(inst) end, 0) end local function StopTeleporting(inst) if inst.TeleportTask then inst.TeleportTask:Cancel() inst.TeleportTask = nil end end Edited February 25, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Birdskull Posted February 25, 2019 Author Share Posted February 25, 2019 omg that's exactly what I needed! Thank you so much!! Link to comment Share on other sites More sharing options...
Ultroman Posted February 25, 2019 Share Posted February 25, 2019 (edited) You're very welcome! I made a change, adding a 0 for the initialDelay parameter to make it call DoTeleportation() immediately, but I forgot to remove the manual call I had to DoTeleportation() before I did that. This means that the code called DoTeleportation() twice the first time. I edited the code in the snippet in my last post to fix this. Take a look. Also, Quote My only coding strength is tenacity. That's all you really need. Then everything else will follow Edited February 25, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Birdskull Posted February 25, 2019 Author Share Posted February 25, 2019 Oops, I didn't even catch that. Fixed! Thanks again~ 31 minutes ago, Ultroman said: That's all you really need. Then everything else will follow Hoping so! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now