Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A prototype of custom sword creation in moonman.
- -- BP 14.10.2011
- local custom_sword_sprite_id
- local custom_sword_id
- -- this function creates a template for the new sword
- local function custom_sword()
- return {
- name = "custom sword",
- inherits = core_entities.sword,
- -- set the default attributes
- attributes = {
- damage = 10,
- speed = 2,
- sprite = custom_sword_sprite_id
- },
- -- this sword kills outright for enemies
- -- not wearing armour
- onHit = function(self,enemy)
- if (not enemy.armor) then
- send_message(core_messages.kill, {target=enemy})
- return true -- handled
- else
- return false -- run normal sword onHit
- end
- end,
- -- 5% of swords spawned are practically useless against armoured enemies
- onSpawn = function(self)
- if (random()<.05) then
- self.damage = 1
- end
- end
- }
- end
- -- the recipe indicates what amount of
- -- each item goes where in the 5x5 crafting matrix
- -- in this case: its just a vertical line in the center
- local recipe = {
- craft.coord(2,0) = {core_entities.steel,2},
- craft.coord(2,1) = {core_entities.steel,2},
- craft.coord(2,2) = {core_entities.steel,2},
- craft.coord(2,3) = {core_entities.ebony,2},
- craft.coord(2,4) = {core_entities.ebony,2}
- }
- -- finally, the onLoad function is called at setup
- -- and registers the new sprite, sword type, and recipe
- -- for building the sword
- function onLoad()
- custom_sword_sprite_id = register_sprite("custom_sword_sprite_id", "sprites/mysword.sprite")
- custom_sword_id = register_entity("custom_sword", custom_sword())
- register_recipe(custom_sword_id, recipe)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement