Lingerdinger Posted March 6, 2015 Share Posted March 6, 2015 Hello!I'm still learning how to code and I wanted to make a few custom items.I was in the process of making a book that when read, will heal all nearby players. But I was wondering, how to find all nearby players and if differentiating players from other entities is possible.I also have some other minor questions. Like, what exactly is inst?What does the block 'if not TheWorld.ismastersim then' doand finally what does inst.entity:SetPristine() do. I couldn't find the above code in the data folders. Thank you for the help! local assets={ --Asset("ANIM", "anim/bookofhealing.zip"), --Asset("ANIM", "anim/swap_bookofhealing.zip"), Asset("ATLAS", "images/inventoryimages/bookofhealing.xml"), Asset("IMAGE", "images/inventoryimages/bookofhealing.tex"),}prefabs = {}local function fn()local function readhealfn(inst, reader)reader.components.sanity:DoDelta(-TUNING.SANITY_LARGE) local pt = Vector3(reader.Transform:GetWorldPosition()) local range = 50 local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, range) for k, v in pairs(ents) do--something something not sure how to target palyerendend return trueend local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() --not sure what this does inst.entity:AddNetwork() MakeInventoryPhysics(inst) --inst.AnimState:SetBank("books") --inst.AnimState:SetBuild("books") --inst.AnimState:PlayAnimation(name) --not sure what this doesif not TheWorld.ismastersim then return inst endinst.entity:SetPristine() inst:AddComponent("inspectable")inst:AddComponent("book") inst:AddComponent("inventoryitem")inst.components.inventoryitem.imagename = "bookofhealing" inst.components.inventoryitem.atlasname = "images/inventoryimages/bookofhealing.xml" inst.components.book.onread = readhealfn inst:AddComponent("finiteuses")inst.components.finiteuses:SetMaxUses(3)inst.components.finiteuses:SetUses(3)inst.components.finiteuses:SetOnFinished(inst.Remove) return instendreturn Prefab("common/inventory/bookofhealing", fn, assets, prefabs) Link to comment Share on other sites More sharing options...
DarkXero Posted March 6, 2015 Share Posted March 6, 2015 (edited) FindEntities can filter by tags.The entities must have all the tags in must_tags to be found.The entities must not have any tags in cant_tags to be found.The entities must have at least one tag of must_oneoftags to be found.TheSim:FindEntities(pt.x, pt.y, pt.z, range, must_tags, cant_tags, must_oneoftags)Players have the tag, "player", so you put in must_tags {"player"}, like:TheSim:FindEntities(inst:GetPosition(), 40, {"player"}, {"playerghost"})Then you loop through ents. You can also loop through AllPlayers, like:for _, v in pairs(AllPlayers) do if inst:GetDistanceSqToInst(v) < 40 then Heal() --- v.components.health:DoDelta(10) endend Edited March 7, 2015 by DarkXero Link to comment Share on other sites More sharing options...
SenL Posted March 6, 2015 Share Posted March 6, 2015 Very useful. Thanks! Link to comment Share on other sites More sharing options...
DarkXero Posted March 7, 2015 Share Posted March 7, 2015 SenL, I was writing the FindEntities off my memory and screwed up the order of the groups of tags.I edited my message to reflect the correct way. Link to comment Share on other sites More sharing options...
Lingerdinger Posted March 7, 2015 Author Share Posted March 7, 2015 Thanks Dark! I truly appreciate this! 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