--medkit script by smallg --sound 0 for pick up noise --sound 1 for usage noise --range to pick up local pick_up_range = 100 --key to pick up local pick_up_key = "e" --key to use the medkit local use_key = "o" --max amount of medkits to carry local max_kits = 5 --amount of time it takes to "use" a kit - for bandaging effects etc local use_delay = 2000 --allows kit to heal more than max health if set to 1 or more (set to 0 and kit will not go above max hp) --if player uses kit and gets more than max hp he will slowly lose hp until back to max hp local decay_amount = 0 --if you want the med kit to restore more than max hp but not decay set decay_delay to 0 local decay_delay = 1000 --size of text (1 ~ 5) local text_size = 3 local state = {} medkits = 0 max_health = nil pressed = 0 function medkit_init_name(e,name) state[e] = "pick up" weapon_name[e] = name end function medkit_main(e) --find players max hp so we know how much to heal to or decay back to if max_health == nil then max_health = g_PlayerHealth else --prompt to show how many med kits you have (should add this line to a global script or keep 1 med kit hidden and always active) Text(1,2,text_size,medkits.. " x Med kits in inventory") --if med kit is on the ground then wait for player to pick it up if state[e] == "pick up" then --player in range of kit if PlayerLooking(e,pick_up_range,10) == 1 then --check we have room for more if medkits < max_kits then TextCenterOnX(50,97,text_size,"Pick up "..weapon_name[e].."? *restores "..g_Entity[e]['health'].." HP when used*") --player picks up med kit if GetInKey() == pick_up_key and pressed == 0 then PlaySound(e,0) pressed = 1 --increase how many medkits we have for the display medkits = medkits + 1 state[e] = "in inventory" end --no room for the kit else TextCenterOnX(50,97,text_size,"You can't carry any more "..weapon_name[e]) end end --player in range --kit is in inventory elseif state[e] == "in inventory" then --update the position of the kit so it stays with the player but hidden Hide(e) ; CollisionOff(e) ; SetPosition(e,g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) --if player tries to use a kit in his inventory if GetInKey() == use_key and pressed == 0 then pressed = 1 --check player can gain more hp if g_PlayerHealth < max_health or decay_amount > 0 then StartTimer(e) state[e] = "healing" else --optional prompt to tell player he can't gain/restore more hp yet PromptDuration("You already have maximum HP",3000) end end --player using a kit elseif state[e] == "healing" then --stop player so he can simulate applying bandaging etc if GetTimer(e) < use_delay then FreezePlayer() --show healing status on screen and play sound local perc = round((GetTimer(e)/use_delay) * 100) TextCenterOnX(50,97,text_size,"Healing "..perc.."%") LoopSound(e,1) else --healing completed so stop sound and let player move again StopSound(e,1) UnFreezePlayer() medkits = medkits - 1 --update health --if health can go over maximum then apply full heal if decay_amount > 0 then SetPlayerHealth(g_PlayerHealth+g_Entity[e]['health']) StartTimer(e) state[e] = "decay" else --if health can't go over maximum then check how much we can heal and apply if g_PlayerHealth + g_Entity[e]['health'] < max_health then SetPlayerHealth(g_PlayerHealth + g_Entity[e]['health']) else SetPlayerHealth(max_health) end Destroy(e) end end --kit used and we were above maximum hp elseif state[e] == "decay" then --update the position of the kit so it stays with the player but hidden Hide(e) ; CollisionOff(e) ; SetPosition(e,g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) --check we want player to lose his new hp if decay_delay > 0 then --check we are still above max hp so we can apply the decay if g_PlayerHealth > max_health then if GetTimer(e) > decay_delay then --check decay wont take us below max hp if g_PlayerHealth - decay_amount >= max_health then SetPlayerHealth(g_PlayerHealth - decay_amount) else SetPlayerHealth(max_health) end StartTimer(e) end else --health below or at max health so stop decay Destroy(e) end else --if player can keep his new "boosted" hp then exit max_health = g_PlayerHealth Destroy(e) end end --state --reset player input if GetScancode() == 0 then pressed = 0 end end --max health set end --main function medkit_exit(e) end --function to check player looking at the med kit function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end --function to round a number function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end