Lootable corpses?

How could I script in the ability to search a body for items like…
find body -> crouch -> activate search -> ‘searching’ (player made immobile for search period) -> you gained $26 (or whatever is found).

Hey, if you’re still interested in this: Here’s a simple block of code that does what you’re asking. (Sort-of)

If the player presses E on a ragdoll while croutched next to it, then he has a 1/10 chance of finding $10.

function GM:KeyPress( pl, key )

-- If the player is croutching, on the ground, and presses USE (E Default)
if ( pl:Crouching( ) and pl:OnGround( ) and key == IN_USE ) then

	-- Trace where the player is looking, and make sure we hit a valid entity
	local tr  = util.QuickTrace( pl:EyePos( ), pl:GetAimVector( ) * 128, pl )
	if ( tr.Hit and tr.HitNonWorld and tr.Entity ) then
		-- Once we know we hit something, we need to know what it is
		local class = tr.Entity:GetClass( )
		if ( string.find( "ragdoll", class ) ) then	-- If it's a ragdoll...
			-- Don't do anything if it's already been looted
			if ( tr.Entity.Looted ) then return; end
			-- Tell the player that you are searching the body
			pl:PrintMessage( HUD_PRINTTALK, "Searching..." )
			-- More code is required here for a more realistic methood
			-- After 5 seconds of searching...
			timer.Simple( 5, function( pl )
				-- The player has a 1 out-of 10 probability of finding something
				local random = math.random( 1, 10 )
				if ( random == 1 ) then
					-- If the player is lucky, he will find $10, and the ragdoll becomes un-lootable
					pl:PrintMessage( HUD_PRINTCENTER, "Found $10" )
				-- we didn't find anything, tell the player
				pl:PrintMessage( HUD_PRINTTALK, "Nothing could be scavenged from this corpse." )
			end, pl )
			-- Make sure we can't loot the same ragdoll twice
			tr.Entity.Looted = true


:0 wow, i mean ive been trying to learn this stuff but im strugglin so bad!

We all have to start slow, specially when it comes to coding.

Just remember that as much as the community would like to be there for you 24/7, your best tools are the Gmod Wiki and the Gmod Lua-Bin. Both have examples of code you can copy and learn from… and patience is always a plus.