Recieve prize for killing someone?

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

Recieve prize for killing someone?

by mcfan » Tue Apr 01, 2014 19:27

As I've said before, I have a minigame pvp server. I want to make it so that when someone kills someone else they either receive money or something that can be cashed in for money or something of value to enhance fighting. I tried messing around with the death mod to add this, but all I did was crash minitest. Is it something that can be done or is it another one of those things that are to hard to do?
Love MINECRAFT... will settle for Minetest
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Tue Apr 01, 2014 20:15

you could always just drop an item with minetest.register_on_dieplayer but that will drop something any time they die, not just when they are killed by another player.
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Tue Apr 01, 2014 21:18

That would be fine. But I tried adding some code for that but it didn't work.
Love MINECRAFT... will settle for Minetest
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Tue Apr 01, 2014 22:29

Something like this should drop one dirt when the player died.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_dieplayer( function (player)
local pos = player:getpos()
        local x = math.random(0, 15)/10 - 1.25
    local z = math.random(0, 15)/10 - 1.25   
    pos.x = pos.x + x
    pos.z = pos.z + z
    pos.y = pos.y + .25
    local obj = minetest.add_item(pos, "default:dirt")
    if obj then
        obj:get_luaentity().collect = true
    end
end )
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Wed Apr 02, 2014 02:43

It worked - Thanks. Now, is it possible to make a random command so sometimes they will drop something special?
Love MINECRAFT... will settle for Minetest
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Wed Apr 02, 2014 12:05

I want it so it will drop the head and something else of value for fighting.
Love MINECRAFT... will settle for Minetest
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Wed Apr 02, 2014 17:58

Something like this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_dieplayer( function (player)
local dropItem = ""
if math.random(0,5) == 1 then
   dropItem = "<special item>"
else
   dropItem = "<common item>"
end

local pos = player:getpos()
        local x = math.random(0, 15)/10 - 1.25
    local z = math.random(0, 15)/10 - 1.25   
    pos.x = pos.x + x
    pos.z = pos.z + z
    pos.y = pos.y + .25
    local obj = minetest.add_item(pos, dropItem)
    if obj then
        obj:get_luaentity().collect = true
    end
end )


That would give it roughly a 1 in 6 chance of dropping the special item, otherwise it would drop the other item
 

User avatar
minermoder27
Member
 
Posts: 127
Joined: Wed Nov 20, 2013 23:24
GitHub: ZNixian
In-game: minermoder27

by minermoder27 » Wed Apr 02, 2014 19:32

You could use my drop on die mod as a base

Let's say you want a drop of a mese block for killing someone:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all



local drop = function(pos, istack)
    --for i=1, istack:get_count() do
        local obj = minetest.env:add_item(pos, istack:get_name() .. " " .. istack:get_count())
        if obj ~= nil then
            obj:get_luaentity().collect = true
            local x = math.random(1, 5)
            if math.random(1,2) == 1 then
                x = -x
            end
            local z = math.random(1, 5)
            if math.random(1,2) == 1 then
                z = -z
            end
            obj:setvelocity({x=1/x, y=5, z=1/z})
           
            -- FIXME this doesnt work for deactiveted objects
            if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
                minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
                    obj:remove()
                end, obj)
            end
        end
    --end
end



minetest.register_on_dieplayer(function(player)
    if minetest.setting_getbool("creative_mode") then
        return
    end
   
    local pos = player:getpos()
    pos.x = math.floor(pos.x+0.5)
    pos.y = math.floor(pos.y+0.5)
    pos.z = math.floor(pos.z+0.5)
    local param2 = minetest.dir_to_facedir(player:get_look_dir())

    drop(pos, ItemStack("default:mese"))
end)


If you wanted to drop a dirt as well, change
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
drop(pos, ItemStack("default:mese"))
to
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
drop(pos, ItemStack("default:mese"))
drop(pos, ItemStack("default:dirt"))
Last edited by minermoder27 on Wed Apr 02, 2014 19:34, edited 1 time in total.
My best mods:
Buildtest
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Wed Apr 02, 2014 21:30

Thanks alot - it worked. People now drop heads on death.
Love MINECRAFT... will settle for Minetest
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 6 guests

cron