Luis95R Posted October 26, 2016 Share Posted October 26, 2016 Hi, I'm working on a mod that has a structure that spawns a mob in front of a player when they're near it. I don't want to spawn with childspawner or periodic spawner. The only mod I could find that did something similar was the "Haunted House" mod that spawns a Hound near the player when they get close to the haunted house. Sadly that mod is only for singleplayer DS so I can't use the code from it as an example. Here is an example of the code that mode uses and I was wondering what it would be like in DST form. Quote local function onnear(inst) inst.components.childspawner:StartSpawning() inst.components.periodicspawner:Start() local lightning = SpawnPrefab("collapse_small") local hound = SpawnPrefab("hound") local player = GetPlayer() local pos = player:GetPosition() pos.x = pos.x - 4 pos.z = pos.z - 4 hound.Transform:SetPosition(pos:Get()) lightning.Transform:SetPosition(pos:Get()) inst.AnimState:PlayAnimation("near", true) -- inst.Light:Enable(true) --SpawnPrefab("spider_dropper").Transform:SetPosition(inst.Transform:GetWorldPosition(0,10,0)) --SpawnPrefab("ghost").Transform:SetPosition(inst.Transform:GetWorldPosition(0,100,0)) end As you can see GetPlayer() is no longer used in DST, so I'm not sure how to make the structure get the nearest player in DST and spawn a mob next to that player. Any suggestions? Link to comment https://forums.kleientertainment.com/forums/topic/71160-how-to-get-nearby-player/ Share on other sites More sharing options...
alainmcd Posted October 26, 2016 Share Posted October 26, 2016 Use GetClosestInstWithTag(tag, inst, radius). The required arguments are simple enough: the tag you're looking for, the entity around which to look for, and the radius around said entity. For example: local player = GetClosestInstWithTag("player", inst, MyRadius) -- player characters have a "player" tag GetPosition() and Transform:SetPosition(x, y, z) are unchanged from single player as far as I can tell. Link to comment https://forums.kleientertainment.com/forums/topic/71160-how-to-get-nearby-player/#findComment-829645 Share on other sites More sharing options...
Maris Posted October 27, 2016 Share Posted October 27, 2016 (edited) local player = FindClosestPlayer(x, y, z, isalive) where x,y,z are coordinates of point. Also: local player = FindClosestPlayerInRange(x, y, z, range, isalive) local player = FindClosestPlayerToInst(inst, range, isalive) local all_nearby_players = FindPlayersInRange(x, y, z, range, isalive) local check_player_exist = IsAnyPlayerInRange(x, y, z, range, isalive) But notice that DST code is different from DS code! If you look at playerprox.lua, you will find that API is different. So you can use: local function onnear(inst, player) ......... Yes, THE GAME will tell you who is triggered playerprox component. You shouldn't check it by yourself. Just look at playerprox.lua. Here is the part of this file: if self.onnear ~= nil then self.onnear(inst, player) end Edited October 27, 2016 by Maris Link to comment https://forums.kleientertainment.com/forums/topic/71160-how-to-get-nearby-player/#findComment-829835 Share on other sites More sharing options...
Luis95R Posted October 27, 2016 Author Share Posted October 27, 2016 Thank you for responding guys! Link to comment https://forums.kleientertainment.com/forums/topic/71160-how-to-get-nearby-player/#findComment-829956 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