dungdodger Posted December 27, 2014 Share Posted December 27, 2014 Hello iv been working on this Item for days its been a lot of fun but i cant seem to get these last two parts working right. Please Help im trying to learn Heres my Issue... i made a item (Copy and Pasted stuff till it started working lol ) that Teleports the target away and spawns a pigman but it will only do this one time after that it only teleports stuff.. But if i unequip it then requip it it does Both effects again.I have NO IDEA why it does this iv just been trying Learn what i can. Also i cant seem to figure out how to make it uncastable if im under 50 Sanity Here is some of what i have tried local function canteleport(inst, caster, target)if target thenreturn target.components.locomotor ~= nilend--if caster.components.sanity then--return (caster.components.sanity.current >= 50)--endreturn trueend I added the --out bc it keeps giving and error about not know the value or sanity or caster i have tried to put it many places or make its ownlocal function. but nothing works... and i have this as a follow up to stop the cast or at least thought it would like it did when i had it as a Weapon or a Book. local function oncast_pig(inst, target, caster, owner)--Check sanityif not canteleport(caster) thenif caster.components.talker thencaster.components.talker:Say ("Could_it_be_MY_Hat_is_FREE")return trueendend this does not crash the game anymore iv tried owner target inst all kinda stuff to make them work but its been days working on this trying to LEARN.. some stuff ahah but still NOTHING Any Help would be much appreciated I can attach some files if need be just let me know what i need to do please THANKS local assets={Asset("ANIM", "anim/pighat.zip"),Asset("ANIM", "anim/swap_pighat.zip"),Asset("ATLAS", "images/inventoryimages/pighat.xml"),Asset("IMAGE", "images/inventoryimages/pighat.tex"),}prefabs = {}local function doeffects(inst, pos)SpawnPrefab("statue_transition").Transform:SetPosition(pos:Get())SpawnPrefab("statue_transition_2").Transform:SetPosition(pos:Get())endlocal function getrandomposition(inst)local ground = GetWorld()local centers = {}for i,node in ipairs(ground.topology.nodes) dolocal tile = GetWorld().Map:GetTileAtPoint(node.x, 0, node.y)if tile and tile ~= GROUND.IMPASSABLE thentable.insert(centers, {x = node.x, z = node.y})endendif #centers > 0 thenlocal pos = centers[math.random(#centers)]return Point(pos.x, 0, pos.z)elsereturn GetPlayer():GetPosition()endendlocal function canteleport(inst, caster, target)if target thenreturn target.components.locomotor ~= nilend--if caster.components.sanity then--return (caster.components.sanity.current >= 50)--endreturn trueendlocal function teleport_thread(inst, caster, teletarget, loctarget)local ground = GetWorld()local t_loc = nilif loctarget thent_loc = loctarget:GetPosition()elset_loc = getrandomposition()endlocal teleportee = teletargetlocal pt = teleportee:GetPosition()if teleportee.components.locomotor thenteleportee.components.locomotor:StopMoving()endif teleportee.components.health thenteleportee.components.health:SetInvincible(true)endteleportee:Hide()if caster.components.sanity thencaster.components.sanity:DoDelta(-50)endif teleportee == GetPlayer() thenTheFrontEnd:Fade(false, 1)Sleep(1)endteleportee.Transform:SetPosition(t_loc.x, 0, t_loc.z)if teleportee == GetPlayer() thenTheCamera:Snap()TheFrontEnd:DoFadeIn(1)Sleep(0)endif loctarget and loctarget.onteleto then loctarget.onteleto(loctarget) endteleportee:Show()inst.Transform:SetPosition(t_loc.x+0.5, 0, t_loc.z+0.5)if teleportee.components.health thenteleportee.components.health:SetInvincible(false)endif teleportee == GetPlayer() thenteleportee.sg:GoToState("idle")endendlocal function teleport_func(inst, target, caster)local mindistance = 1local caster = inst.components.inventoryitem.ownerlocal tar = target or casterlocal pt = tar:GetPosition()local ents = TheSim:FindEntities(pt.x,pt.y,pt.z, 9000, {"telebase"})if #ents <= 0 then--There's no bases, active or inactive. Teleport randomly.inst.task = inst:StartThread(function() teleport_thread(inst, caster, tar) end)returnendlocal targets = {}for k,v in pairs(ents) dolocal v_pt = v:GetPosition()if distsq(pt, v_pt) >= mindistance * mindistance thentable.insert(targets, {base = v, distance = distsq(pt, v_pt)})endendtable.sort(targets, function(a,b) return (a.distance) < (b.distance) end)for i = 1, #targets dolocal teletarget = targetsif teletarget.base and teletarget.base.canteleto(teletarget.base) theninst.task = inst:StartThread(function() teleport_thread(inst, caster, tar, teletarget.base) end)return oncast_pig(inst, target)endendinst.task = inst:StartThread(function() teleport_thread(inst, caster, tar) end)end----- ATTACK--------local function canattack(inst, target)-- if inst.components.sanity then-- return (inst.components.sanity.current >= 50)--target:HasTag("pigman") )--end-- return true--end--local function canteleport(inst)--endlocal function oncast_pig(inst, target, caster, owner)------------------SANITY-----------------------------Check sanityif not canteleport(caster) thenif caster.components.talker thencaster.components.talker:Say ("Could_it_be_MY_Hat_is_FREE")return trueendend--Check reagent--if not owner.components.inventory:Has("petals", 5) then--if owner.components.talker then--owner.components.talker:Say("The_Flowers_have_Escaped")--return true--end--end--caster.components.inventory:ConsumeByName("petals", 5)----------------SANITY---------------------------------Ok you had everything. Make the image.local theta = math.random() * 2 * PIlocal pt = inst:GetPosition()local radius = math.random(3, 6)local offset = FindWalkableOffset(pt, theta, radius, 12, true)if offset thenlocal image = SpawnPrefab("pigman")local pos = pt + offsetimage.Transform:SetPosition(pos:Get())doeffects(inst, pos)inst.SoundEmitter:PlaySound("dontstarve/maxwell/shadowmax_appear")endreturn teleport_func(inst, target, caster)endlocal function OnEquip(inst, owner)owner.AnimState:OverrideSymbol("swap_object", "swap_pighat", "swap_pighat")owner.AnimState:Show("ARM_carry")owner.AnimState:Hide("ARM_normal")endlocal function OnUnequip(inst, owner)owner.AnimState:Hide("ARM_carry")owner.AnimState:Show("ARM_normal")endlocal function fn()local inst = CreateEntity()local trans = inst.entity:AddTransform()local anim = inst.entity:AddAnimState()local sound = inst.entity:AddSoundEmitter()MakeInventoryPhysics(inst)anim:SetBank("pighat")anim:SetBuild("pighat")anim:PlayAnimation("idle")local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon("pighat.tex")inst:AddComponent("inspectable")inst:AddComponent("inventoryitem")inst.components.inventoryitem.imagename = "pighat"inst.components.inventoryitem.atlasname = "images/inventoryimages/pighat.xml"--inst:AddComponent("equippable")inst.components.equippable:SetOnEquip( OnEquip )inst.components.equippable:SetOnUnequip( OnUnequip )--Shovel with your hat-------------------------inst:AddComponent("tool")inst.components.tool:SetAction(ACTIONS.DIG)inst:AddInherentAction(ACTIONS.DIG)--inst:AddComponent("finiteuses")--inst.components.finiteuses:SetMaxUses(0)--inst.components.finiteuses:SetUses(0)--inst.components.finiteuses:SetConsumption(ACTIONS.DIG, 0)localbase_finiteuses_OnUsedAsItem =inst.components.finiteuses.OnUsedAsIteminst.components.finiteuses.OnUsedAsItem =function( self, action )base_finiteuses_OnUsedAsItem( self, action ) -- drain sanity on digif action == ACTIONS.DIG thenif self.inst.components.inventoryitemand self.inst.components.inventoryitem.owner thenlocal owner = self.inst.components.inventoryitem.ownerowner.components.sanity:DoDelta( -10)endendend---------------------------------------------------inst:AddComponent("spellcaster")--inst.components.spellcaster:SetSpellTestFn(san_chk)inst.components.spellcaster.canuseontargets = trueinst.components.spellcaster:SetSpellTestFn(canteleport)inst.components.spellcaster:SetSpellFn(oncast_pig)--inst:AddTag("dull")--inst:AddComponent("weapon")--inst.components.weapon:SetDamage(2)--inst.components.weapon:SetOnAttack(onattack)return instendreturn Prefab("common/inventory/pighat", fn, assets) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.