local up = {} local max_height = {} local moved = {} function grenade_init_name(e,name) g_name[e] = "grenade"..name state[e] = "wait" Hide(e) moved[e] = 0 --how fast grenades will travel up and down bounce_speed[e] = 100 --how fast grenades will travel forwards forward_speed[e] = 375 end function grenade_main(e) if grenade[e] ~= nil then --size of the grenade Scale(e,100) if state[e] == "wait" then Hide(e) CollisionOff(e) SetPosition(e,g_Entity[grenade[e]]['x'],g_Entity[grenade[e]]['y']+60,g_Entity[grenade[e]]['z']) RotateToPlayer(e) --starting height of the grenade max_height[e] = g_Entity[e]['y'] + 90 up[e] = 0 StartTimer(e) moved[e] = 0 elseif state[e] == "thrown" then --delay to allow throw animation to play first if GetTimer(e) > 1000 then Show(e) RotateToPlayer(e) state[e] = "moving" end elseif state[e] == "moving" then Show(e) CollisionOff(e) --range to detect player for "hit" if GetPlayerDistance(e) < 80 then SetEntityHealth(e,0) else --has stopped moving if moved[e] < max_distance and forward_speed[e] > 10 then MoveForward(e,forward_speed[e]) moved[e] = moved[e] + 1 if up[e] == 0 then if g_Entity[e]['y'] < max_height[e] then MoveUp(e,bounce_speed[e]) else up[e] = 1 end else if g_Entity[e]['y'] <= g_PlayerPosY - 40 then if up[e] == 1 then --adjusts the grenade speed to simulate gravity bounce_speed[e] = bounce_speed[e] * 0.8 forward_speed[e] = forward_speed[e] * 0.9 if max_height[e] - 25 > g_PlayerPosY - 40 then max_height[e] = max_height[e] - 25 end up[e] = 0 end PlaySoundIfSilent(e,1) else MoveUp(e,-bounce_speed[e]) end end else --stopped moving so explode SetEntityHealth(e,0) end end CollisionOn(e) end --state --Prompt(forward_speed[e]) end end function grenade_exit(e) Hide(e) end