What happened to OC? - CLOSED Carnage?!
ThePolice

Deleting Weapons Dropped by Dead People

Hi, I was wondering if someone could help me complete this script.  I'm not familiar with lua but I think I already have the necessary functions in it.

 

I think I just need to finish the OnDeath() function.  Keep in mind that everyone in the mod will only spawn with one weapon.  Also deleting the weapon should work at death because this worked in the events.txt:  

 

event_die wdel $n 1'  

 

api_version = "1.9.0.0"

function OnScriptLoad()
	register_callback(cb['EVENT_DIE'],"OnDeath")
end

function OnDeath()
	--should get the map_ids object
	--if the weapon they were holding ~= map_ids.ball or map_ids.flag
	--then delete the weapon dropped
end

function get_map_ids()
    local globals_tag = read_dword(lookup_tag("matg","globals\\globals") + 0x14)
    
    if read_dword(globals_tag + 0x14C) ~= 16 or read_dword(globals_tag + 0x158) ~= 5 then return end
    
    local map_ids = {}
    
    local weapons_address = read_dword(globals_tag + 0x14C + 0x4) + 0xC
    map_ids.assault_rifle = read_dword(weapons_address + 0 * 16)
    map_ids.flamethrower = read_dword(weapons_address + 1 * 16)
    map_ids.gravity_rifle = read_dword(weapons_address + 2 * 16)
    map_ids.needler = read_dword(weapons_address + 3 * 16)
    map_ids.pistol = read_dword(weapons_address + 4 * 16)
    map_ids.plasma_pistol = read_dword(weapons_address + 5 * 16)
    map_ids.plasma_rifle = read_dword(weapons_address + 6 * 16)
    map_ids.rocket_launcher = read_dword(weapons_address + 7 * 16)
    map_ids.shotgun = read_dword(weapons_address + 8 * 16)
    map_ids.sniper_rifle = read_dword(weapons_address + 9 * 16)
    map_ids.frag_grenade = read_dword(weapons_address + 12 * 16)
    map_ids.plasma_grenade = read_dword(weapons_address + 13 * 16)
    map_ids.plasma_cannon = read_dword(weapons_address + 14 * 16)
    map_ids.mp_needler = read_dword(weapons_address + 15 * 16)
    
    local powerups_address = read_dword(globals_tag + 0x158 + 0x4) + 0xC
    map_ids.active_camouflage = read_dword(powerups_address + 0 * 16)
    map_ids.double_speed = read_dword(powerups_address + 1 * 16)
    map_ids.full_spectrum_vision = read_dword(powerups_address + 2 * 16)
    map_ids.overshield = read_dword(powerups_address + 3 * 16)
    map_ids.health_pack = read_dword(powerups_address + 4 * 16)
    
    local multiplayer_information = read_dword(globals_tag + 0x164 + 0x4)
    map_ids.ball = read_dword(multiplayer_information + 0x4C + 0xC)
    map_ids.flag = read_dword(multiplayer_information + 0x0 + 0xC)
    
    local vehicles_address = read_dword(multiplayer_information + 0x20 + 0x4) + 0xC
    map_ids.mp_warthog = read_dword(vehicles_address + 0 * 16)
    map_ids.ghost_mp = read_dword(vehicles_address + 1 * 16)
    map_ids.scorpion_mp = read_dword(vehicles_address + 2 * 16)
    map_ids.banshee_mp = read_dword(vehicles_address + 3 * 16)
    map_ids.c_gun_turret_mp = read_dword(vehicles_address + 4 * 16)
    map_ids.rwarthog = read_dword(vehicles_address + 5 * 16)
    
    return map_ids
end


function OnScriptUnload()

end

 

Share this post


Link to post
Share on other sites

Tiddy-bits:

This will work as long as they only have one weapon.

 


api_version = "1.10.0.0"

function OnScriptLoad()
	register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
end

function OnScriptUnload() end

function OnPlayerDeath(VictimIndex, KillerIndex)
	local m_object = get_dynamic_player(VictimIndex)
	if m_object ~= 0 then
		local m_weaponID = read_dword(m_object + 0x118)
		local weapon_address = get_object_memory(m_weaponID)
		if weapon_address ~= 0 then
			local weapon_tag = lookup_tag(read_dword(weapon_address))
			if weapon_tag ~= 0 then
				local tag = read_string(read_dword(weapon_tag + 0x10))
				if tag ~= "weapons\\ball\ball" or tag ~= "weapons\\flag\\flag" then
					destroy_object(m_weaponID)
				end
			end
		end
	end
end

If you need it to check for other weapons let me know.  Also since I'm not just using the mapIds it may not work on protected maps, but if you need that I'll re-write it using that then.

Takka likes this

Share this post


Link to post
Share on other sites

Thanks for the help I really appreciate it.  I was able to get it working but I had to change the conditional statement to

 

if tag ~= "weapons\\flag\\flag" then
	if tag ~= "weapons\\ball\\ball" then
		destroy_object(m_weaponID)
	end
end

The way you had it should of worked but whatever.

 

 

I forgot to mention that I want it so when you're holding the flag or the ball and you die, then the weapon you have in your inventory gets deleted so only the flag or ball is dropped.

 

So wouldn't the code look like this?

 

if m_object ~= 0 then
		local m_weaponID = read_dword(m_object + 0x118)

		--weaponID of their secondary weapon = read(m_object + 0x???)

		local weapon_address = get_object_memory(m_weaponID)

		--weapon address of secondary weapon (will = 0 if not holding the flag?)

		if weapon_address ~= 0 then
			local weapon_tag = lookup_tag(read_dword(weapon_address))

			--secondary weapon tag = lookup(secondary address)

			if weapon_tag ~= 0 then
				local tag = read_string(read_dword(weapon_tag + 0x10))

				--secondary tag = read(secondary weapon tag + 0x??)

				if tag ~= "weapons\\flag\\flag" then
					if tag ~= "weapons\\ball\\ball" then
						destroy_object(m_weaponID)
					end
				else
					--destroy secondary weapon
				end
			end
		end
	end
end

 

 

Thanks again

Share this post


Link to post
Share on other sites
45 minutes ago, ThePolice said:

That script works really well thanks giraffe.

 

No problem, but your thanks should go to @002. I just happened to remember that I requested something similar quite some time ago.

Share this post


Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.