Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. local assets =
  2. {
  3.     Asset("ANIM", "anim/primitivegun.zip"),
  4.     Asset("ANIM", "anim/swap_primitivegun.zip"),
  5.  
  6.     Asset("ATLAS", "images/inventoryimages/primitivegun.xml"),
  7.     Asset("IMAGE", "images/inventoryimages/primitivegun.tex"),
  8.  
  9. }
  10.  
  11. local prefabs =
  12. {
  13.     red =
  14.     {
  15.         "fire_projectile",
  16.         "cutgrass",
  17.     },
  18. }
  19.  
  20. ---------RED STAFF---------
  21.  
  22. local function onattack_red(inst, attacker, target, skipsanity)
  23.  
  24.     attacker.SoundEmitter:PlaySound("dontstarve/wilson/fireball_explo")
  25.  
  26.     if not target:IsValid() then
  27.         --target killed or removed in combat damage phase
  28.         return
  29.     end
  30.  
  31.     if target.components.combat ~= nil then
  32.         target.components.combat:SuggestTarget(attacker)
  33.     end
  34.  
  35.     target:PushEvent("attacked", { attacker = attacker, damage = 0, weapon = inst })
  36. end
  37.  
  38. local function onlight(inst, target)
  39.     if inst.components.finiteuses ~= nil then
  40.         inst.components.finiteuses:Use(1)
  41.     end
  42. end
  43.  
  44.  
  45.  
  46. ---------COMMON FUNCTIONS---------
  47.  
  48. local function onfinished(inst)
  49.     inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")
  50.     inst:Remove()
  51. end
  52.  
  53. local function onequip(inst, owner)
  54.     owner.AnimState:OverrideSymbol("swap_object", "swap_primitivegun", "swap_primitivegun")
  55.     owner.AnimState:Show("ARM_carry")
  56.     owner.AnimState:Hide("ARM_normal")
  57. end
  58.  
  59. local function onunequip(inst, owner)
  60.     owner.AnimState:Hide("ARM_carry")
  61.     owner.AnimState:Show("ARM_normal")
  62.  
  63. end
  64.  
  65. local function commonfn(colour, tags, hasskin)
  66.     local inst = CreateEntity()
  67.  
  68.     inst.entity:AddTransform()
  69.     inst.entity:AddAnimState()
  70.     inst.entity:AddSoundEmitter()
  71.     inst.entity:AddNetwork()
  72.  
  73.     MakeInventoryPhysics(inst)
  74.  
  75.     --probably need to change this
  76.     inst.AnimState:SetBank("primitivegun")
  77.     inst.AnimState:SetBuild("primitivegun")
  78.     inst.AnimState:PlayAnimation("primitivegun")
  79.  
  80.     if tags ~= nil then
  81.         for i, v in ipairs(tags) do
  82.             inst:AddTag(v)
  83.         end
  84.     end
  85.  
  86.     inst.entity:SetPristine()
  87.  
  88.     if not TheWorld.ismastersim then
  89.         return inst
  90.     end
  91.  
  92.     -------
  93.     inst:AddComponent("finiteuses")
  94.     inst.components.finiteuses:SetOnFinished(onfinished)
  95.  
  96.     inst:AddComponent("inspectable")
  97.  
  98.     inst:AddComponent("inventoryitem")
  99.     inst.components.inventoryitem.imagename = "primitivegun"
  100.     inst.components.inventoryitem.atlasname = "images/inventoryimages/primitivegun.xml"
  101.  
  102.     inst:AddComponent("tradable")
  103.  
  104.     inst:AddComponent("equippable")
  105.  
  106.     inst.components.equippable:SetOnUnequip(onequip)
  107.     inst.components.equippable:SetOnUnequip(onunequip)
  108.  
  109.     return inst
  110. end
  111.  
  112. ---------COLOUR SPECIFIC CONSTRUCTIONS---------
  113.  
  114. local function creation()
  115.     local inst = commonfn("red", {"rangedweapon"}, true)
  116.  
  117.     if not TheWorld.ismastersim then
  118.         return inst
  119.     end
  120.  
  121.     inst:AddComponent("weapon")
  122.     inst.components.weapon:SetDamage(23)
  123.     inst.components.weapon:SetRange(8, 10)
  124.     inst.components.weapon:SetOnAttack(onattack_red)
  125.     inst.components.weapon:SetProjectile("bullet")
  126.  
  127.     inst.components.finiteuses:SetMaxUses(15)
  128.     inst.components.finiteuses:SetUses(15)
  129.  
  130.     MakeHauntableLaunch(inst)
  131.  
  132.     return inst
  133. end
  134.  
  135.  
  136. return Prefab("primitivegun", creation, assets, prefabs.red)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement