Advertisement
Guest User

moonman script test

a guest
Oct 13th, 2011
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. -- A prototype of custom sword creation in moonman.
  2. -- BP 14.10.2011
  3.  
  4. local custom_sword_sprite_id
  5. local custom_sword_id
  6.  
  7. -- this function creates a template for the new sword
  8. local function custom_sword()
  9.     return {
  10.         name = "custom sword",
  11.         inherits = core_entities.sword,
  12.         -- set the default attributes
  13.         attributes = {
  14.             damage = 10,
  15.             speed = 2,
  16.             sprite = custom_sword_sprite_id                    
  17.         },
  18.         -- this sword kills outright for enemies
  19.         -- not wearing armour
  20.         onHit = function(self,enemy)
  21.             if (not enemy.armor) then
  22.                 send_message(core_messages.kill, {target=enemy})
  23.                 return true -- handled
  24.             else           
  25.                 return false -- run normal sword onHit
  26.             end
  27.         end,
  28.         -- 5% of swords spawned are practically useless against armoured enemies
  29.         onSpawn = function(self)
  30.             if (random()<.05) then
  31.                 self.damage = 1
  32.             end
  33.         end    
  34.     }
  35. end
  36.  
  37. -- the recipe indicates what amount of
  38. -- each item goes where in the 5x5 crafting matrix
  39. -- in this case: its just a vertical line in the center
  40. local recipe = {
  41.     craft.coord(2,0) = {core_entities.steel,2},
  42.     craft.coord(2,1) = {core_entities.steel,2},
  43.     craft.coord(2,2) = {core_entities.steel,2},
  44.     craft.coord(2,3) = {core_entities.ebony,2},
  45.     craft.coord(2,4) = {core_entities.ebony,2} 
  46. }
  47.  
  48. -- finally, the onLoad function is called at setup
  49. -- and registers the new sprite, sword type, and recipe
  50. -- for building the sword
  51. function onLoad()
  52.     custom_sword_sprite_id = register_sprite("custom_sword_sprite_id", "sprites/mysword.sprite")
  53.     custom_sword_id = register_entity("custom_sword", custom_sword())
  54.     register_recipe(custom_sword_id, recipe)   
  55. end
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement