--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 g_medkits to carry local max_kits = 5 --amount of time it takes to "use" a kit - for bandaging effects etc local use_delay = 2000 --size of text (1 ~ 5) local text_size = 3 local state = {} g_medkits = g_medkits or 0 max_health = nil pressed = 0 medkitE = nil function medkit2_init_name(e,name) if medkitE == nil then medkitE = e SetActivated(e,2) state[e] = "display hud" else state[e] = "pick up" end weapon_name[e] = name end function medkit2_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 if state[e] == "display hud" then --prompt to show how many med kits you have (should keep 1 med kit hidden and always active) Hide(e) ; CollisionOff(e) ; SetPosition(e,g_PlayerPosX,g_PlayerPosY+250,g_PlayerPosZ) Text(1,2,text_size,g_medkits.. " x Med kits in inventory") if g_Entity[medkitE]['activated'] == 2 then if g_medkits > 0 then --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(medkitE) SetActivated(medkitE,3) else --optional prompt to tell player he can't gain/restore more hp yet PromptDuration("You already have maximum HP",3000) end end end elseif g_Entity[medkitE]['activated'] == 3 then --player using a kit --stop player so he can simulate applying bandaging etc if GetTimer(medkitE) < use_delay then FreezePlayer() --show healing status on screen and play sound local perc = round((GetTimer(medkitE)/use_delay) * 100) TextCenterOnX(50,97,text_size,"Healing "..perc.."%") LoopSound(medkitE,1) else --healing completed so stop sound and let player move again StopSound(medkitE,1) UnFreezePlayer() g_medkits = g_medkits - 1 --update health --check how much we can heal and apply if g_PlayerHealth + g_Entity[medkitE]['health'] < max_health then SetPlayerHealth(g_PlayerHealth + g_Entity[medkitE]['health']) else SetPlayerHealth(max_health) end SetActivated(medkitE,2) end end --activated --if med kit is on the ground then wait for player to pick it up elseif 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 g_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(medkitE,0) pressed = 1 --increase how many g_medkits we have for the display g_medkits = g_medkits + 1 state[e] = "" Hide(e) ; CollisionOff(e) ; Destroy(e) 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 end --reset player input if GetScancode() == 0 then pressed = 0 end end --max health set end --main function medkit2_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